]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterInfo.java
Acorn: Fix WriteRunnable.runReally() and other fixes
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / lru / ClusterInfo.java
index 1cd5822674ab4b14518707bc071ee85a2056d3d9..57dfe9f41442c0a327012e5f98efe02145bf2cba 100644 (file)
@@ -8,12 +8,15 @@ import org.simantics.acorn.ClusterManager;
 import org.simantics.acorn.Persistable;
 import org.simantics.acorn.cluster.ClusterImpl;
 import org.simantics.acorn.cluster.ClusterSmall;
+import org.simantics.acorn.exception.AcornAccessVerificationException;
+import org.simantics.acorn.exception.IllegalAcornStateException;
 import org.simantics.acorn.cluster.ClusterImpl.ClusterTables;
 import org.simantics.acorn.internal.ClusterSupport2;
 import org.simantics.compressions.CompressionCodec;
 import org.simantics.compressions.Compressions;
 import org.simantics.db.ClusterCreator;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.SDBException;
 import org.simantics.db.service.Bytes;
 import org.simantics.db.service.ClusterUID;
 import org.simantics.utils.datastructures.Pair;
@@ -28,7 +31,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
        public static final String COMPRESSION = "LZ4";
        
        // Stub
-       public ClusterInfo(ClusterManager manager, LRU<ClusterUID, ClusterInfo> LRU, Path readDirectory, ClusterUID uid, int offset, int length) {
+       public ClusterInfo(ClusterManager manager, LRU<ClusterUID, ClusterInfo> LRU, Path readDirectory, ClusterUID uid, int offset, int length) throws AcornAccessVerificationException {
                super(LRU, uid, readDirectory, uid.toString() + ".cluster", offset, length, false, false);
                this.manager = manager;
                this.cluster = null;
@@ -36,7 +39,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
        }
        
        // New
-       public ClusterInfo(ClusterManager manager, LRU<ClusterUID, ClusterInfo> LRU, ClusterImpl cluster) {
+       public ClusterInfo(ClusterManager manager, LRU<ClusterUID, ClusterInfo> LRU, ClusterImpl cluster) throws AcornAccessVerificationException, IllegalAcornStateException {
                super(LRU, cluster.getClusterUID(), LRU.getDirectory(), cluster.getClusterUID().toString() + ".cluster", true, true);
                this.manager = manager;
                this.cluster = cluster;
@@ -44,7 +47,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                LRU.swap(getKey());
        }
        
-       public <T> T clone(ClusterUID uid, ClusterCreator creator) throws DatabaseException {
+       public <T> T clone(ClusterUID uid, ClusterCreator creator) throws IOException, AcornAccessVerificationException, IllegalAcornStateException {
                
                // Updates have been ensured at this point
                        
@@ -56,9 +59,9 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                                return creator.create(uid, tables.bytes, tables.ints, tables.longs); 
                        }
                } catch (IOException e) {
-                       throw new DatabaseException(e);
+                       throw e;
                } catch (Throwable t) {
-                       throw new IllegalStateException(t);
+                       throw new IllegalAcornStateException(t);
                } finally {
                        releaseMutex();
                }
@@ -80,9 +83,9 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                        }
 
                } catch (IOException e) {
-                       throw new DatabaseException(e);
+                       throw e;
                } catch (Throwable t) {
-                       throw new IllegalStateException(t);
+                       throw new IllegalAcornStateException(t);
                } finally {
                        releaseMutex();
                }
@@ -170,10 +173,8 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
        }
 
        @Override
-       protected Pair<byte[],Integer> toBytes() {
-               
+       protected Pair<byte[],Integer> toBytes() throws IllegalAcornStateException {
                try {
-
                        byte[] raw = null;
                        
                        if(cluster instanceof ClusterSmall) {
@@ -215,7 +216,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                        return Pair.make(result, compressedSize+4);
 
                } catch (Throwable t) {
-                       throw new IllegalStateException(t);
+                       throw new IllegalAcornStateException(t);
                } finally {
                        release();
                }
@@ -233,7 +234,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                return "cluster";
        }
        
-       public void scheduleUpdate() {
+       public void scheduleUpdate() throws AcornAccessVerificationException {
 
                if(VERIFY) verifyAccess();
 
@@ -243,10 +244,8 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
 
        }
        
-       public ClusterImpl getForUpdate() {
-
+       public ClusterImpl getForUpdate() throws SDBException {
                try {
-                       
                        acquireMutex();
 
                        assert(updateState != null);
@@ -255,18 +254,16 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                        setDirty(true);
                        updateState.beginUpdate();
                        return cluster;
-                       
+               } catch (IllegalAcornStateException | AcornAccessVerificationException e) {
+                   throw e;
                } catch (Throwable t) {
-                       throw new IllegalStateException(t);
+                       throw new IllegalAcornStateException(t);
                } finally {
-                       
                        releaseMutex();
-                       
                }
-
        }
        
-       public void update(ClusterImpl clu) {
+       public void update(ClusterImpl clu) throws AcornAccessVerificationException, IllegalAcornStateException {
                
                if(VERIFY) verifyAccess();
                
@@ -278,7 +275,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
 
        }
        
-       public ClusterImpl getCluster() {
+       public ClusterImpl getCluster() throws AcornAccessVerificationException, IllegalAcornStateException {
 
                if(VERIFY) verifyAccess();
 
@@ -289,7 +286,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
        }
        
        @Override
-       public boolean canBePersisted() {
+       public boolean canBePersisted() throws AcornAccessVerificationException {
                
                if(VERIFY) verifyAccess();
 
@@ -302,7 +299,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                
        }
 
-       private ClusterUpdateState getUpdateState() {
+       private ClusterUpdateState getUpdateState() throws AcornAccessVerificationException {
                
                if(VERIFY) verifyAccess();
                
@@ -310,13 +307,13 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                
        }
 
-       private ClusterUpdateState getUpdateStateWithoutMutex() {
+       private ClusterUpdateState getUpdateStateWithoutMutex() throws IllegalAcornStateException {
                
                try {
                        acquireMutex();
                        return getUpdateState();
                } catch (Throwable t) {
-                       throw new IllegalStateException(t);
+                       throw new IllegalAcornStateException(t);
                } finally {
                        releaseMutex();
                }
@@ -326,7 +323,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
        /*
         * This method blocks - no locks here
         */
-       public void waitForUpdates() {
+       public void waitForUpdates() throws IllegalAcornStateException {
                
                ClusterUpdateState state = getUpdateStateWithoutMutex();
                if(state != null) {
@@ -335,7 +332,6 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
                        long duration = System.nanoTime() - start;
                        System.err.println("Wait updates to cluster " + getKey() + " for " + (1e-6 * duration) + "ms.");
                }
-               
        }
        
        @Override