use of com.hazelcast.spi.impl.InitializingObject in project hazelcast by hazelcast.
the class ProxyRegistry method doCreateProxy.
private DistributedObjectFuture doCreateProxy(String name, UUID source, boolean initialize, DistributedObjectFuture proxyFuture, boolean local) {
boolean publishEvent = !local;
DistributedObject proxy;
try {
TenantControlServiceImpl tenantControlService = proxyService.nodeEngine.getTenantControlService();
TenantControl tenantControl = tenantControlService.getTenantControl(serviceName, name);
if (tenantControl == null) {
if (initialize && service instanceof TenantContextAwareService) {
try {
tenantControl = tenantControlService.initializeTenantControl(serviceName, name);
} catch (Exception e) {
// log and throw exception to be handled in outer catch block
proxyService.logger.warning("Error while initializing tenant control for service '" + serviceName + "' and object '" + name + "'", e);
throw e;
}
} else {
tenantControl = TenantControl.NOOP_TENANT_CONTROL;
}
}
proxy = service.createDistributedObject(name, source, local);
tenantControl.registerObject(proxy.getDestroyContextForTenant());
if (initialize && proxy instanceof InitializingObject) {
try {
((InitializingObject) proxy).initialize();
} catch (Exception e) {
// log and throw exception to be handled in outer catch block
proxyService.logger.warning("Error while initializing proxy: " + proxy, e);
throw e;
}
}
proxyFuture.set(proxy, initialize);
if (INTERNAL_OBJECTS_PREFIXES.stream().noneMatch(name::startsWith)) {
createdCounter.inc();
}
} catch (Throwable e) {
// proxy creation or initialization failed
// deregister future to avoid infinite hang on future.get()
proxyFuture.setError(e);
proxies.remove(name);
throw rethrow(e);
}
EventService eventService = proxyService.nodeEngine.getEventService();
ProxyEventProcessor callback = new ProxyEventProcessor(proxyService.listeners.values(), CREATED, serviceName, name, proxy, source);
eventService.executeEventCallback(callback);
if (publishEvent) {
publish(new DistributedObjectEventPacket(CREATED, serviceName, name, source));
}
return proxyFuture;
}
use of com.hazelcast.spi.impl.InitializingObject in project hazelcast by hazelcast.
the class DistributedObjectFutureTest method get_returnsObject_whenObjectSet.
@Test
public void get_returnsObject_whenObjectSet() throws Exception {
future.set(object, true);
assertSame(object, future.get());
InitializingObject initializingObject = (InitializingObject) object;
verify(initializingObject, never()).initialize();
}
use of com.hazelcast.spi.impl.InitializingObject in project hazelcast by hazelcast.
the class DistributedObjectFutureTest method get_returnsInitializedObject_whenUninitializedObjectSet.
@Test
public void get_returnsInitializedObject_whenUninitializedObjectSet() throws Exception {
future.set(object, false);
assertSame(object, future.get());
InitializingObject initializingObject = (InitializingObject) object;
verify(initializingObject).initialize();
}
use of com.hazelcast.spi.impl.InitializingObject in project hazelcast by hazelcast.
the class DistributedObjectFuture method initialize.
private void initialize() {
synchronized (this) {
try {
InitializingObject o = (InitializingObject) rawProxy;
o.initialize();
proxy = rawProxy;
} catch (Throwable e) {
error = e;
}
notifyAll();
}
}
Aggregations