Search in sources :

Example 81 with OperationService

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

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    Node node = TestUtil.getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, ClientType>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, ClientType> clients = future.get();
    assertEquals(0, clients.size());
}
Also used : ClientType(com.hazelcast.core.ClientType) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) Operation(com.hazelcast.spi.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.OperationService) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 82 with OperationService

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

the class ExecutorServiceProxy method submitToMember.

@Override
public <T> void submitToMember(Callable<T> task, Member member, ExecutionCallback<T> callback) {
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    String uuid = newUnsecureUuidString();
    MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData);
    OperationService operationService = nodeEngine.getOperationService();
    Address address = ((MemberImpl) member).getAddress();
    operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, address).setExecutionCallback((ExecutionCallback) callback).invoke();
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) Data(com.hazelcast.nio.serialization.Data) UuidUtil.newUnsecureUuidString(com.hazelcast.util.UuidUtil.newUnsecureUuidString) OperationService(com.hazelcast.spi.OperationService) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback)

Example 83 with OperationService

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

the class ExecutorServiceProxy method submitToPartitionOwner.

private <T> void submitToPartitionOwner(Callable<T> task, ExecutionCallback<T> callback, int partitionId) {
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    Data taskData = nodeEngine.toData(task);
    CallableTaskOperation op = new CallableTaskOperation(name, null, taskData);
    OperationService operationService = nodeEngine.getOperationService();
    operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, partitionId).setExecutionCallback((ExecutionCallback) callback).invoke();
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Data(com.hazelcast.nio.serialization.Data) OperationService(com.hazelcast.spi.OperationService) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation)

Example 84 with OperationService

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

the class MemberImpl method invokeOnAllMembers.

private void invokeOnAllMembers(Operation operation) {
    NodeEngineImpl nodeEngine = instance.node.nodeEngine;
    OperationService os = nodeEngine.getOperationService();
    String uuid = nodeEngine.getLocalMember().getUuid();
    operation.setCallerUuid(uuid).setNodeEngine(nodeEngine);
    try {
        for (Member member : nodeEngine.getClusterService().getMembers()) {
            if (!member.localMember()) {
                os.send(operation, member.getAddress());
            } else {
                os.execute(operation);
            }
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Example 85 with OperationService

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

the class CancellableDelegatingFuture method invokeCancelOperation.

private Future<Boolean> invokeCancelOperation(boolean mayInterruptIfRunning) {
    CancellationOperation op = new CancellationOperation(uuid, mayInterruptIfRunning);
    OperationService opService = nodeEngine.getOperationService();
    InvocationBuilder builder;
    if (partitionId > -1) {
        builder = opService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, partitionId);
    } else {
        builder = opService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, target);
    }
    builder.setTryCount(CANCEL_TRY_COUNT).setTryPauseMillis(CANCEL_TRY_PAUSE_MILLIS);
    return builder.invoke();
}
Also used : CancellationOperation(com.hazelcast.executor.impl.operations.CancellationOperation) OperationService(com.hazelcast.spi.OperationService) InvocationBuilder(com.hazelcast.spi.InvocationBuilder)

Aggregations

OperationService (com.hazelcast.spi.OperationService)135 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)48 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 HazelcastInstance (com.hazelcast.core.HazelcastInstance)45 Operation (com.hazelcast.spi.Operation)39 NodeEngine (com.hazelcast.spi.NodeEngine)30 Address (com.hazelcast.nio.Address)26 Future (java.util.concurrent.Future)26 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 Config (com.hazelcast.config.Config)21 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)21 Member (com.hazelcast.core.Member)19 Data (com.hazelcast.nio.serialization.Data)14 ArrayList (java.util.ArrayList)11 Node (com.hazelcast.instance.Node)7 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)7 ExecutionException (java.util.concurrent.ExecutionException)7 TimeoutException (java.util.concurrent.TimeoutException)7 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)6