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%2FLRU.java;h=b9ba72121858540c66e7c40d66990f196ecc7cea;hp=323d66d3df12ea34d2d429293801eeacfc95a23b;hb=1dfeb7d5c49b1391cd9d877e1eddab18995cb151;hpb=1956b6ed85e1df65c4df58e6cb0ac6aa296e6939 diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRU.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRU.java index 323d66d3d..b9ba72121 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRU.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRU.java @@ -16,16 +16,19 @@ import org.simantics.acorn.ClusterManager; import org.simantics.acorn.GraphClientImpl2; import org.simantics.acorn.exception.AcornAccessVerificationException; import org.simantics.acorn.exception.IllegalAcornStateException; -import org.simantics.db.common.utils.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /* * The order rule of synchronization for LRU and LRUObject is: - * § Always lock LRUObject first! + * � Always lock LRUObject first! * */ public class LRU> { - + + private static final Logger LOGGER = LoggerFactory.getLogger(LRU.class); + public static boolean VERIFY = true; final private long swapTime = 5L*1000000000L; @@ -59,7 +62,7 @@ public class LRU> { public void acquireMutex() throws IllegalAcornStateException { try { while(!mutex.tryAcquire(3, TimeUnit.SECONDS)) { - System.err.println("Mutex is taking a long time to acquire - owner is " + mutexOwner); + LOGGER.info("Mutex is taking a long time to acquire - owner is " + mutexOwner); } if(VERIFY) mutexOwner = Thread.currentThread(); @@ -75,7 +78,7 @@ public class LRU> { public void shutdown() { if (GraphClientImpl2.DEBUG) - System.err.println("Shutting down LRU writers " + writers); + LOGGER.info("Shutting down LRU writers " + writers); writers.shutdown(); try { writers.awaitTermination(60, TimeUnit.SECONDS); @@ -94,7 +97,7 @@ public class LRU> { } }); if (GraphClientImpl2.DEBUG) - System.err.println("Resuming LRU writers " + writers); + LOGGER.info("Resuming LRU writers " + writers); } /* @@ -148,6 +151,12 @@ public class LRU> { } } + + + public MapValue purge(MapKey id) { + return map.remove(id); + } + public MapValue get(MapKey key) throws AcornAccessVerificationException { if(VERIFY) verifyAccess(); @@ -513,7 +522,7 @@ public class LRU> { manager.notSafeToMakeSnapshot(new IllegalAcornStateException(t)); } t.printStackTrace(); - Logger.defaultLogError(t); + LOGGER.error("Exception happened in WriteRunnable.run", t); } } @@ -547,14 +556,28 @@ public class LRU> { boolean gotMutex = impl.tryAcquireMutex(); boolean done = false; + int count = 0; + long startTime = 0; while (!done) { if (gotMutex || borrowMutex) { runWithMutex(); done = true; } else { - System.err.println("Retry mutex acquire"); + if (count % 10 == 0) { + // Taking too long, sleep for a while. + LOGGER.warn("Retry mutex acquire"); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + } gotMutex = impl.tryAcquireMutex(); + long currentTime = System.currentTimeMillis(); + if ((currentTime - startTime) > 10) { + startTime = currentTime; + count++; + } } }