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;
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 {
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) {
}
return info;
-
+ } catch (IllegalAcornStateException | AcornAccessVerificationException e) {
+ throw e;
} catch (Throwable t) {
- throw new IllegalStateException(t);
+ throw new IllegalAcornStateException(t);
} finally {
releaseMutex();
/*
* 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 {
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();
}
- 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();
}
- public ClusterBase getClusterByClusterUIDOrMake(ClusterUID uid) throws DatabaseException {
+ public ClusterBase getClusterByClusterUIDOrMake(ClusterUID uid) throws AcornAccessVerificationException, IllegalAcornStateException {
if(VERIFY) verifyAccess();
}
- public int getClusterKeyByClusterUIDOrMake(ClusterUID clusterUID) {
+ public int getClusterKeyByClusterUIDOrMake(ClusterUID clusterUID) throws AcornAccessVerificationException {
if(VERIFY) verifyAccess();
}
- 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();
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();
}
- 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();
}
- public int getClusterKeyByUID(long id1, long id2) throws DatabaseException {
+ public int getClusterKeyByUID(long id1, long id2) throws DatabaseException, AcornAccessVerificationException {
if(VERIFY) verifyAccess();
}
- 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();
}
-
}