X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fvamsas%2FDatastoreRegistry.java;h=f00426aecf3dae89284c244a504dfbecbf6e788b;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=21083dd1b7ec500f16f4d5f29f63a7d51ac1e80e;hpb=68623b2a89b09108abfb0c2bc1f71cc6f70e6d38;p=jalview.git diff --git a/src/jalview/io/vamsas/DatastoreRegistry.java b/src/jalview/io/vamsas/DatastoreRegistry.java index 21083dd..f00426a 100644 --- a/src/jalview/io/vamsas/DatastoreRegistry.java +++ b/src/jalview/io/vamsas/DatastoreRegistry.java @@ -1,3 +1,20 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + */ package jalview.io.vamsas; import java.util.Enumeration; @@ -51,55 +68,54 @@ public class DatastoreRegistry if (obj instanceof DatastoreItem) { log.debug("Returning DatastoreItem self reference.");// TODO: we could - // store the update - // hierarchy - so - // retrieve parent - // for obj. + // store the update + // hierarchy - so + // retrieve parent + // for obj. return (DatastoreItem) obj; } return (DatastoreItem) dsObjReg.get(obj); } - public void registerDsObj(DatastoreItem dsitem) + synchronized void registerDsObj(DatastoreItem dsitem) { - synchronized (dsItemReg) + Object[] dsregitem = (Object[]) dsItemReg.get(dsitem); + if (dsregitem == null) { - Object[] dsregitem = (Object[]) dsItemReg.get(dsitem); - if (dsregitem == null) + // create a new item entry + dsregitem = new Object[] + { dsitem.jvobj, dsitem.vobj }; + dsItemReg.put(dsitem, dsregitem); + dsObjReg.put(dsitem.jvobj, dsitem); + dsObjReg.put(dsitem.vobj, dsitem); + } + else + { + // update registry for any changed references + // for the jvobject + if (dsitem.jvobj != dsregitem[0]) { - // create a new item entry - dsregitem = new Object[] - { dsitem.jvobj, dsitem.vobj }; - dsItemReg.put(dsitem, dsregitem); + // overwrite existing involved entries. + if (dsregitem[0] != null) + { + dsObjReg.remove(dsregitem[0]); + } + if ((dsregitem[0] = dsitem.jvobj) != null) + { + dsObjReg.put(dsregitem[0], dsitem); + } } - // atomic update of the jv and vobject references in the dsObjReg - synchronized (dsObjReg) + // and for the vobject + if (dsitem.vobj != dsregitem[1]) { - // for the jvobject - if (dsitem.jvobj != dsregitem[0]) + // overwrite existing involved entries. + if (dsregitem[1] != null) { - // overwrite existing involved entries. - if (dsregitem[0] != null) - { - dsObjReg.remove(dsregitem[0]); - } - if ((dsregitem[0] = dsitem.jvobj) != null) - { - dsObjReg.put(dsregitem[0], dsitem); - } + dsObjReg.remove(dsregitem[1]); } - // and for the vobject - if (dsitem.vobj != dsregitem[1]) + if ((dsregitem[1] = dsitem.vobj) != null) { - // overwrite existing involved entries. - if (dsregitem[1] != null) - { - dsObjReg.remove(dsregitem[1]); - } - if ((dsregitem[1] = dsitem.vobj) != null) - { - dsObjReg.put(dsregitem[1], dsitem); - } + dsObjReg.put(dsregitem[1], dsitem); } } } @@ -112,12 +128,12 @@ public class DatastoreRegistry * @return null or last known Object[] { jvobject, vobject } references for * this dsitem */ - public Object[] removeDsObj(DatastoreItem dsitem) + public synchronized Object[] removeDsObj(DatastoreItem dsitem) { Object[] dsregitem = null; - synchronized (dsItemReg) + // synchronized (dsItemReg) { - synchronized (dsObjReg) + // synchronized (dsObjReg) { dsregitem = (Object[]) dsItemReg.remove(dsitem); if (dsregitem != null) @@ -152,7 +168,7 @@ public class DatastoreRegistry items = null; dsObjReg.clear(); } - if (dsItemReg!=null) + if (dsItemReg != null) { dsItemReg.clear(); }