X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.acorn%2Fsrc%2Forg%2Fsimantics%2Facorn%2Flru%2FClusterInfo.java;h=f058a559d9ca54960d061b2493a9bbf600d91953;hb=HEAD;hp=1cd5822674ab4b14518707bc071ee85a2056d3d9;hpb=a0687ce02bac73aad9e0d7ddc85625016604f0db;p=simantics%2Fplatform.git 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..f058a559d 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,18 +8,24 @@ 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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ClusterInfo extends LRUObject implements Persistable { - + + private static final Logger LOGGER = LoggerFactory.getLogger(ClusterInfo.class); final private ClusterManager manager; private ClusterImpl cluster; public int changeSetId; @@ -28,23 +34,23 @@ 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) { - super(LRU, uid, readDirectory, uid.toString() + ".cluster", offset, length, false, false); + public ClusterInfo(ClusterManager manager, LRU LRU, Path readDirectory, ClusterUID uid, int offset, int length) throws AcornAccessVerificationException { + super(LRU, manager.getFileCache(), uid, readDirectory, uid.toString() + ".cluster", offset, length, false, false); this.manager = manager; this.cluster = null; LRU.map(this); } // New - public ClusterInfo(ClusterManager manager, LRU LRU, ClusterImpl cluster) { - super(LRU, cluster.getClusterUID(), LRU.getDirectory(), cluster.getClusterUID().toString() + ".cluster", true, true); + public ClusterInfo(ClusterManager manager, LRU LRU, ClusterImpl cluster) throws AcornAccessVerificationException, IllegalAcornStateException { + super(LRU, manager.getFileCache(), cluster.getClusterUID(), LRU.getDirectory(), cluster.getClusterUID().toString() + ".cluster", true, true); this.manager = manager; this.cluster = cluster; LRU.insert(this, accessTime); 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 +62,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 +86,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 +176,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 +219,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 +237,7 @@ public class ClusterInfo extends LRUObject implements P return "cluster"; } - public void scheduleUpdate() { + public void scheduleUpdate() throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -243,30 +247,24 @@ public class ClusterInfo extends LRUObject implements P } - public ClusterImpl getForUpdate() { - + public ClusterImpl getForUpdate() throws SDBException { + acquireMutex(); try { - - acquireMutex(); - assert(updateState != null); - makeResident(); 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 +276,7 @@ public class ClusterInfo extends LRUObject implements P } - public ClusterImpl getCluster() { + public ClusterImpl getCluster() throws AcornAccessVerificationException, IllegalAcornStateException { if(VERIFY) verifyAccess(); @@ -289,7 +287,7 @@ public class ClusterInfo extends LRUObject implements P } @Override - public boolean canBePersisted() { + public boolean canBePersisted() throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -302,7 +300,7 @@ public class ClusterInfo extends LRUObject implements P } - private ClusterUpdateState getUpdateState() { + private ClusterUpdateState getUpdateState() throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -310,13 +308,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,21 +324,25 @@ 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) { long start = System.nanoTime(); state.waitForUpdates(); long duration = System.nanoTime() - start; - System.err.println("Wait updates to cluster " + getKey() + " for " + (1e-6 * duration) + "ms."); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Wait updates to cluster " + getKey() + " for " + (1e-6 * duration) + "ms."); } - } @Override protected boolean overwrite() { return true; } - + + @Override + public Logger getLogger() { + return LOGGER; + } } \ No newline at end of file