org.apache.curator.framework.recipes.shared.VersionedValue Java Examples
The following examples show how to use
org.apache.curator.framework.recipes.shared.VersionedValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZooKeeperCheckpointIDCounter.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public long getAndIncrement() throws Exception { while (true) { ConnectionState connState = connStateListener.getLastState(); if (connState != null) { throw new IllegalStateException("Connection state: " + connState); } VersionedValue<Integer> current = sharedCount.getVersionedValue(); int newCount = current.getValue() + 1; if (newCount < 0) { // overflow and wrap around throw new Exception("Checkpoint counter overflow. ZooKeeper checkpoint counter only supports " + "checkpoints Ids up to " + Integer.MAX_VALUE); } if (sharedCount.trySetCount(current, newCount)) { return current.getValue(); } } }
Example #2
Source File: ZooKeeperCheckpointIDCounter.java From flink with Apache License 2.0 | 6 votes |
@Override public long getAndIncrement() throws Exception { while (true) { checkConnectionState(); VersionedValue<Integer> current = sharedCount.getVersionedValue(); int newCount = current.getValue() + 1; if (newCount < 0) { // overflow and wrap around throw new Exception("Checkpoint counter overflow. ZooKeeper checkpoint counter only supports " + "checkpoints Ids up to " + Integer.MAX_VALUE); } if (sharedCount.trySetCount(current, newCount)) { return current.getValue(); } } }
Example #3
Source File: SharedCacheCoordinator.java From datawave with Apache License 2.0 | 6 votes |
/** * Increments the shared distributed counter named {@code counterName} by one. */ public void incrementCounter(String counterName) throws Exception { ArgumentChecker.notNull(counterName); SharedCount count = sharedCounters.get(counterName); Preconditions.checkArgument(count != null, "Invalid counter name: " + counterName + ". Shared counter may be down."); VersionedValue<Integer> currentCount = count.getVersionedValue(); int newCount = currentCount.getValue() + 1; int tries = 0; while (!count.trySetCount(currentCount, newCount)) { currentCount = count.getVersionedValue(); newCount = currentCount.getValue() + 1; if (++tries >= maxRetries) { // We've exceeded our max tries to update the counter. Try to re-register it and also throw an exception to // indicate that we didn't necessarily update the shared count. sharedCounters.remove(counterName); count.removeListener(sharedCountListeners.get(counterName)); count.close(); reregisterCounter(counterName, sharedCountListeners.get(counterName), newCount); throw new IllegalStateException("Unable to increment shared counter " + counterName + " after " + maxRetries + " attempts. Zookeeper connection may be down."); } } localCounters.put(counterName, newCount); }
Example #4
Source File: ZKDelegationTokenSecretManager.java From hadoop with Apache License 2.0 | 5 votes |
private void incrSharedCount(SharedCount sharedCount) throws Exception { while (true) { // Loop until we successfully increment the counter VersionedValue<Integer> versionedValue = sharedCount.getVersionedValue(); if (sharedCount.trySetCount(versionedValue, versionedValue.getValue() + 1)) { break; } } }
Example #5
Source File: ZKDelegationTokenSecretManager.java From big-c with Apache License 2.0 | 5 votes |
private void incrSharedCount(SharedCount sharedCount) throws Exception { while (true) { // Loop until we successfully increment the counter VersionedValue<Integer> versionedValue = sharedCount.getVersionedValue(); if (sharedCount.trySetCount(versionedValue, versionedValue.getValue() + 1)) { break; } } }
Example #6
Source File: ZooKeeperVersionedValue.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
public ZooKeeperVersionedValue(VersionedValue<T> versionedValue) { this.versionedValue = Preconditions.checkNotNull(versionedValue); }
Example #7
Source File: ZooKeeperVersionedValue.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
VersionedValue<T> getVersionedValue() { return versionedValue; }
Example #8
Source File: ZooKeeperVersionedValue.java From flink with Apache License 2.0 | 4 votes |
public ZooKeeperVersionedValue(VersionedValue<T> versionedValue) { this.versionedValue = Preconditions.checkNotNull(versionedValue); }
Example #9
Source File: ZooKeeperVersionedValue.java From flink with Apache License 2.0 | 4 votes |
VersionedValue<T> getVersionedValue() { return versionedValue; }