Search in sources :

Example 41 with OperationService

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

the class FinalizeJoinOp method sendPostJoinOperationsBackToMaster.

private void sendPostJoinOperationsBackToMaster() {
    final ClusterServiceImpl clusterService = getService();
    final NodeEngineImpl nodeEngine = clusterService.getNodeEngine();
    // Post join operations must be lock free; means no locks at all;
    // no partition locks, no key-based locks, no service level locks!
    Collection<Operation> postJoinOperations = nodeEngine.getPostJoinOperations();
    if (postJoinOperations != null && !postJoinOperations.isEmpty()) {
        final OperationService operationService = nodeEngine.getOperationService();
        // send post join operations to master and it will broadcast it to all members
        Address masterAddress = clusterService.getMasterAddress();
        OnJoinOp operation = new OnJoinOp(postJoinOperations);
        operationService.invokeOnTarget(ClusterServiceImpl.SERVICE_NAME, operation, masterAddress);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Address(com.hazelcast.cluster.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 42 with OperationService

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

the class OnJoinOp method run.

@Override
public void run() throws Exception {
    if (!operations.isEmpty()) {
        SecurityConfig securityConfig = getNodeEngine().getConfig().getSecurityConfig();
        boolean runPermissionUpdates = securityConfig.getOnJoinPermissionOperation() == OnJoinPermissionOperationName.RECEIVE;
        for (Operation op : operations) {
            if ((op instanceof UpdatePermissionConfigOperation) && !runPermissionUpdates) {
                continue;
            }
            try {
                // not running via OperationService since we don't want any restrictions like cluster state check etc.
                runDirect(op);
            } catch (Exception e) {
                getLogger().warning("Error while running post-join operation: " + op, e);
            }
        }
        final ClusterService clusterService = getService();
        // if executed on master, broadcast to all other members except sender (joining member)
        if (clusterService.isMaster()) {
            final OperationService operationService = getNodeEngine().getOperationService();
            for (Member member : clusterService.getMembers()) {
                if (!member.localMember() && !member.getUuid().equals(getCallerUuid())) {
                    OnJoinOp operation = new OnJoinOp(operations);
                    operationService.invokeOnTarget(getServiceName(), operation, member.getAddress());
                }
            }
        }
    }
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) SecurityConfig(com.hazelcast.config.SecurityConfig) UpdatePermissionConfigOperation(com.hazelcast.internal.management.operation.UpdatePermissionConfigOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) UpdatePermissionConfigOperation(com.hazelcast.internal.management.operation.UpdatePermissionConfigOperation) UrgentSystemOperation(com.hazelcast.spi.impl.operationservice.UrgentSystemOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Member(com.hazelcast.cluster.Member) IOException(java.io.IOException)

Example 43 with OperationService

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

the class InvocationFuture_GetNewInstanceTest method invocationToLocalMember.

@Test
public void invocationToLocalMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    OperationService service = getOperationService(local);
    Future future = service.createInvocationBuilder(null, op, localNode.address).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with OperationService

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

the class InvocationFuture_GetNewInstanceTest method invocationToRemoteMember.

@Test
public void invocationToRemoteMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    Address remoteAddress = getAddress(remote);
    OperationService operationService = getOperationService(local);
    Future future = operationService.createInvocationBuilder(null, op, remoteAddress).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with OperationService

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

the class Invocation_DetectHeartbeatTimeoutTest method whenCallTimeoutNotExpired.

@Test
public void whenCallTimeoutNotExpired() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance();
    HazelcastInstance remote = factory.newHazelcastInstance();
    OperationService opService = getOperationService(local);
    Operation operation = new SlowOperation(SECONDS.toMillis(60));
    InvocationFuture future = (InvocationFuture) opService.invokeOnPartition(null, operation, getPartitionId(remote));
    Invocation invocation = future.invocation;
    assertEquals(NO_TIMEOUT__CALL_TIMEOUT_NOT_EXPIRED, invocation.detectTimeout(SECONDS.toMillis(1)));
    assertFalse(future.isDone());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Operation(com.hazelcast.spi.impl.operationservice.Operation) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

OperationService (com.hazelcast.spi.impl.operationservice.OperationService)140 Operation (com.hazelcast.spi.impl.operationservice.Operation)55 Test (org.junit.Test)54 HazelcastInstance (com.hazelcast.core.HazelcastInstance)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)40 Address (com.hazelcast.cluster.Address)31 NodeEngine (com.hazelcast.spi.impl.NodeEngine)31 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)24 Future (java.util.concurrent.Future)24 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 Config (com.hazelcast.config.Config)22 Member (com.hazelcast.cluster.Member)21 Data (com.hazelcast.internal.serialization.Data)12 SlowTest (com.hazelcast.test.annotation.SlowTest)12 ClusterService (com.hazelcast.internal.cluster.ClusterService)9 ILogger (com.hazelcast.logging.ILogger)7 ArrayList (java.util.ArrayList)7 IPartitionService (com.hazelcast.internal.partition.IPartitionService)6