X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.acorn%2Fsrc%2Forg%2Fsimantics%2Facorn%2Flru%2FClusterLRU.java;h=6b5252161a814668411ae8a60d2bc5d5d0a0a643;hp=1f0db54354184c89af52d102fe622cb88d9c9926;hb=d9a9d77c7024260e3e3b3a8558ddc84b2a8b99b3;hpb=463c2a8dd4b9ca623872e6520906c19c03a1c4cb diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterLRU.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterLRU.java index 1f0db5435..6b5252161 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterLRU.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterLRU.java @@ -6,6 +6,8 @@ import java.util.concurrent.atomic.AtomicInteger; import org.simantics.acorn.ClusterManager; import org.simantics.acorn.cluster.ClusterImpl; +import org.simantics.acorn.exception.AcornAccessVerificationException; +import org.simantics.acorn.exception.IllegalAcornStateException; import org.simantics.acorn.internal.BijectionMap; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.ClusterDoesNotExistException; @@ -19,18 +21,14 @@ import gnu.trove.TIntIntHashMap; public class ClusterLRU extends LRU { final private BijectionMap clusterMapping = new BijectionMap(); - final private ClusterManager manager; public ClusterLRU(ClusterManager manager, String identifier, Path writeDir) { - - super(identifier, writeDir); - this.manager = manager; + super(manager, identifier, writeDir); clusterMapping.map(ClusterUID.make(0,2), clusterMapping.size() + 1); - } - public ClusterInfo getOrCreate(ClusterUID uid, boolean makeIfNull) { + public ClusterInfo getOrCreate(ClusterUID uid, boolean makeIfNull) throws IllegalAcornStateException, AcornAccessVerificationException { try { @@ -40,7 +38,7 @@ public class ClusterLRU extends LRU { if (info == null) { - if(!makeIfNull) throw new IllegalStateException("Asked for an existing cluster " + uid + " that was not found."); + if(!makeIfNull) throw new IllegalAcornStateException("Asked for an existing cluster " + uid + " that was not found."); Integer clusterKey = clusterMapping.getRight(uid); if (clusterKey == null) { @@ -54,9 +52,10 @@ public class ClusterLRU extends LRU { } return info; - + } catch (IllegalAcornStateException | AcornAccessVerificationException e) { + throw e; } catch (Throwable t) { - throw new IllegalStateException(t); + throw new IllegalAcornStateException(t); } finally { releaseMutex(); @@ -68,16 +67,15 @@ public class ClusterLRU extends LRU { /* * This method waits - we have no locks here */ - public void ensureUpdates(ClusterUID uid) throws DatabaseException { + public void ensureUpdates(ClusterUID uid) throws ClusterDoesNotExistException, AcornAccessVerificationException, IllegalAcornStateException { ClusterInfo info = getWithoutMutex(uid); if(info == null) throw new ClusterDoesNotExistException("Asked a cluster which does not exist: " + uid); info.waitForUpdates(); - } - public ClusterInfo get(ClusterUID uid, boolean makeIfNull, boolean ensureUpdates) throws DatabaseException { + public ClusterInfo get(ClusterUID uid, boolean makeIfNull, boolean ensureUpdates) throws AcornAccessVerificationException, IllegalAcornStateException { if (ensureUpdates) { try { @@ -86,19 +84,18 @@ public class ClusterLRU extends LRU { if (makeIfNull) { Logger.defaultLogError("For debug purposes, creating cluster which does not exist", e); } else { - throw e; + throw new IllegalAcornStateException(e); } } } return getOrCreate(uid, makeIfNull); } - public ClusterInfo get(ClusterUID uid, boolean makeIfNull) throws DatabaseException { + public ClusterInfo get(ClusterUID uid, boolean makeIfNull) throws AcornAccessVerificationException, IllegalAcornStateException { return get(uid, makeIfNull, true); - } - public int getResourceKey(ClusterUID uid, int index) { + public int getResourceKey(ClusterUID uid, int index) throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -111,20 +108,19 @@ public class ClusterLRU extends LRU { } - public int getResourceKeyWithoutMutex(ClusterUID uid, int index) { + public int getResourceKeyWithoutMutex(ClusterUID uid, int index) throws IllegalAcornStateException { acquireMutex(); try { return getResourceKey(uid, index); } catch (Throwable t) { - throw new IllegalStateException(t); + throw new IllegalAcornStateException(t); } finally { releaseMutex(); } - } - public int createClusterKeyByClusterUID(ClusterUID uid) { + public int createClusterKeyByClusterUID(ClusterUID uid) throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -137,7 +133,7 @@ public class ClusterLRU extends LRU { } - public ClusterBase getClusterByClusterUIDOrMake(ClusterUID uid) throws DatabaseException { + public ClusterBase getClusterByClusterUIDOrMake(ClusterUID uid) throws AcornAccessVerificationException, IllegalAcornStateException { if(VERIFY) verifyAccess(); @@ -146,7 +142,7 @@ public class ClusterLRU extends LRU { } - public int getClusterKeyByClusterUIDOrMake(ClusterUID clusterUID) { + public int getClusterKeyByClusterUIDOrMake(ClusterUID clusterUID) throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -154,18 +150,20 @@ public class ClusterLRU extends LRU { } - public int getClusterKeyByClusterUIDOrMakeWithoutMutex(ClusterUID clusterUID) { + public int getClusterKeyByClusterUIDOrMakeWithoutMutex(ClusterUID clusterUID) throws IllegalAcornStateException, AcornAccessVerificationException { acquireMutex(); try { return getClusterKeyByClusterUIDOrMake(clusterUID); + } catch (AcornAccessVerificationException e) { + throw e; } catch (Throwable t) { - throw new IllegalStateException(t); + throw new IllegalAcornStateException(t); } finally { releaseMutex(); } } - public ClusterBase getClusterByClusterKey(int clusterKey) throws DatabaseException { + public ClusterBase getClusterByClusterKey(int clusterKey) throws AcornAccessVerificationException, IllegalAcornStateException { if(VERIFY) verifyAccess(); @@ -174,16 +172,16 @@ public class ClusterLRU extends LRU { info.acquireMutex(); try { return info.getCluster(); + } catch (IllegalAcornStateException | AcornAccessVerificationException e) { + throw e; } catch (Throwable t) { - throw new IllegalStateException(t); + throw new IllegalAcornStateException(t); } finally { info.releaseMutex(); } - } - public ClusterUID getClusterUIDByResourceKey(int resourceKey) - throws DatabaseException { + public ClusterUID getClusterUIDByResourceKey(int resourceKey) throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -192,24 +190,22 @@ public class ClusterLRU extends LRU { } - public ClusterUID getClusterUIDByResourceKeyWithoutMutex(int resourceKey) throws DatabaseException { + public ClusterUID getClusterUIDByResourceKeyWithoutMutex(int resourceKey) throws IllegalAcornStateException, AcornAccessVerificationException { acquireMutex(); try { return getClusterUIDByResourceKey(resourceKey); - } catch (Throwable t) { - throw new IllegalStateException(t); } finally { releaseMutex(); } } @SuppressWarnings("unchecked") - public T getClusterByClusterUIDOrMakeProxy(ClusterUID uid) throws DatabaseException { + public T getClusterByClusterUIDOrMakeProxy(ClusterUID uid) throws DatabaseException, AcornAccessVerificationException, IllegalAcornStateException { return (T) getClusterByClusterUIDOrMake(uid); } @SuppressWarnings("unchecked") - public T getClusterProxyByResourceKey(int resourceKey) throws DatabaseException { + public T getClusterProxyByResourceKey(int resourceKey) throws DatabaseException, AcornAccessVerificationException, IllegalAcornStateException { if(VERIFY) verifyAccess(); @@ -217,7 +213,7 @@ public class ClusterLRU extends LRU { } - public int getClusterKeyByUID(long id1, long id2) throws DatabaseException { + public int getClusterKeyByUID(long id1, long id2) throws DatabaseException, AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -225,17 +221,15 @@ public class ClusterLRU extends LRU { } - public int getClusterKeyByUIDWithoutMutex(long id1, long id2) throws DatabaseException { - + public int getClusterKeyByUIDWithoutMutex(long id1, long id2) throws DatabaseException, IllegalAcornStateException { acquireMutex(); try { return getClusterKeyByClusterUIDOrMake(ClusterUID.make(id1, id2)); } catch (Throwable t) { - throw new IllegalStateException(t); + throw new IllegalAcornStateException(t); } finally { releaseMutex(); } - }