Search in sources :

Example 21 with NodeEngine

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

the class GetAndAlterOperation method run.

@Override
public void run() throws Exception {
    NodeEngine nodeEngine = getNodeEngine();
    IFunction f = nodeEngine.toObject(function);
    AtomicReferenceContainer atomicReferenceContainer = getReferenceContainer();
    response = atomicReferenceContainer.get();
    Object input = nodeEngine.toObject(atomicReferenceContainer.get());
    //noinspection unchecked
    Object output = f.apply(input);
    Data serializedOutput = nodeEngine.toData(output);
    shouldBackup = !isEquals(response, serializedOutput);
    if (shouldBackup) {
        atomicReferenceContainer.set(serializedOutput);
        backup = serializedOutput;
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) AtomicReferenceContainer(com.hazelcast.concurrent.atomicreference.AtomicReferenceContainer) Data(com.hazelcast.nio.serialization.Data) IFunction(com.hazelcast.core.IFunction)

Example 22 with NodeEngine

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

the class SemaphoreDetachMemberOperation method shouldBackup.

@Override
public boolean shouldBackup() {
    final NodeEngine nodeEngine = getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    IPartition partition = partitionService.getPartition(getPartitionId());
    return partition.isLocal() && Boolean.TRUE.equals(response);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) IPartitionService(com.hazelcast.spi.partition.IPartitionService) IPartition(com.hazelcast.spi.partition.IPartition)

Example 23 with NodeEngine

use of com.hazelcast.spi.NodeEngine 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 24 with NodeEngine

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

the class ExecutorServiceProxy method submitToMembers.

@Override
public <T> void submitToMembers(Callable<T> task, Collection<Member> members, MultiExecutionCallback callback) {
    NodeEngine nodeEngine = getNodeEngine();
    ExecutionCallbackAdapterFactory executionCallbackFactory = new ExecutionCallbackAdapterFactory(nodeEngine.getLogger(ExecutionCallbackAdapterFactory.class), members, callback);
    for (Member member : members) {
        submitToMember(task, member, executionCallbackFactory.<T>callbackFor(member));
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Member(com.hazelcast.core.Member)

Example 25 with NodeEngine

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

the class DurableExecutorServiceProxy method shutdown.

@Override
public void shutdown() {
    NodeEngine nodeEngine = getNodeEngine();
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Future> calls = new LinkedList<Future>();
    for (Member member : members) {
        if (member.localMember()) {
            getService().shutdownExecutor(name);
        } else {
            ShutdownOperation op = new ShutdownOperation(name);
            Future f = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
            calls.add(f);
        }
    }
    waitWithDeadline(calls, 1, TimeUnit.SECONDS, WHILE_SHUTDOWN_EXCEPTION_HANDLER);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) DurableExecutorServiceFuture(com.hazelcast.durableexecutor.DurableExecutorServiceFuture) DelegatingFuture(com.hazelcast.util.executor.DelegatingFuture) Future(java.util.concurrent.Future) CompletedFuture(com.hazelcast.util.executor.CompletedFuture) ShutdownOperation(com.hazelcast.durableexecutor.impl.operations.ShutdownOperation) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Aggregations

NodeEngine (com.hazelcast.spi.NodeEngine)157 Data (com.hazelcast.nio.serialization.Data)50 OperationService (com.hazelcast.spi.OperationService)30 Address (com.hazelcast.nio.Address)20 ILogger (com.hazelcast.logging.ILogger)14 Operation (com.hazelcast.spi.Operation)14 Member (com.hazelcast.core.Member)12 Future (java.util.concurrent.Future)12 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)11 IPartitionService (com.hazelcast.spi.partition.IPartitionService)11 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)10 Test (org.junit.Test)10 InitializingObject (com.hazelcast.spi.InitializingObject)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)7 Config (com.hazelcast.config.Config)6 ArrayList (java.util.ArrayList)6