@Test public void testBlockinLock() throws InterruptedException, IOException { final LockingManagement memoryLockManager = new MemoryLockManager(UUID.randomUUID().toString()); final DefaultTransaction t1 = new DefaultTransaction(); memoryLockManager.lock(t1, "f3"); final DefaultTransaction t2 = new DefaultTransaction(); final Thread commiter = new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(4000); t1.commit(); } catch (final InterruptedException e) { e.printStackTrace(); throw new RuntimeException(e); } catch (final IOException e) { e.printStackTrace(); throw new RuntimeException(e); } } }); final long currentTime = System.currentTimeMillis(); commiter.start(); memoryLockManager.lock(t2, "f3"); final long endTime = System.currentTimeMillis(); assertTrue((endTime - currentTime) >= 3800); commiter.join(); t2.commit(); t2.close(); t1.close(); }
@SuppressFBWarnings( value = {"MWN_MISMATCHED_WAIT"}, justification = "incorrect flag; lock held (in synchronized block)") @Override public void lock(final AuthorizedLock lock, final String featureID) { AuthorizedLock featureLock = null; synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { featureLock = lock; locks.put(featureID, lock); return; } else if (featureLock.isAuthorized(lock)) { return; } } while (featureLock != lock) { synchronized (featureLock) { while (!featureLock.isStale()) { try { featureLock.wait( Math.min(5000, featureLock.getExpireTime() - System.currentTimeMillis())); } catch (final InterruptedException ex) { } catch (final Exception e) { LOGGER.error( "Memory lock manager filed to wait for lock release. Will cycle till lock is stale.", e); } } } synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { locks.put(featureID, lock); featureLock = lock; } } } }
MemoryLockManager extends AbstractLockingManagement { @SuppressFBWarnings( value = {"MWN_MISMATCHED_WAIT"}, justification = "incorrect flag; lock held (in synchronized block)") @Override public void lock(final AuthorizedLock lock, final String featureID) { AuthorizedLock featureLock = null; synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { featureLock = lock; locks.put(featureID, lock); return; } else if (featureLock.isAuthorized(lock)) { return; } } while (featureLock != lock) { synchronized (featureLock) { while (!featureLock.isStale()) { try { featureLock.wait( Math.min(5000, featureLock.getExpireTime() - System.currentTimeMillis())); } catch (final InterruptedException ex) { } catch (final Exception e) { LOGGER.error( "Memory lock manager filed to wait for lock release. Will cycle till lock is stale.", e); } } } synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { locks.put(featureID, lock); featureLock = lock; } } } } }
MemoryLockManager extends AbstractLockingManagement { @SuppressFBWarnings( value = {"MWN_MISMATCHED_WAIT"}, justification = "incorrect flag; lock held (in synchronized block)") @Override public void lock(final AuthorizedLock lock, final String featureID) { AuthorizedLock featureLock = null; synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { featureLock = lock; locks.put(featureID, lock); return; } else if (featureLock.isAuthorized(lock)) { return; } } while (featureLock != lock) { synchronized (featureLock) { while (!featureLock.isStale()) { try { featureLock.wait( Math.min(5000, featureLock.getExpireTime() - System.currentTimeMillis())); } catch (final InterruptedException ex) { } catch (final Exception e) { LOGGER.error( "Memory lock manager filed to wait for lock release. Will cycle till lock is stale.", e); } } } synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { locks.put(featureID, lock); featureLock = lock; } } } } MemoryLockManager(final String instanceName);  MemoryLockManager(final GeoWavePluginConfig pluginConfig); }
MemoryLockManager extends AbstractLockingManagement { @SuppressFBWarnings( value = {"MWN_MISMATCHED_WAIT"}, justification = "incorrect flag; lock held (in synchronized block)") @Override public void lock(final AuthorizedLock lock, final String featureID) { AuthorizedLock featureLock = null; synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { featureLock = lock; locks.put(featureID, lock); return; } else if (featureLock.isAuthorized(lock)) { return; } } while (featureLock != lock) { synchronized (featureLock) { while (!featureLock.isStale()) { try { featureLock.wait( Math.min(5000, featureLock.getExpireTime() - System.currentTimeMillis())); } catch (final InterruptedException ex) { } catch (final Exception e) { LOGGER.error( "Memory lock manager filed to wait for lock release. Will cycle till lock is stale.", e); } } } synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { locks.put(featureID, lock); featureLock = lock; } } } } MemoryLockManager(final String instanceName);  MemoryLockManager(final GeoWavePluginConfig pluginConfig); @Override void releaseAll(final AuthorizedLock lock); @Override void resetAll(final AuthorizedLock lock); @SuppressFBWarnings( value = {"MWN_MISMATCHED_WAIT"}, justification = "incorrect flag; lock held (in synchronized block)") @Override void lock(final AuthorizedLock lock, final String featureID); @Override boolean exists(final String authID); @Override void unlock(final AuthorizedLock lock, final String featureID); }
MemoryLockManager extends AbstractLockingManagement { @SuppressFBWarnings( value = {"MWN_MISMATCHED_WAIT"}, justification = "incorrect flag; lock held (in synchronized block)") @Override public void lock(final AuthorizedLock lock, final String featureID) { AuthorizedLock featureLock = null; synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { featureLock = lock; locks.put(featureID, lock); return; } else if (featureLock.isAuthorized(lock)) { return; } } while (featureLock != lock) { synchronized (featureLock) { while (!featureLock.isStale()) { try { featureLock.wait( Math.min(5000, featureLock.getExpireTime() - System.currentTimeMillis())); } catch (final InterruptedException ex) { } catch (final Exception e) { LOGGER.error( "Memory lock manager filed to wait for lock release. Will cycle till lock is stale.", e); } } } synchronized (locks) { featureLock = locks.get(featureID); if ((featureLock == null) || featureLock.isStale()) { locks.put(featureID, lock); featureLock = lock; } } } } MemoryLockManager(final String instanceName);  MemoryLockManager(final GeoWavePluginConfig pluginConfig); @Override void releaseAll(final AuthorizedLock lock); @Override void resetAll(final AuthorizedLock lock); @SuppressFBWarnings( value = {"MWN_MISMATCHED_WAIT"}, justification = "incorrect flag; lock held (in synchronized block)") @Override void lock(final AuthorizedLock lock, final String featureID); @Override boolean exists(final String authID); @Override void unlock(final AuthorizedLock lock, final String featureID);  }