@Test public void shouldWatchOnLock() throws Exception { final LockFactory delegate = mock(LockFactory.class); final DistributedLock mock = mock(DistributedLock.class); when(mock.getKey()).thenReturn("1234"); when(delegate.getLock(eq("1234"))).thenReturn(mock); final DistributedLockWatcher watcher = new DistributedLockWatcher(delegate); final DistributedLock lock = watcher.getLock("1234"); assertEquals(DistributedLockWatcher.WatchedDistributedLock.class, lock.getClass()); }
@Override public DistributedLock getLock(String id) { final DistributedLock lock = delegate.getLock(id); final WatchedDistributedLock watchedDistributedLock = new WatchedDistributedLock(lock); locks.put(watchedDistributedLock.getKey(), watchedDistributedLock); return watchedDistributedLock; }
DistributedLockWatcher implements LockFactory, ApplicationListener<ContextClosedEvent> { @Override public DistributedLock getLock(String id) { final DistributedLock lock = delegate.getLock(id); final WatchedDistributedLock watchedDistributedLock = new WatchedDistributedLock(lock); locks.put(watchedDistributedLock.getKey(), watchedDistributedLock); return watchedDistributedLock; } }
DistributedLockWatcher implements LockFactory, ApplicationListener<ContextClosedEvent> { @Override public DistributedLock getLock(String id) { final DistributedLock lock = delegate.getLock(id); final WatchedDistributedLock watchedDistributedLock = new WatchedDistributedLock(lock); locks.put(watchedDistributedLock.getKey(), watchedDistributedLock); return watchedDistributedLock; } DistributedLockWatcher(LockFactory delegate); }
DistributedLockWatcher implements LockFactory, ApplicationListener<ContextClosedEvent> { @Override public DistributedLock getLock(String id) { final DistributedLock lock = delegate.getLock(id); final WatchedDistributedLock watchedDistributedLock = new WatchedDistributedLock(lock); locks.put(watchedDistributedLock.getKey(), watchedDistributedLock); return watchedDistributedLock; } DistributedLockWatcher(LockFactory delegate); @Override DistributedLock getLock(String id); @Override void onApplicationEvent(ContextClosedEvent event); Collection<DistributedLock> getLocks(); }
DistributedLockWatcher implements LockFactory, ApplicationListener<ContextClosedEvent> { @Override public DistributedLock getLock(String id) { final DistributedLock lock = delegate.getLock(id); final WatchedDistributedLock watchedDistributedLock = new WatchedDistributedLock(lock); locks.put(watchedDistributedLock.getKey(), watchedDistributedLock); return watchedDistributedLock; } DistributedLockWatcher(LockFactory delegate); @Override DistributedLock getLock(String id); @Override void onApplicationEvent(ContextClosedEvent event); Collection<DistributedLock> getLocks();  }