Search in sources :

Example 16 with InternalOperationService

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

the class LockAdvancedTest method testLockCleanup_whenInvokingMemberDies.

@Test
public void testLockCleanup_whenInvokingMemberDies() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz = factory.newHazelcastInstance();
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz2);
    InternalOperationService operationService = getOperationService(hz2);
    warmUpPartitions(hz2);
    String name = randomNameOwnedBy(hz);
    Data key = nodeEngine.toData(name);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    operationService.invokeOnPartition(LockService.SERVICE_NAME, new SlowLockOperation(name, key, 2000), partitionId);
    sleepMillis(500);
    terminateInstance(hz2);
    final ILock lock = hz.getLock(name);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse("Lock owned by dead member should have been released!", lock.isLocked());
        }
    }, 30);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) HeapData(com.hazelcast.internal.serialization.impl.HeapData) Data(com.hazelcast.nio.serialization.Data) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) ILock(com.hazelcast.core.ILock) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with InternalOperationService

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

the class InternalPartitionServiceImpl method prepareToSafeShutdown.

@Override
public boolean prepareToSafeShutdown(long timeout, TimeUnit unit) {
    if (!node.joined()) {
        return true;
    }
    if (node.isLiteMember()) {
        return true;
    }
    CountDownLatch latch = getShutdownLatch();
    InternalOperationService operationService = nodeEngine.getOperationService();
    long timeoutMillis = unit.toMillis(timeout);
    long awaitStep = Math.min(SAFE_SHUTDOWN_MAX_AWAIT_STEP_MILLIS, timeoutMillis);
    try {
        do {
            Address masterAddress = nodeEngine.getMasterAddress();
            if (masterAddress == null) {
                logger.warning("Safe shutdown failed, master member is not known!");
                return false;
            }
            if (node.getThisAddress().equals(masterAddress)) {
                onShutdownRequest(node.getThisAddress());
            } else {
                operationService.send(new ShutdownRequestOperation(), masterAddress);
            }
            if (latch.await(awaitStep, TimeUnit.MILLISECONDS)) {
                return true;
            }
            timeoutMillis -= awaitStep;
        } while (timeoutMillis > 0);
    } catch (InterruptedException e) {
        logger.info("Safe shutdown is interrupted!");
    }
    return false;
}
Also used : Address(com.hazelcast.nio.Address) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) CountDownLatch(java.util.concurrent.CountDownLatch) ShutdownRequestOperation(com.hazelcast.internal.partition.operation.ShutdownRequestOperation)

Example 18 with InternalOperationService

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

the class TransactionLog method invokeAsync.

private void invokeAsync(NodeEngine nodeEngine, ExecutionCallback callback, TransactionLogRecord record, Operation op) {
    InternalOperationService operationService = (InternalOperationService) nodeEngine.getOperationService();
    if (record instanceof TargetAwareTransactionLogRecord) {
        Address target = ((TargetAwareTransactionLogRecord) record).getTarget();
        operationService.invokeOnTarget(op.getServiceName(), op, target);
    } else {
        operationService.asyncInvokeOnPartition(op.getServiceName(), op, op.getPartitionId(), callback);
    }
}
Also used : Address(com.hazelcast.nio.Address) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService)

Example 19 with InternalOperationService

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

the class LockServiceImpl method destroyDistributedObject.

@Override
public void destroyDistributedObject(String objectId) {
    final Data key = nodeEngine.getSerializationService().toData(objectId, StringPartitioningStrategy.INSTANCE);
    final int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    final LockStoreImpl lockStore = containers[partitionId].getLockStore(new InternalLockNamespace(objectId));
    if (lockStore != null) {
        InternalOperationService operationService = (InternalOperationService) nodeEngine.getOperationService();
        operationService.execute(new PartitionSpecificRunnable() {

            @Override
            public void run() {
                lockStore.forceUnlock(key);
            }

            @Override
            public int getPartitionId() {
                return partitionId;
            }
        });
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 20 with InternalOperationService

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

the class OperationServiceImpl_invokeOnPartitionLiteMemberTest method test_asyncInvokeOnPartition_onLiteMember.

@Test
public void test_asyncInvokeOnPartition_onLiteMember() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final HazelcastInstance instance = factory.newHazelcastInstance(liteMemberConfig);
    final InternalOperationService operationService = getOperationService(instance);
    final DummyExecutionCallback callback = new DummyExecutionCallback();
    operationService.asyncInvokeOnPartition(null, operation, 0, callback);
    assertOpenEventually(callback.responseLatch);
    assertTrue(callback.response instanceof NoDataMemberInClusterException);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)20 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 ClientEndpoint (com.hazelcast.client.ClientEndpoint)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Address (com.hazelcast.nio.Address)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 Data (com.hazelcast.nio.serialization.Data)3 InvocationBuilder (com.hazelcast.spi.InvocationBuilder)3 Operation (com.hazelcast.spi.Operation)3 OperationFactory (com.hazelcast.spi.OperationFactory)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 OperationFactoryWrapper (com.hazelcast.client.impl.operations.OperationFactoryWrapper)2 AddAndGetOperation (com.hazelcast.concurrent.atomiclong.operations.AddAndGetOperation)2 Config (com.hazelcast.config.Config)2 CancellationOperation (com.hazelcast.executor.impl.operations.CancellationOperation)2 MemberImpl (com.hazelcast.instance.MemberImpl)2 Future (java.util.concurrent.Future)2 AuthenticationCustomCredentialsMessageTask (com.hazelcast.client.impl.protocol.task.AuthenticationCustomCredentialsMessageTask)1