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<ClusterUID, ClusterInfo> implements Persistable {
-
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ClusterInfo.class);
final private ClusterManager manager;
private ClusterImpl cluster;
public int changeSetId;
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;
}
// 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;
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
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();
}
}
} catch (IOException e) {
- throw new DatabaseException(e);
+ throw e;
} catch (Throwable t) {
- throw new IllegalStateException(t);
+ throw new IllegalAcornStateException(t);
} finally {
releaseMutex();
}
}
@Override
- protected Pair<byte[],Integer> toBytes() {
-
+ protected Pair<byte[],Integer> toBytes() throws IllegalAcornStateException {
try {
-
byte[] raw = null;
if(cluster instanceof ClusterSmall) {
return Pair.make(result, compressedSize+4);
} catch (Throwable t) {
- throw new IllegalStateException(t);
+ throw new IllegalAcornStateException(t);
} finally {
release();
}
return "cluster";
}
- public void scheduleUpdate() {
+ public void scheduleUpdate() throws AcornAccessVerificationException {
if(VERIFY) verifyAccess();
}
- 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();
}
- public ClusterImpl getCluster() {
+ public ClusterImpl getCluster() throws AcornAccessVerificationException, IllegalAcornStateException {
if(VERIFY) verifyAccess();
}
@Override
- public boolean canBePersisted() {
+ public boolean canBePersisted() throws AcornAccessVerificationException {
if(VERIFY) verifyAccess();
}
- private ClusterUpdateState getUpdateState() {
+ private ClusterUpdateState getUpdateState() throws AcornAccessVerificationException {
if(VERIFY) verifyAccess();
}
- 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();
}
/*
* 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