@Override protected Lock initialValue() { return new ReentrantDistributedLock(zkClient, IDS_BASEPATH + "/lock"); } };
private synchronized String getItemNodePath(String key) { return getNodePath(key); }
private String getItemNodePath(String key) { return getNodePath(key); }
@Override public void run() { try { lock2.lockInterruptibly(); try { lockAcquired.countDown(); } finally { lock2.unlock(); } } catch (InterruptedException e) { lockInterrupted.countDown(); } } };
@Override public synchronized T remove(Object key) { globalLock.lock(); try { reloadCacheIfNeeded(); return removeInternal(key); } finally { globalLock.unlock(); } }
public synchronized T put(String key, T value) { globalLock.lock(); try { reloadCacheIfNeeded(); return putInternal(key, value); } finally { globalLock.unlock(); } }
public synchronized void clear() { globalLock.lock(); try { reloadCacheIfNeeded(); clearInternal(); } finally { globalLock.unlock(); } }
/** * Acquires a distributed lock through ZooKeeper. It's the same as calling * {@link #acquire(boolean, boolean, long, java.util.concurrent.TimeUnit)} with {@link Long#MAX_VALUE} as timeout. */ private boolean acquire(boolean interruptible, boolean waitForLock) throws InterruptedException, ExecutionException { try { return acquire(interruptible, waitForLock, Long.MAX_VALUE, TimeUnit.SECONDS); } catch (TimeoutException e) { // Should never happen throw Throwables.propagate(e); } }
@Override public synchronized Set<Entry<String, T>> entrySet() { globalLock.lock(); try { reloadCacheIfNeeded(); return currentView.entrySet(); } finally { globalLock.unlock(); } }
private boolean collectionEventuallyEquals(Collection<String> all, String... values) throws InterruptedException { int numRetries = 0; while (numRetries < 10) { if (checkCollectionEquals(all, values)) { return true; } numRetries++; TimeUnit.MILLISECONDS.sleep(10); } return false; }
@Override protected Lock initialValue() { return new ReentrantDistributedLock(zkClient, basePath); } };
@Override public void run() { try { lock.lockInterruptibly(); try { lockAcquired.countDown(); } finally { lock.unlock(); } } catch (InterruptedException e) { lockInterrupted.countDown(); } } };
public Lock getTenantProvisionerLock() { return new ReentrantDistributedLock(zkClient, Constants.Lock.TENANT_NAMESPACE); } }
public SynchronizedZKMap(ZKClient zkClient, Serializer<T> serializer) { this.zkClient = zkClient; this.serializer = serializer; this.currentView = Maps.newHashMap(); this.currentViewVersion = -1; this.globalLock = new ReentrantDistributedLock(zkClient, LOCK_PATH); }
public Lock getResourceLock(String tenantId, String pluginType, String pluginName, String typeName, String resourceName) { String path = Joiner.on('/') .join(Constants.Lock.PLUGIN_NAMESPACE, "resources", tenantId, pluginType, pluginName, typeName, resourceName); return new ReentrantDistributedLock(zkClient, path); }
public Lock getClusterLock(String tenantId, String clusterId) { String path = Joiner.on('/').join(Constants.Lock.CLUSTER_NAMESPACE, "clusters", tenantId, clusterId); return new ReentrantDistributedLock(zkClient, path); }
public Lock getJobLock(String tenantId, String clusterId) { String path = Joiner.on('/').join(Constants.Lock.TASK_NAMESPACE, "jobs", tenantId, clusterId); return new ReentrantDistributedLock(zkClient, path); }
public Lock getClusterCreateLock(String tenantId) { String path = Joiner.on('/').join(Constants.Lock.CLUSTER_NAMESPACE, "create", tenantId); return new ReentrantDistributedLock(zkClient, path); }