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%2FClusterInfo.java;h=57dfe9f41442c0a327012e5f98efe02145bf2cba;hp=1cd5822674ab4b14518707bc071ee85a2056d3d9;hb=d9a9d77c7024260e3e3b3a8558ddc84b2a8b99b3;hpb=0144ba232323a0e4f7ec8fe0681a150faafd7caf diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterInfo.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterInfo.java index 1cd582267..57dfe9f41 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterInfo.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterInfo.java @@ -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 implements P public static final String COMPRESSION = "LZ4"; // Stub - public ClusterInfo(ClusterManager manager, LRU LRU, Path readDirectory, ClusterUID uid, int offset, int length) { + public ClusterInfo(ClusterManager manager, LRU 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 implements P } // New - public ClusterInfo(ClusterManager manager, LRU LRU, ClusterImpl cluster) { + public ClusterInfo(ClusterManager manager, LRU 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 implements P LRU.swap(getKey()); } - public T clone(ClusterUID uid, ClusterCreator creator) throws DatabaseException { + public 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 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 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 implements P } @Override - protected Pair toBytes() { - + protected Pair toBytes() throws IllegalAcornStateException { try { - byte[] raw = null; if(cluster instanceof ClusterSmall) { @@ -215,7 +216,7 @@ public class ClusterInfo extends LRUObject 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 implements P return "cluster"; } - public void scheduleUpdate() { + public void scheduleUpdate() throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -243,10 +244,8 @@ public class ClusterInfo extends LRUObject implements P } - public ClusterImpl getForUpdate() { - + public ClusterImpl getForUpdate() throws SDBException { try { - acquireMutex(); assert(updateState != null); @@ -255,18 +254,16 @@ public class ClusterInfo extends LRUObject 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 implements P } - public ClusterImpl getCluster() { + public ClusterImpl getCluster() throws AcornAccessVerificationException, IllegalAcornStateException { if(VERIFY) verifyAccess(); @@ -289,7 +286,7 @@ public class ClusterInfo extends LRUObject implements P } @Override - public boolean canBePersisted() { + public boolean canBePersisted() throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -302,7 +299,7 @@ public class ClusterInfo extends LRUObject implements P } - private ClusterUpdateState getUpdateState() { + private ClusterUpdateState getUpdateState() throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -310,13 +307,13 @@ public class ClusterInfo extends LRUObject 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 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 implements P long duration = System.nanoTime() - start; System.err.println("Wait updates to cluster " + getKey() + " for " + (1e-6 * duration) + "ms."); } - } @Override