Java 类com.hazelcast.core.ISemaphore 实例源码

项目:hazelcast-archive    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphoreReducePermits() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("test", 10);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client = newHazelcastClient(instance);
    ISemaphore semaphore = client.getSemaphore("test");
    assertEquals(10, semaphore.availablePermits());
    semaphore.reducePermits(1);
    assertEquals(9, semaphore.availablePermits());
    semaphore.tryAcquire(9);
    assertEquals(0, semaphore.availablePermits());
    semaphore.reducePermits(8);
    assertEquals(-8, semaphore.availablePermits());
    semaphore.release();
    assertEquals(-7, semaphore.availablePermits());
    semaphore.release(8);
    assertEquals(1, semaphore.availablePermits());
}
项目:hazelcast-archive    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphoreDisconnect() throws InterruptedException {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("default", 10);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client1 = newHazelcastClient(instance);
    HazelcastClient client2 = newHazelcastClient(instance);
    ISemaphore semaphore1 = client1.getSemaphore("test");
    ISemaphore semaphore2 = client2.getSemaphore("test");
    assertEquals(10, semaphore1.availablePermits());
    semaphore1.tryAcquireAttach(5);
    semaphore2.tryAcquire(3);
    semaphore1.reducePermits(1);
    assertEquals(1, semaphore2.availablePermits());
    client1.shutdown();
    assertEquals(6, semaphore2.availablePermits());
}
项目:hazelcast-archive    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphorePeerDisconnect() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("default", 10);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client1 = newHazelcastClient(instance);
    HazelcastClient client2 = newHazelcastClient(instance);
    ISemaphore semaphore1 = client1.getSemaphore("test");
    ISemaphore semaphore2 = client2.getSemaphore("test");
    semaphore2.tryAcquireAttach(5);
    semaphore2.tryAcquire(3);
    semaphore2.detach(2);
    assertEquals(2, semaphore1.availablePermits());
    client2.shutdown();
    assertEquals(5, semaphore1.availablePermits());
}
项目:vertx-hazelcast    文件:HazelcastClusterManager.java   
@Override
public void getLockWithTimeout(String name, long timeout, Handler<AsyncResult<Lock>> resultHandler) {
  ContextImpl context = (ContextImpl) vertx.getOrCreateContext();
  // Ordered on the internal blocking executor
  context.executeBlocking(() -> {
    ISemaphore iSemaphore = hazelcast.getSemaphore(LOCK_SEMAPHORE_PREFIX + name);
    boolean locked = false;
    long remaining = timeout;
    do {
      long start = System.nanoTime();
      try {
        locked = iSemaphore.tryAcquire(remaining, TimeUnit.MILLISECONDS);
      } catch (InterruptedException e) {
        // OK continue
      }
      remaining = remaining - MILLISECONDS.convert(System.nanoTime() - start, NANOSECONDS);
    } while (!locked && remaining > 0);
    if (locked) {
      return new HazelcastLock(iSemaphore);
    } else {
      throw new VertxException("Timed out waiting to get lock " + name);
    }
  }, resultHandler);
}
项目:health-and-care-developer-network    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphoreReducePermits() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("test", 10);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client = newHazelcastClient(instance);
    ISemaphore semaphore = client.getSemaphore("test");
    assertEquals(10, semaphore.availablePermits());
    semaphore.reducePermits(1);
    assertEquals(9, semaphore.availablePermits());
    semaphore.tryAcquire(9);
    assertEquals(0, semaphore.availablePermits());
    semaphore.reducePermits(8);
    assertEquals(-8, semaphore.availablePermits());
    semaphore.release();
    assertEquals(-7, semaphore.availablePermits());
    semaphore.release(8);
    assertEquals(1, semaphore.availablePermits());
}
项目:health-and-care-developer-network    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphoreDisconnect() throws InterruptedException {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("default", 10);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client1 = newHazelcastClient(instance);
    HazelcastClient client2 = newHazelcastClient(instance);
    ISemaphore semaphore1 = client1.getSemaphore("test");
    ISemaphore semaphore2 = client2.getSemaphore("test");
    assertEquals(10, semaphore1.availablePermits());
    semaphore1.tryAcquireAttach(5);
    semaphore2.tryAcquire(3);
    semaphore1.reducePermits(1);
    assertEquals(1, semaphore2.availablePermits());
    client1.shutdown();
    assertEquals(6, semaphore2.availablePermits());
}
项目:health-and-care-developer-network    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphorePeerDisconnect() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("default", 10);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client1 = newHazelcastClient(instance);
    HazelcastClient client2 = newHazelcastClient(instance);
    ISemaphore semaphore1 = client1.getSemaphore("test");
    ISemaphore semaphore2 = client2.getSemaphore("test");
    semaphore2.tryAcquireAttach(5);
    semaphore2.tryAcquire(3);
    semaphore2.detach(2);
    assertEquals(2, semaphore1.availablePermits());
    client2.shutdown();
    assertEquals(5, semaphore1.availablePermits());
}
项目:ahome-tooling-server-hazelcast    文件:HazelcastContextInstance.java   
@Override
public ISemaphore getISemaphore(String name)
{
    name = Objects.requireNonNull(name);

    final ISemaphore valu = getBeanSafely(name, ISemaphore.class);

    if (null != valu)
    {
        return valu;
    }
    return hz().getSemaphore(name);
}
项目:hazelcast-archive    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSimpleSemaphore() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("test", 1);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client = newHazelcastClient(instance);
    ISemaphore semaphore = client.getSemaphore("test");
    assertEquals(1, semaphore.availablePermits());
    semaphore.tryAcquire();
    assertEquals(0, semaphore.availablePermits());
    semaphore.release();
    assertEquals(1, semaphore.availablePermits());
}
项目:hazelcast-archive    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphoreIncreasePermits() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("default", 1);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client = newHazelcastClient(instance);
    ISemaphore semaphore = client.getSemaphore("test");
    assertEquals(1, semaphore.availablePermits());
    semaphore.release();
    assertEquals(2, semaphore.availablePermits());
}
项目:health-and-care-developer-network    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSimpleSemaphore() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("test", 1);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client = newHazelcastClient(instance);
    ISemaphore semaphore = client.getSemaphore("test");
    assertEquals(1, semaphore.availablePermits());
    semaphore.tryAcquire();
    assertEquals(0, semaphore.availablePermits());
    semaphore.release();
    assertEquals(1, semaphore.availablePermits());
}
项目:health-and-care-developer-network    文件:HazelcastClientSemaphoreTest.java   
@Test
public void testSemaphoreIncreasePermits() {
    SemaphoreConfig semaphoreConfig = new SemaphoreConfig("default", 1);
    Config config = new Config();
    config.addSemaphoreConfig(semaphoreConfig);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    HazelcastClient client = newHazelcastClient(instance);
    ISemaphore semaphore = client.getSemaphore("test");
    assertEquals(1, semaphore.availablePermits());
    semaphore.release();
    assertEquals(2, semaphore.availablePermits());
}
项目:xm-ms-entity    文件:WebConfigurerIntTest.java   
@Override
public ISemaphore getSemaphore(String s) {
    return null;
}
项目:hazelcast-locks    文件:HazelcastSemaphore.java   
public HazelcastSemaphore(ISemaphore delegate)
{
    this.delegate = delegate;
}
项目:Cherry    文件:HazelcastService.java   
@Override
public ISemaphore getSemaphore(final String name) {
  return getHazelcastInstance().getSemaphore(name);
}
项目:hazelcast-archive    文件:SemaphoreMBean.java   
public SemaphoreMBean(ISemaphore managedObject, ManagementService managementService) {
    super(managedObject, managementService);
}
项目:vertx-hazelcast    文件:HazelcastClusterManager.java   
private HazelcastLock(ISemaphore semaphore) {
  this.semaphore = semaphore;
}
项目:health-and-care-developer-network    文件:SemaphoreMBean.java   
public SemaphoreMBean(ISemaphore managedObject, ManagementService managementService) {
    super(managedObject, managementService);
}
项目:ahome-tooling-server-hazelcast    文件:IHazelcastContext.java   
public ISemaphore getISemaphore(String name);