Skip to content

Commit

Permalink
Replace OutstandingOps with JDK bundled Phaser (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun authored Oct 16, 2021
1 parent ed3cc84 commit 1038aa6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Phaser;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Stream;
Expand All @@ -58,7 +59,14 @@ class CuratorCacheImpl implements CuratorCache, CuratorCacheBridge
private final boolean clearOnClose;
private final StandardListenerManager<CuratorCacheListener> listenerManager = StandardListenerManager.standard();
private final Consumer<Exception> exceptionHandler;
private final OutstandingOps outstandingOps = new OutstandingOps(() -> callListeners(CuratorCacheListener::initialized));

private final Phaser outstandingOps = new Phaser() {
@Override
protected boolean onAdvance(int phase, int registeredParties) {
callListeners(CuratorCacheListener::initialized);
return true;
}
};

private enum State
{
Expand Down Expand Up @@ -210,10 +218,10 @@ else if ( event.getResultCode() == NONODE.intValue() )
{
handleException(event);
}
outstandingOps.decrement();
outstandingOps.arriveAndDeregister();
};

outstandingOps.increment();
outstandingOps.register();
client.getChildren().inBackground(callback).forPath(fromPath);
}
catch ( Exception e )
Expand Down Expand Up @@ -245,10 +253,10 @@ else if ( event.getResultCode() == NONODE.intValue() )
{
handleException(event);
}
outstandingOps.decrement();
outstandingOps.arriveAndDeregister();
};

outstandingOps.increment();
outstandingOps.register();
if ( compressedData )
{
client.getData().decompressed().inBackground(callback).forPath(fromPath);
Expand Down

This file was deleted.

0 comments on commit 1038aa6

Please sign in to comment.