]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterLRU.java
Acorn: Fix WriteRunnable.runReally() and other fixes
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / lru / ClusterLRU.java
index 1f0db54354184c89af52d102fe622cb88d9c9926..6b5252161a814668411ae8a60d2bc5d5d0a0a643 100644 (file)
@@ -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<ClusterUID, ClusterInfo> {
 
        final private BijectionMap<ClusterUID, Integer> clusterMapping = new BijectionMap<ClusterUID, Integer>();
-       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<ClusterUID, ClusterInfo> {
 
                        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<ClusterUID, ClusterInfo> {
                        }
 
                        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<ClusterUID, ClusterInfo> {
        /*
         * 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<ClusterUID, ClusterInfo> {
                        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<ClusterUID, ClusterInfo> {
 
        }
 
-       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<ClusterUID, ClusterInfo> {
                
        }
 
-       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<ClusterUID, ClusterInfo> {
                
        }
 
-       public int getClusterKeyByClusterUIDOrMake(ClusterUID clusterUID) {
+       public int getClusterKeyByClusterUIDOrMake(ClusterUID clusterUID) throws AcornAccessVerificationException {
 
                if(VERIFY) verifyAccess();
 
@@ -154,18 +150,20 @@ public class ClusterLRU extends LRU<ClusterUID, ClusterInfo> {
                        
        }
        
-       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<ClusterUID, ClusterInfo> {
                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<ClusterUID, ClusterInfo> {
                
        }
        
-       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 extends ClusterI> T getClusterByClusterUIDOrMakeProxy(ClusterUID uid) throws DatabaseException {
+       public <T extends ClusterI> T getClusterByClusterUIDOrMakeProxy(ClusterUID uid) throws DatabaseException, AcornAccessVerificationException, IllegalAcornStateException {
                return (T) getClusterByClusterUIDOrMake(uid);
        }
 
        @SuppressWarnings("unchecked")
-       public <T extends ClusterI> T getClusterProxyByResourceKey(int resourceKey) throws DatabaseException {
+       public <T extends ClusterI> T getClusterProxyByResourceKey(int resourceKey) throws DatabaseException, AcornAccessVerificationException, IllegalAcornStateException {
                
                if(VERIFY) verifyAccess();
 
@@ -217,7 +213,7 @@ public class ClusterLRU extends LRU<ClusterUID, ClusterInfo> {
                
        }
 
-       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<ClusterUID, ClusterInfo> {
                
        }
        
-       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();
                }
-
        }