use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class SemaphoreProxy method acquire.
@Override
public void acquire(int permits) throws InterruptedException {
checkNotNegative(permits, "permits can't be negative");
try {
Operation operation = new AcquireOperation(name, permits, -1).setPartitionId(partitionId);
InternalCompletableFuture<Object> future = invokeOnPartition(operation);
future.get();
} catch (Throwable t) {
throw rethrowAllowInterrupted(t);
}
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class SemaphoreProxy method drainPermits.
@Override
public int drainPermits() {
Operation operation = new DrainOperation(name).setPartitionId(partitionId);
InternalCompletableFuture<Integer> future = invokeOnPartition(operation);
return future.join();
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class SemaphoreProxy method reducePermits.
@Override
public void reducePermits(int reduction) {
checkNotNegative(reduction, "reduction can't be negative");
Operation operation = new ReduceOperation(name, reduction).setPartitionId(partitionId);
InternalCompletableFuture<Object> future = invokeOnPartition(operation);
future.join();
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class SemaphoreProxy method tryAcquire.
@Override
public boolean tryAcquire(int permits, long timeout, TimeUnit unit) throws InterruptedException {
checkNotNegative(permits, "permits can't be negative");
try {
Operation operation = new AcquireOperation(name, permits, unit.toMillis(timeout)).setPartitionId(partitionId);
Future<Boolean> future = invokeOnPartition(operation);
return future.get();
} catch (Throwable t) {
throw rethrowAllowInterrupted(t);
}
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class SemaphoreService method onOwnerDisconnected.
private void onOwnerDisconnected(final String owner) {
OperationService operationService = nodeEngine.getOperationService();
for (Map.Entry<String, SemaphoreContainer> entry : containers.entrySet()) {
String name = entry.getKey();
SemaphoreContainer container = entry.getValue();
Operation op = new SemaphoreDetachMemberOperation(name, owner).setPartitionId(container.getPartitionId()).setValidateTarget(false).setService(this).setNodeEngine(nodeEngine).setServiceName(SERVICE_NAME);
// op will be executed on partition thread locally.
// Invocation is to handle retries (if partition is being migrated).
operationService.invokeOnTarget(SERVICE_NAME, op, nodeEngine.getThisAddress());
}
}
Aggregations