Package java.util.concurrent

Examples of java.util.concurrent.Semaphore.release()


                    {
                        @Override
                        public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
                        {
                            events.add(event.getType());
                            semaphore.release();
                        }
                    }
                );
            cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
View Full Code Here


            client.setData().forPath("/test/one", "alt".getBytes());
            cache.rebuildNode("/test/one");
            Assert.assertEquals(cache.getCurrentData("/test/one").getData(), "alt".getBytes());
            Assert.assertEquals(saveCounter, counter.get());

            semaphore.release(1000);
        }
        finally
        {
            CloseableUtils.closeQuietly(cache);
            CloseableUtils.closeQuietly(client);
View Full Code Here

        cache2.getListenable().addListener(new TreeCacheListener()
        {
            @Override
            public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception
            {
                semaphore.release();
            }
        });

        try
        {
View Full Code Here

            Assert.assertTrue(queue.put("2", timing.milliseconds(), TimeUnit.MILLISECONDS));   // should sit blocking in DistributedQueue
            Assert.assertTrue(timing.awaitLatch(latch));
            timing.sleepABit();
            Assert.assertFalse(queue.put("3", timing.multiple(.5).milliseconds(), TimeUnit.MILLISECONDS));

            semaphore.release(100);
            Assert.assertTrue(queue.put("3", timing.milliseconds(), TimeUnit.MILLISECONDS));
            Assert.assertTrue(queue.put("4", timing.milliseconds(), TimeUnit.MILLISECONDS));
            Assert.assertTrue(queue.put("5", timing.milliseconds(), TimeUnit.MILLISECONDS));

            for ( int i = 0; i < 5; ++i )
View Full Code Here

          } catch (IOException e) {
            // Can't fail
            e.printStackTrace();
            System.exit(1);
          } finally {
            semaphore.release();
          }
        }
      });
    }
    // Wait for them all to complete
View Full Code Here

          } catch (IOException e) {
            // Can't fail
            e.printStackTrace();
            System.exit(1);
          } finally {
            semaphore.release();
          }
        }
      });
    }
    // Wait for them all to complete
View Full Code Here

  */

  private void leaveIOCriticalSection(String key) {
        Semaphore creationSemaphore = socketCreationMap.get(key);
        if (creationSemaphore != null) {
            creationSemaphore.release();
        }
    }

    private void enterIOCriticalSection(String key) throws IOException {
        // http://dmy999.com/article/34/correct-use-of-concurrenthashmap
View Full Code Here

                @Override
                public void takeLeadership(CuratorFramework client) throws Exception
                {
                    List<String>        names = client.getChildren().forPath("/leader");
                    Assert.assertTrue(names.size() > 0);
                    semaphore.release();
                }

                @Override
                public void stateChanged(CuratorFramework client, ConnectionState newState)
                {
View Full Code Here

                    try
                    {
                        List<String>        names = client.getChildren().forPath("/leader");
                        if ( names.size() != 1 )
                        {
                            semaphore.release();
                            Exception exception = new Exception("Names size isn't 1: " + names.size());
                            error.set(exception);
                            return;
                        }
                        lockNode.set(names.get(0));
View Full Code Here

                            error.set(exception);
                            return;
                        }
                        lockNode.set(names.get(0));

                        semaphore.release();
                        if ( !timing.multiple(4).awaitLatch(internalLostLatch) )
                        {
                            error.set(new Exception("internalLostLatch await failed"));
                        }
                    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.