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())));
}
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);
}
}
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();
}
}
}
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();
}
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;
}
Aggregations