Search in sources :

Example 11 with ObjectNamespace

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

the class AbstractRingBufferOperation method getRingbufferWaitNotifyKey.

/**
 * Returns {@link WaitNotifyKey} of the ringbuffer.
 *
 * If the RingbufferContainer exists it reuses it's {@link RingbufferContainer#getRingEmptyWaitNotifyKey()}.
 * If the RingbufferContainer doesn't exist it creates new RingbufferWaitNotifyKey and doesn't recreate
 * the ringbuffer container.
 *
 * @return WaitNotifyKey of the ringbuffer
 */
WaitNotifyKey getRingbufferWaitNotifyKey() {
    final RingbufferService service = getService();
    final ObjectNamespace ns = RingbufferService.getRingbufferNamespace(name);
    RingbufferContainer ringbuffer = service.getContainerOrNull(getPartitionId(), ns);
    if (ringbuffer != null) {
        return ringbuffer.getRingEmptyWaitNotifyKey();
    } else {
        return new RingbufferWaitNotifyKey(ns, getPartitionId());
    }
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) RingbufferWaitNotifyKey(com.hazelcast.ringbuffer.impl.RingbufferWaitNotifyKey) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Example 12 with ObjectNamespace

use of com.hazelcast.internal.services.ObjectNamespace 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 13 with ObjectNamespace

use of com.hazelcast.internal.services.ObjectNamespace 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)

Example 14 with ObjectNamespace

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

the class ReliableTopicCreateTest method testConstruction.

@Test
public void testConstruction() {
    HazelcastInstance hz = createHazelcastInstance();
    RingbufferService ringbufferService = getNodeEngineImpl(hz).getService(RingbufferService.SERVICE_NAME);
    ReliableTopicProxy<String> topic = (ReliableTopicProxy<String>) hz.<String>getReliableTopic("foo");
    final String name = RingbufferService.TOPIC_RB_PREFIX + "foo";
    Ringbuffer ringbuffer = hz.getRingbuffer(name);
    assertSame(ringbuffer, topic.ringbuffer);
    // make sure the ringbuffer and topic are hooked up correctly
    topic.publish("item1");
    topic.publish("item2");
    assertEquals(0, ringbuffer.headSequence());
    assertEquals(1, ringbuffer.tailSequence());
    final Map<ObjectNamespace, RingbufferContainer> containers = ringbufferService.getContainers().get(ringbufferService.getRingbufferPartitionId(name));
    final ObjectNamespace ns = RingbufferService.getRingbufferNamespace(ringbuffer.getName());
    assertEquals(1, containers.size());
    assertTrue(containers.containsKey(ns));
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with ObjectNamespace

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

the class ReliableTopicCreateTest method testRingbufferConfiguration.

@Test
public void testRingbufferConfiguration() {
    Config config = new Config();
    RingbufferConfig rbConfig = new RingbufferConfig("foo").setCapacity(21);
    config.addRingBufferConfig(rbConfig);
    HazelcastInstance hz = createHazelcastInstance(config);
    RingbufferService ringbufferService = getNodeEngineImpl(hz).getService(RingbufferService.SERVICE_NAME);
    ReliableTopicProxy topic = (ReliableTopicProxy) hz.getReliableTopic("foo");
    Ringbuffer ringbuffer = hz.getRingbuffer(RingbufferService.TOPIC_RB_PREFIX + "foo");
    assertSame(ringbuffer, topic.ringbuffer);
    assertEquals(21, ringbuffer.capacity());
    // triggers the creation
    ringbuffer.size();
    final Map<ObjectNamespace, RingbufferContainer> containers = ringbufferService.getContainers().get(ringbufferService.getRingbufferPartitionId(ringbuffer.getName()));
    final ObjectNamespace ns = RingbufferService.getRingbufferNamespace(ringbuffer.getName());
    assertEquals(1, containers.size());
    assertTrue(containers.containsKey(ns));
    RingbufferContainer container = containers.get(ns);
    assertEquals(rbConfig.getCapacity(), container.getConfig().getCapacity());
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) RingbufferConfig(com.hazelcast.config.RingbufferConfig) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)28 RingbufferContainer (com.hazelcast.ringbuffer.impl.RingbufferContainer)12 RingbufferService (com.hazelcast.ringbuffer.impl.RingbufferService)10 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 DistributedObjectNamespace (com.hazelcast.internal.services.DistributedObjectNamespace)7 Test (org.junit.Test)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Config (com.hazelcast.config.Config)4 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)3 Ringbuffer (com.hazelcast.ringbuffer.Ringbuffer)3 Map (java.util.Map)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ListenerConfig (com.hazelcast.config.ListenerConfig)2 MapConfig (com.hazelcast.config.MapConfig)2 ReliableTopicConfig (com.hazelcast.config.ReliableTopicConfig)2 RingbufferConfig (com.hazelcast.config.RingbufferConfig)2 LockSupportService (com.hazelcast.internal.locksupport.LockSupportService)2 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)2