public ProxyRegistry createNew(String serviceName) { return new ProxyRegistry(ProxyServiceImpl.this, serviceName); } };
public void shutdown() { for (ProxyRegistry registry : registries.values()) { registry.destroy(); } registries.clear(); listeners.clear(); }
/** * Destroys this proxy registry. */ void destroy() { for (DistributedObjectFuture future : proxies.values()) { if (!future.isSetAndInitialized()) { continue; } DistributedObject distributedObject = extractDistributedObject(future); invalidate(distributedObject); } proxies.clear(); }
@Override public void dispatchEvent(final DistributedObjectEventPacket eventPacket, Object ignore) { String serviceName = eventPacket.getServiceName(); if (eventPacket.getEventType() == CREATED) { try { final ProxyRegistry registry = getOrCreateRegistry(serviceName); if (!registry.contains(eventPacket.getName())) { registry.createProxy(eventPacket.getName(), false, true); // listeners will be called if proxy is created here. } } catch (HazelcastInstanceNotActiveException ignored) { ignore(ignored); } } else { final ProxyRegistry registry = registries.get(serviceName); if (registry != null) { registry.destroyProxy(eventPacket.getName(), false); } } }
/** * Retrieves a DistributedObjectFuture or creates it if it is not available. * If {@code initialize} is false and DistributedObject implements {@link InitializingObject}, * {@link InitializingObject#initialize()} will be called before {@link DistributedObjectFuture#get()} returns. * * @param name The name of the DistributedObject proxy object to retrieve or create. * @param publishEvent true if a DistributedObjectEvent should be fired. * @param initialize true if the DistributedObject proxy object should be initialized. */ public DistributedObjectFuture getOrCreateProxyFuture(String name, boolean publishEvent, boolean initialize) { DistributedObjectFuture proxyFuture = proxies.get(name); if (proxyFuture == null) { if (!proxyService.nodeEngine.isRunning()) { throw new HazelcastInstanceNotActiveException(); } proxyFuture = createProxy(name, publishEvent, initialize); if (proxyFuture == null) { return getOrCreateProxyFuture(name, publishEvent, initialize); } } return proxyFuture; }
@Override public void initializeDistributedObject(String serviceName, String name) { checkServiceNameNotNull(serviceName); checkObjectNameNotNull(name); ProxyRegistry registry = getOrCreateRegistry(serviceName); registry.createProxy(name, true, true); createdCounter.inc(); }
@Override public Collection<DistributedObject> getAllDistributedObjects() { Collection<DistributedObject> result = new LinkedList<DistributedObject>(); for (ProxyRegistry registry : registries.values()) { registry.getDistributedObjects(result); } return result; }
@Override public DistributedObject getDistributedObject(String serviceName, String name) { checkServiceNameNotNull(serviceName); checkObjectNameNotNull(name); ProxyRegistry registry = getOrCreateRegistry(serviceName); return registry.getOrCreateProxy(name, true); }
public void destroyLocalDistributedObject(String serviceName, String name, boolean fireEvent) { ProxyRegistry registry = registries.get(serviceName); if (registry != null) { registry.destroyProxy(name, fireEvent); destroyedCounter.inc(); } RemoteService service = nodeEngine.getService(serviceName); service.destroyDistributedObject(name); String message = "DistributedObject[" + service + " -> " + name + "] has been destroyed!"; Throwable cause = new DistributedObjectDestroyedException(message); nodeEngine.getOperationParker().cancelParkedOperations(serviceName, name, cause); }
@Override public Collection<String> getDistributedObjectNames(String serviceName) { checkServiceNameNotNull(serviceName); ProxyRegistry registry = registries.get(serviceName); if (registry == null) { return Collections.emptySet(); } else { return registry.getDistributedObjectNames(); } }
/** * Creates a DistributedObject proxy if it is not created yet * * @param name The name of the distributedObject proxy object. * @param publishEvent true if a DistributedObjectEvent should be fired. * @param initialize true if he DistributedObject proxy object should be initialized. * @return The DistributedObject instance if it is created by this method, null otherwise. */ public DistributedObjectFuture createProxy(String name, boolean publishEvent, boolean initialize) { if (proxies.containsKey(name)) { return null; } if (!proxyService.nodeEngine.isRunning()) { throw new HazelcastInstanceNotActiveException(); } DistributedObjectFuture proxyFuture = new DistributedObjectFuture(); if (proxies.putIfAbsent(name, proxyFuture) != null) { return null; } return doCreateProxy(name, publishEvent, initialize, proxyFuture); }
@Override public void dispatchEvent(final DistributedObjectEventPacket eventPacket, Object ignore) { String serviceName = eventPacket.getServiceName(); if (eventPacket.getEventType() == CREATED) { try { final ProxyRegistry registry = getOrCreateRegistry(serviceName); if (!registry.contains(eventPacket.getName())) { registry.createProxy(eventPacket.getName(), false, true); // listeners will be called if proxy is created here. } } catch (HazelcastInstanceNotActiveException ignored) { ignore(ignored); } } else { final ProxyRegistry registry = registries.get(serviceName); if (registry != null) { registry.destroyProxy(eventPacket.getName(), false); } } }
/** * Retrieves a DistributedObjectFuture or creates it if it is not available. * If {@code initialize} is false and DistributedObject implements {@link InitializingObject}, * {@link InitializingObject#initialize()} will be called before {@link DistributedObjectFuture#get()} returns. * * @param name The name of the DistributedObject proxy object to retrieve or create. * @param publishEvent true if a DistributedObjectEvent should be fired. * @param initialize true if the DistributedObject proxy object should be initialized. */ public DistributedObjectFuture getOrCreateProxyFuture(String name, boolean publishEvent, boolean initialize) { DistributedObjectFuture proxyFuture = proxies.get(name); if (proxyFuture == null) { if (!proxyService.nodeEngine.isRunning()) { throw new HazelcastInstanceNotActiveException(); } proxyFuture = createProxy(name, publishEvent, initialize); if (proxyFuture == null) { return getOrCreateProxyFuture(name, publishEvent, initialize); } } return proxyFuture; }
@Override public void initializeDistributedObject(String serviceName, String name) { checkServiceNameNotNull(serviceName); checkObjectNameNotNull(name); ProxyRegistry registry = getOrCreateRegistry(serviceName); registry.createProxy(name, true, true); createdCounter.inc(); }
@Override public Collection<DistributedObject> getAllDistributedObjects() { Collection<DistributedObject> result = new LinkedList<DistributedObject>(); for (ProxyRegistry registry : registries.values()) { registry.getDistributedObjects(result); } return result; }
@Override public DistributedObject getDistributedObject(String serviceName, String name) { checkServiceNameNotNull(serviceName); checkObjectNameNotNull(name); ProxyRegistry registry = getOrCreateRegistry(serviceName); return registry.getOrCreateProxy(name, true); }
public void destroyLocalDistributedObject(String serviceName, String name, boolean fireEvent) { ProxyRegistry registry = registries.get(serviceName); if (registry != null) { registry.destroyProxy(name, fireEvent); destroyedCounter.inc(); } RemoteService service = nodeEngine.getService(serviceName); service.destroyDistributedObject(name); String message = "DistributedObject[" + service + " -> " + name + "] has been destroyed!"; Throwable cause = new DistributedObjectDestroyedException(message); nodeEngine.getOperationParker().cancelParkedOperations(serviceName, name, cause); }
@Override public Collection<String> getDistributedObjectNames(String serviceName) { checkServiceNameNotNull(serviceName); ProxyRegistry registry = registries.get(serviceName); if (registry == null) { return Collections.emptySet(); } else { return registry.getDistributedObjectNames(); } }
/** * Creates a DistributedObject proxy if it is not created yet * * @param name The name of the distributedObject proxy object. * @param publishEvent true if a DistributedObjectEvent should be fired. * @param initialize true if he DistributedObject proxy object should be initialized. * @return The DistributedObject instance if it is created by this method, null otherwise. */ public DistributedObjectFuture createProxy(String name, boolean publishEvent, boolean initialize) { if (proxies.containsKey(name)) { return null; } if (!proxyService.nodeEngine.isRunning()) { throw new HazelcastInstanceNotActiveException(); } DistributedObjectFuture proxyFuture = new DistributedObjectFuture(); if (proxies.putIfAbsent(name, proxyFuture) != null) { return null; } return doCreateProxy(name, publishEvent, initialize, proxyFuture); }
/** * Destroys this proxy registry. */ void destroy() { for (DistributedObjectFuture future : proxies.values()) { if (!future.isSetAndInitialized()) { continue; } DistributedObject distributedObject = extractDistributedObject(future); invalidate(distributedObject); } proxies.clear(); }