本文整理汇总了Java中com.hazelcast.core.ISemaphore类的典型用法代码示例。如果您正苦于以下问题:Java ISemaphore类的具体用法?Java ISemaphore怎么用?Java ISemaphore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISemaphore类属于com.hazelcast.core包,在下文中一共展示了ISemaphore类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testSemaphoreReducePermits
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@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());
}
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:21,代码来源:HazelcastClientSemaphoreTest.java
示例2: testSemaphoreDisconnect
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@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());
}
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:19,代码来源:HazelcastClientSemaphoreTest.java
示例3: testSemaphorePeerDisconnect
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@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());
}
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:18,代码来源:HazelcastClientSemaphoreTest.java
示例4: getLockWithTimeout
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@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);
}
开发者ID:vert-x3,项目名称:vertx-hazelcast,代码行数:25,代码来源:HazelcastClusterManager.java
示例5: getISemaphore
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@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);
}
开发者ID:ahome-it,项目名称:ahome-tooling-server-hazelcast,代码行数:14,代码来源:HazelcastContextInstance.java
示例6: testSimpleSemaphore
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@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());
}
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:15,代码来源:HazelcastClientSemaphoreTest.java
示例7: testSemaphoreIncreasePermits
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@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());
}
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:13,代码来源:HazelcastClientSemaphoreTest.java
示例8: getSemaphore
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@Override
public ISemaphore getSemaphore(String s) {
return null;
}
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:5,代码来源:WebConfigurerIntTest.java
示例9: HazelcastSemaphore
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
public HazelcastSemaphore(ISemaphore delegate)
{
this.delegate = delegate;
}
开发者ID:ThoughtWire,项目名称:hazelcast-locks,代码行数:5,代码来源:HazelcastSemaphore.java
示例10: getSemaphore
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
@Override
public ISemaphore getSemaphore(final String name) {
return getHazelcastInstance().getSemaphore(name);
}
开发者ID:Sabadios,项目名称:Cherry,代码行数:5,代码来源:HazelcastService.java
示例11: SemaphoreMBean
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
public SemaphoreMBean(ISemaphore managedObject, ManagementService managementService) {
super(managedObject, managementService);
}
开发者ID:mdogan,项目名称:hazelcast-archive,代码行数:4,代码来源:SemaphoreMBean.java
示例12: HazelcastLock
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
private HazelcastLock(ISemaphore semaphore) {
this.semaphore = semaphore;
}
开发者ID:vert-x3,项目名称:vertx-hazelcast,代码行数:4,代码来源:HazelcastClusterManager.java
示例13: getISemaphore
import com.hazelcast.core.ISemaphore; //导入依赖的package包/类
public ISemaphore getISemaphore(String name);
开发者ID:ahome-it,项目名称:ahome-tooling-server-hazelcast,代码行数:2,代码来源:IHazelcastContext.java
注:本文中的com.hazelcast.core.ISemaphore类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论