Search in sources :

Example 86 with Operation

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);
    }
}
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 87 with Operation

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();
}
Also used : DrainOperation(com.hazelcast.concurrent.semaphore.operations.DrainOperation) 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 88 with Operation

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();
}
Also used : 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) ReduceOperation(com.hazelcast.concurrent.semaphore.operations.ReduceOperation)

Example 89 with Operation

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);
    }
}
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)

Example 90 with Operation

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());
    }
}
Also used : SemaphoreDetachMemberOperation(com.hazelcast.concurrent.semaphore.operations.SemaphoreDetachMemberOperation) OperationService(com.hazelcast.spi.OperationService) SemaphoreReplicationOperation(com.hazelcast.concurrent.semaphore.operations.SemaphoreReplicationOperation) Operation(com.hazelcast.spi.Operation) SemaphoreDetachMemberOperation(com.hazelcast.concurrent.semaphore.operations.SemaphoreDetachMemberOperation) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Operation (com.hazelcast.spi.Operation)94 OperationService (com.hazelcast.spi.OperationService)14 Member (com.hazelcast.core.Member)13 Address (com.hazelcast.nio.Address)11 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)8 ArrayList (java.util.ArrayList)8 ILogger (com.hazelcast.logging.ILogger)7 UrgentSystemOperation (com.hazelcast.spi.UrgentSystemOperation)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 AcquireOperation (com.hazelcast.concurrent.semaphore.operations.AcquireOperation)6 AvailableOperation (com.hazelcast.concurrent.semaphore.operations.AvailableOperation)6 DrainOperation (com.hazelcast.concurrent.semaphore.operations.DrainOperation)6 InitOperation (com.hazelcast.concurrent.semaphore.operations.InitOperation)6 ReduceOperation (com.hazelcast.concurrent.semaphore.operations.ReduceOperation)6 ReleaseOperation (com.hazelcast.concurrent.semaphore.operations.ReleaseOperation)6 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)6 NodeEngine (com.hazelcast.spi.NodeEngine)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6