Search in sources :

Example 16 with ObjectNamespace

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

the class PartitionControlledIdTest method testRingbuffer.

@Test
public void testRingbuffer() {
    String partitionKey = "hazelcast";
    HazelcastInstance hz = getHazelcastInstance(partitionKey);
    Ringbuffer<String> ringbuffer = hz.getRingbuffer("ringbuffer@" + partitionKey);
    ringbuffer.add("foo");
    assertEquals("ringbuffer@" + partitionKey, ringbuffer.getName());
    assertEquals(partitionKey, ringbuffer.getPartitionKey());
    RingbufferService service = getNodeEngine(hz).getService(RingbufferService.SERVICE_NAME);
    final Map<ObjectNamespace, RingbufferContainer> partitionContainers = service.getContainers().get(service.getRingbufferPartitionId(ringbuffer.getName()));
    assertNotNull(partitionContainers);
    assertTrue(partitionContainers.containsKey(RingbufferService.getRingbufferNamespace(ringbuffer.getName())));
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 17 with ObjectNamespace

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

the class ProxyManager method getOrCreateProxyInternal.

private ClientProxy getOrCreateProxyInternal(@Nonnull String service, @Nonnull String id, boolean remote) {
    checkNotNull(service, "Service name is required!");
    checkNotNull(id, "Object name is required!");
    final ObjectNamespace ns = new DistributedObjectNamespace(service, id);
    ClientProxyFuture proxyFuture = proxies.get(ns);
    if (proxyFuture != null) {
        return proxyFuture.get();
    }
    ClientProxyFactory factory = proxyFactories.get(service);
    if (factory == null) {
        throw new ClientServiceNotFoundException("No factory registered for service: " + service);
    }
    proxyFuture = new ClientProxyFuture();
    ClientProxyFuture current = proxies.putIfAbsent(ns, proxyFuture);
    if (current != null) {
        return current.get();
    }
    try {
        ClientProxy clientProxy = createClientProxy(id, factory);
        if (remote) {
            initialize(clientProxy);
        } else {
            clientProxy.onInitialize();
        }
        proxyFuture.set(clientProxy);
        return clientProxy;
    } catch (Throwable e) {
        proxies.remove(ns);
        proxyFuture.set(e);
        throw rethrow(e);
    }
}
Also used : DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ClientServiceNotFoundException(com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Example 18 with ObjectNamespace

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

the class ProxyManager method destroyProxy.

/**
 * Destroys the given proxy in a cluster-wide way.
 * <p>
 * Upon successful completion the proxy is unregistered in this proxy
 * manager, all local resources associated with the proxy are released and
 * a distributed object destruction operation is issued to the cluster.
 * <p>
 * If the given proxy instance is not registered in this proxy manager, the
 * proxy instance is considered stale. In this case, this stale instance is
 * a subject to a local-only destruction and its registered counterpart, if
 * there is any, is a subject to a cluster-wide destruction.
 *
 * @param proxy the proxy to destroy.
 */
public void destroyProxy(ClientProxy proxy) {
    ObjectNamespace objectNamespace = new DistributedObjectNamespace(proxy.getServiceName(), proxy.getDistributedObjectName());
    ClientProxyFuture registeredProxyFuture = proxies.remove(objectNamespace);
    ClientProxy registeredProxy = registeredProxyFuture == null ? null : registeredProxyFuture.get();
    try {
        if (registeredProxy != null) {
            try {
                registeredProxy.destroyLocally();
            } finally {
                registeredProxy.destroyRemotely();
            }
        }
    } finally {
        if (proxy != registeredProxy) {
            // The given proxy is stale and was already destroyed, but the caller
            // may have allocated local resources in the context of this stale proxy
            // instance after it was destroyed, so we have to cleanup it locally one
            // more time to make sure there are no leaking local resources.
            proxy.destroyLocally();
        }
    }
}
Also used : DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Example 19 with ObjectNamespace

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

the class ProxyManager method createDistributedObjectsOnCluster.

public void createDistributedObjectsOnCluster() {
    List<Map.Entry<String, String>> proxyEntries = new LinkedList<>();
    for (ObjectNamespace objectNamespace : proxies.keySet()) {
        String name = objectNamespace.getObjectName();
        String serviceName = objectNamespace.getServiceName();
        proxyEntries.add(new AbstractMap.SimpleEntry<>(name, serviceName));
    }
    if (proxyEntries.isEmpty()) {
        return;
    }
    ClientMessage clientMessage = ClientCreateProxiesCodec.encodeRequest(proxyEntries);
    new ClientInvocation(client, clientMessage, null).invokeUrgent();
    createCachesOnCluster();
}
Also used : AbstractMap(java.util.AbstractMap) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) LinkedList(java.util.LinkedList)

Example 20 with ObjectNamespace

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

the class NameSpaceUtil method getAllNamespaces.

/**
 * @param containers      collection of all containers in a partition
 * @param containerFilter allows only matching containers
 * @param toNamespace     returns {@link ObjectNamespace} for a container
 *
 * @return all service namespaces after functions are applied
 */
public static <T> Collection<ServiceNamespace> getAllNamespaces(Map<?, T> containers, Predicate<T> containerFilter, Function<T, ObjectNamespace> toNamespace) {
    if (MapUtil.isNullOrEmpty(containers)) {
        return Collections.emptySet();
    }
    Collection<ServiceNamespace> collection = Collections.emptySet();
    for (T container : containers.values()) {
        if (!containerFilter.test(container)) {
            continue;
        }
        ObjectNamespace namespace = toNamespace.apply(container);
        if (collection.isEmpty()) {
            collection = singleton(namespace);
            continue;
        }
        if (collection.size() == 1) {
            // previous is an immutable singleton set
            collection = new HashSet<>(collection);
            collection.add(namespace);
            continue;
        }
        collection.add(namespace);
    }
    return collection;
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

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