Search in sources :

Example 1 with AcquireOperation

use of com.hazelcast.concurrent.semaphore.operations.AcquireOperation 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);
    }
}
Also used : AcquireOperation(com.hazelcast.concurrent.semaphore.operations.AcquireOperation) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) Operation(com.hazelcast.spi.Operation) AvailableOperation(com.hazelcast.concurrent.semaphore.operations.AvailableOperation) ReduceOperation(com.hazelcast.concurrent.semaphore.operations.ReduceOperation) AcquireOperation(com.hazelcast.concurrent.semaphore.operations.AcquireOperation) DrainOperation(com.hazelcast.concurrent.semaphore.operations.DrainOperation) ReleaseOperation(com.hazelcast.concurrent.semaphore.operations.ReleaseOperation) InitOperation(com.hazelcast.concurrent.semaphore.operations.InitOperation)

Example 2 with AcquireOperation

use of com.hazelcast.concurrent.semaphore.operations.AcquireOperation 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);
    }
}
Also used : AcquireOperation(com.hazelcast.concurrent.semaphore.operations.AcquireOperation) Operation(com.hazelcast.spi.Operation) AvailableOperation(com.hazelcast.concurrent.semaphore.operations.AvailableOperation) ReduceOperation(com.hazelcast.concurrent.semaphore.operations.ReduceOperation) AcquireOperation(com.hazelcast.concurrent.semaphore.operations.AcquireOperation) DrainOperation(com.hazelcast.concurrent.semaphore.operations.DrainOperation) ReleaseOperation(com.hazelcast.concurrent.semaphore.operations.ReleaseOperation) InitOperation(com.hazelcast.concurrent.semaphore.operations.InitOperation)

Aggregations

AcquireOperation (com.hazelcast.concurrent.semaphore.operations.AcquireOperation)2 AvailableOperation (com.hazelcast.concurrent.semaphore.operations.AvailableOperation)2 DrainOperation (com.hazelcast.concurrent.semaphore.operations.DrainOperation)2 InitOperation (com.hazelcast.concurrent.semaphore.operations.InitOperation)2 ReduceOperation (com.hazelcast.concurrent.semaphore.operations.ReduceOperation)2 ReleaseOperation (com.hazelcast.concurrent.semaphore.operations.ReleaseOperation)2 Operation (com.hazelcast.spi.Operation)2 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)1