public void stateChanged(CuratorFramework client, ConnectionState newState)
{
}
};
final Timing timing = new Timing();
final ExecutorService executor = Executors.newCachedThreadPool();
ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<Void>(executor);
final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try
{
client.start();
client.create().forPath(PATH);
final CountDownLatch isWaitingLatch = new CountDownLatch(1);
final AtomicBoolean isDone = new AtomicBoolean(false);
final List<Integer> counts = new CopyOnWriteArrayList<Integer>();
final Object lock = new Object();
executor.submit
(
new Callable<Void>()
{
@Override
public Void call() throws Exception
{
Watcher watcher = new Watcher()
{
@Override
public void process(WatchedEvent event)
{
synchronized(lock)
{
lock.notifyAll();
}
}
};
while ( !Thread.currentThread().isInterrupted() && client.getState() == CuratorFrameworkState.STARTED && !isDone.get() )
{
synchronized(lock)
{
int size = client.getChildren().usingWatcher(watcher).forPath(PATH).size();
counts.add(size);
isWaitingLatch.countDown();
lock.wait();
}
}
return null;
}
}
);
isWaitingLatch.await();
for ( int i = 0; i < CLIENT_QTY; ++i )
{
final int index = i;
completionService.submit
(
new Callable<Void>()
{
@Override
public Void call() throws Exception
{
CuratorFramework client = null;
DistributedQueue<String> queue = null;
try
{
client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
queue = QueueBuilder.builder(client, consumer, serializer, PATH).executor(executor).maxItems(MAX_ITEMS).putInBackground(false).lockPath("/locks").buildQueue();
queue.start();
for ( int i = 0; i < ADD_ITEMS; ++i )