Search in sources :

Example 1 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class MultiMapPartitionContainer method clearLockStore.

private void clearLockStore(String name) {
    NodeEngine nodeEngine = service.getNodeEngine();
    LockSupportService lockService = nodeEngine.getServiceOrNull(LockSupportService.SERVICE_NAME);
    if (lockService != null) {
        DistributedObjectNamespace namespace = new DistributedObjectNamespace(MultiMapService.SERVICE_NAME, name);
        lockService.clearLockStore(partitionId, namespace);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) LockSupportService(com.hazelcast.internal.locksupport.LockSupportService)

Example 2 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class ProxyManager method destroyProxyLocally.

/**
 * Locally destroys the proxy identified by the given service and object ID.
 * <p>
 * Upon successful completion the proxy is unregistered in this proxy
 * manager and all local resources associated with the proxy are released.
 *
 * @param service the service associated with the proxy.
 * @param id      the ID of the object to destroy the proxy of.
 */
public void destroyProxyLocally(String service, String id) {
    ObjectNamespace objectNamespace = new DistributedObjectNamespace(service, id);
    ClientProxyFuture clientProxyFuture = proxies.remove(objectNamespace);
    if (clientProxyFuture != null) {
        ClientProxy clientProxy = clientProxyFuture.get();
        clientProxy.destroyLocally();
    }
}
Also used : DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Example 3 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class Invocation_BlockingTest method sync_whenHeartbeatTimeout.

// ============================ heartbeat timeout =============================================================================
// 
// ===========================================================================================================================
@Test
public void sync_whenHeartbeatTimeout() {
    int callTimeout = 5000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(factory.getAllHazelcastInstances());
    NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
    String key = generateKeyOwnedBy(remote);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we execute an operation that stall the partition.
    OperationServiceImpl opService = nodeEngine.getOperationService();
    opService.invokeOnPartition(null, new SlowOperation(5 * callTimeout), partitionId);
    // then we execute a lock operation that won't be executed because the partition is blocked.
    LockOperation op = new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), 1, -1, -1);
    InternalCompletableFuture<Object> future = opService.createInvocationBuilder(null, op, partitionId).setCallTimeout(callTimeout).invoke();
    try {
        future.joinInternal();
        fail("Invocation should failed with timeout!");
    } catch (OperationTimeoutException expected) {
        ignore(expected);
    }
    IsLockedOperation isLockedOperation = new IsLockedOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), 1);
    Boolean isLocked = (Boolean) opService.createInvocationBuilder(null, isLockedOperation, partitionId).setCallTimeout(10 * callTimeout).invoke().join();
    assertFalse(isLocked);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LockOperation(com.hazelcast.internal.locksupport.operations.LockOperation) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) IsLockedOperation(com.hazelcast.internal.locksupport.operations.IsLockedOperation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class Invocation_BlockingTest method async_whenOperationTimeout.

@Test
public void async_whenOperationTimeout() {
    int callTimeout = 5000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(factory.getAllHazelcastInstances());
    NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
    String key = generateKeyOwnedBy(remote);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we lock the lock by another thread
    OperationServiceImpl opService = nodeEngine.getOperationService();
    int otherThreadId = 2;
    opService.invokeOnPartition(new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), otherThreadId, -1, -1).setPartitionId(partitionId)).join();
    // then we execute a lock operation that won't be executed because lock is already acquired
    // we are going to do some waiting (3x call timeout)
    int threadId = 1;
    Operation op = new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), threadId, -1, 3 * callTimeout).setPartitionId(partitionId);
    final InternalCompletableFuture<Object> future = opService.invokeOnPartition(op);
    final BiConsumer<Object, Throwable> callback = getExecutionCallbackMock();
    future.whenCompleteAsync(callback);
    assertTrueEventually(() -> verify(callback).accept(Boolean.FALSE, null));
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LockOperation(com.hazelcast.internal.locksupport.operations.LockOperation) Config(com.hazelcast.config.Config) Operation(com.hazelcast.spi.impl.operationservice.Operation) IsLockedOperation(com.hazelcast.internal.locksupport.operations.IsLockedOperation) UnlockOperation(com.hazelcast.internal.locksupport.operations.UnlockOperation) LockOperation(com.hazelcast.internal.locksupport.operations.LockOperation) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class Invocation_BlockingTest method sync_whenOperationTimeout.

// ====================================================================
// 
// ====================================================================
@Test
public void sync_whenOperationTimeout() {
    int callTimeout = 5000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(factory.getAllHazelcastInstances());
    NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
    String key = generateKeyOwnedBy(remote);
    ObjectNamespace namespace = new DistributedObjectNamespace(SERVICE_NAME, key);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we lock the lock by another thread
    OperationServiceImpl opService = nodeEngine.getOperationService();
    int otherThreadId = 2;
    opService.invokeOnPartition(new LockOperation(namespace, nodeEngine.toData(key), otherThreadId, -1, -1).setPartitionId(partitionId)).join();
    // then we execute a lock operation that won't be executed because lock is already acquired
    // we are going to do some waiting (3x call timeout)
    int threadId = 1;
    Operation op = new LockOperation(namespace, nodeEngine.toData(key), threadId, -1, 3 * callTimeout).setPartitionId(partitionId);
    final InternalCompletableFuture<Object> future = opService.invokeOnPartition(op);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(future.isDone());
        }
    });
    assertEquals(Boolean.FALSE, future.join());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LockOperation(com.hazelcast.internal.locksupport.operations.LockOperation) Config(com.hazelcast.config.Config) Operation(com.hazelcast.spi.impl.operationservice.Operation) IsLockedOperation(com.hazelcast.internal.locksupport.operations.IsLockedOperation) UnlockOperation(com.hazelcast.internal.locksupport.operations.UnlockOperation) LockOperation(com.hazelcast.internal.locksupport.operations.LockOperation) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DistributedObjectNamespace (com.hazelcast.internal.services.DistributedObjectNamespace)14 Config (com.hazelcast.config.Config)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 LockOperation (com.hazelcast.internal.locksupport.operations.LockOperation)7 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)7 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 UnlockOperation (com.hazelcast.internal.locksupport.operations.UnlockOperation)4 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)4 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)3 IsLockedOperation (com.hazelcast.internal.locksupport.operations.IsLockedOperation)3 NodeEngine (com.hazelcast.spi.impl.NodeEngine)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 TimeoutException (java.util.concurrent.TimeoutException)2 ClientServiceNotFoundException (com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException)1 ServiceConfig (com.hazelcast.config.ServiceConfig)1 LockProxySupport (com.hazelcast.internal.locksupport.LockProxySupport)1