Search in sources :

Example 6 with InternalCompletableFuture

use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.

the class AbstractExecutorServiceCancelMessageTask method call.

@Override
protected Object call() throws Exception {
    InvocationBuilder builder = createInvocationBuilder();
    builder.setTryCount(CANCEL_TRY_COUNT).setTryPauseMillis(CANCEL_TRY_PAUSE_MILLIS);
    InternalCompletableFuture future = builder.invoke();
    boolean result = false;
    try {
        result = (Boolean) future.get();
    } catch (InterruptedException e) {
        logException(e);
    } catch (ExecutionException e) {
        logException(e);
    }
    return result;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with InternalCompletableFuture

use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.

the class ConditionImpl method beforeAwait.

private void beforeAwait(long threadId) {
    Data key = lockProxy.getKeyData();
    BeforeAwaitOperation op = new BeforeAwaitOperation(namespace, key, threadId, conditionId);
    InternalCompletableFuture f = invoke(op);
    f.join();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) BeforeAwaitOperation(com.hazelcast.concurrent.lock.operations.BeforeAwaitOperation) Data(com.hazelcast.nio.serialization.Data)

Example 8 with InternalCompletableFuture

use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.

the class SemaphoreProxy method release.

@Override
public void release(int permits) {
    checkNotNegative(permits, "permits can't be negative");
    Operation operation = new ReleaseOperation(name, permits).setPartitionId(partitionId);
    InternalCompletableFuture future = invokeOnPartition(operation);
    future.join();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) 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) ReleaseOperation(com.hazelcast.concurrent.semaphore.operations.ReleaseOperation)

Example 9 with InternalCompletableFuture

use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToPartitionOwner.

private <T> Future<T> submitToPartitionOwner(Callable<T> task, int partitionId, boolean preventSync) {
    checkNotNull(task, "task can't be null");
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    String uuid = newUnsecureUuidString();
    boolean sync = !preventSync && checkSync();
    Operation op = new CallableTaskOperation(name, uuid, taskData).setPartitionId(partitionId);
    InternalCompletableFuture future = invokeOnPartition(op);
    if (sync) {
        Object response;
        try {
            response = future.get();
        } catch (Exception e) {
            response = e;
        }
        return new CompletedFuture<T>(nodeEngine.getSerializationService(), response, getAsyncExecutor());
    }
    return new CancellableDelegatingFuture<T>(future, nodeEngine, uuid, partitionId);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Data(com.hazelcast.nio.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) UuidUtil.newUnsecureUuidString(com.hazelcast.util.UuidUtil.newUnsecureUuidString) ShutdownOperation(com.hazelcast.executor.impl.operations.ShutdownOperation) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) Operation(com.hazelcast.spi.Operation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) CompletedFuture(com.hazelcast.util.executor.CompletedFuture)

Example 10 with InternalCompletableFuture

use of com.hazelcast.spi.InternalCompletableFuture in project hazelcast by hazelcast.

the class ClientMapMetaDataFetcher method scanMembers.

@Override
protected List<InternalCompletableFuture> scanMembers(List<String> names) {
    Collection<Member> members = clusterService.getMembers(DATA_MEMBER_SELECTOR);
    List<InternalCompletableFuture> futures = new ArrayList<InternalCompletableFuture>(members.size());
    for (Member member : members) {
        Address address = member.getAddress();
        ClientMessage message = encodeRequest(names, address);
        ClientInvocation invocation = new ClientInvocation(clientImpl, message, address);
        try {
            futures.add(invocation.invoke());
        } catch (Exception e) {
            if (logger.isWarningEnabled()) {
                logger.warning("Cant fetch invalidation meta-data from address + " + address + " + [" + e.getMessage() + "]");
            }
        }
    }
    return futures;
}
Also used : Address(com.hazelcast.nio.Address) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) Member(com.hazelcast.core.Member) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)17 Operation (com.hazelcast.spi.Operation)6 Data (com.hazelcast.nio.serialization.Data)5 ArrayList (java.util.ArrayList)5 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 Member (com.hazelcast.core.Member)4 Address (com.hazelcast.nio.Address)3 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)2 InvocationBuilder (com.hazelcast.spi.InvocationBuilder)2 OperationService (com.hazelcast.spi.OperationService)2 CacheCreateConfigOperation (com.hazelcast.cache.impl.operation.CacheCreateConfigOperation)1 AwaitOperation (com.hazelcast.concurrent.countdownlatch.operations.AwaitOperation)1 CountDownOperation (com.hazelcast.concurrent.countdownlatch.operations.CountDownOperation)1 GetCountOperation (com.hazelcast.concurrent.countdownlatch.operations.GetCountOperation)1 SetCountOperation (com.hazelcast.concurrent.countdownlatch.operations.SetCountOperation)1 BeforeAwaitOperation (com.hazelcast.concurrent.lock.operations.BeforeAwaitOperation)1 SignalOperation (com.hazelcast.concurrent.lock.operations.SignalOperation)1 AcquireOperation (com.hazelcast.concurrent.semaphore.operations.AcquireOperation)1