X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fvamsas%2FDatastoreRegistry.java;h=9ecd36c6ba985bab473bd0a69cfc952c368cfb04;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;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..9ecd36c 100644 --- a/src/jalview/io/vamsas/DatastoreRegistry.java +++ b/src/jalview/io/vamsas/DatastoreRegistry.java @@ -1,12 +1,29 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) + * Copyright (C) 2015 The Jalview Authors + * + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.io.vamsas; -import java.util.Enumeration; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; -import uk.ac.vamsas.client.Vobject; - public class DatastoreRegistry { protected static org.apache.log4j.Logger log = org.apache.log4j.Logger @@ -51,55 +68,53 @@ 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) + { + // 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 { - Object[] dsregitem = (Object[]) dsItemReg.get(dsitem); - if (dsregitem == null) + // 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 +127,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 +167,7 @@ public class DatastoreRegistry items = null; dsObjReg.clear(); } - if (dsItemReg!=null) + if (dsItemReg != null) { dsItemReg.clear(); }