Search in sources :

Example 1 with TenantControl

use of com.hazelcast.spi.tenantcontrol.TenantControl 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;
}
Also used : AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) DistributedObject(com.hazelcast.core.DistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) TenantControlServiceImpl(com.hazelcast.spi.impl.tenantcontrol.impl.TenantControlServiceImpl) EventService(com.hazelcast.spi.impl.eventservice.EventService) TenantContextAwareService(com.hazelcast.internal.services.TenantContextAwareService) TenantControl(com.hazelcast.spi.tenantcontrol.TenantControl) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) HazelcastException(com.hazelcast.core.HazelcastException)

Example 2 with TenantControl

use of com.hazelcast.spi.tenantcontrol.TenantControl in project hazelcast by hazelcast.

the class TenantControlServiceImpl method initializeTenantControl.

/**
 * Creates a new {@link TenantControl} and propagates it to other members
 * in the cluster. The tenant control is created for a single distributed
 * object which is defined by a service and object name.
 * This method must be invoked on the application thread to properly capture
 * the appropriate tenant context.
 *
 * @param serviceName the distributed service name
 * @param objectName  the distributed object name
 * @return the created tenant control
 */
public TenantControl initializeTenantControl(@Nonnull String serviceName, @Nonnull String objectName) {
    if (!isTenantControlEnabled()) {
        return TenantControl.NOOP_TENANT_CONTROL;
    }
    TenantControl tenantControl = tenantControlFactory.saveCurrentTenant();
    appendTenantControl(serviceName, objectName, tenantControl);
    try {
        invokeOnStableClusterSerial(nodeEngine, () -> new TenantControlReplicationOperation(serviceName, objectName, tenantControl), MAX_RETRIES).get();
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return tenantControl;
}
Also used : TenantControl(com.hazelcast.spi.tenantcontrol.TenantControl)

Example 3 with TenantControl

use of com.hazelcast.spi.tenantcontrol.TenantControl in project Payara by payara.

the class PayaraHazelcastTenantFactory method saveCurrentTenant.

@Override
public TenantControl saveCurrentTenant() {
    ComponentInvocation invocation = invocationMgr.getCurrentInvocation();
    TenantControl tenantControl = TenantControl.NOOP_TENANT_CONTROL;
    if (invocation != null) {
        tenantControl = invocation.getRegistryFor(TenantControl.class);
        if (tenantControl == null && ctxUtil.isInvocationLoaded()) {
            blockingDisabled = getDisableBlockingProperty.get();
            tenantControl = new PayaraHazelcastTenant();
            invocation.setRegistryFor(TenantControl.class, tenantControl);
        } else if (tenantControl == null) {
            tenantControl = TenantControl.NOOP_TENANT_CONTROL;
        }
    }
    return tenantControl;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) TenantControl(com.hazelcast.spi.tenantcontrol.TenantControl)

Example 4 with TenantControl

use of com.hazelcast.spi.tenantcontrol.TenantControl in project hazelcast by hazelcast.

the class TenantControlServiceImpl method distributedObjectDestroyed.

@Override
public void distributedObjectDestroyed(DistributedObjectEvent event) {
    // asynchronous to proxy.destroy();
    ConcurrentMap<String, TenantControl> serviceMap = tenantControlMap.get(event.getServiceName());
    if (serviceMap == null) {
        // race between create and destroy
        return;
    }
    TenantControl tc = serviceMap.remove(event.getObjectName().toString());
    if (tc == null) {
        // race between create and destroy
        return;
    }
    tc.unregisterObject();
}
Also used : TenantControl(com.hazelcast.spi.tenantcontrol.TenantControl)

Aggregations

TenantControl (com.hazelcast.spi.tenantcontrol.TenantControl)4 DistributedObject (com.hazelcast.core.DistributedObject)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 TenantContextAwareService (com.hazelcast.internal.services.TenantContextAwareService)1 DistributedObjectDestroyedException (com.hazelcast.spi.exception.DistributedObjectDestroyedException)1 AbstractDistributedObject (com.hazelcast.spi.impl.AbstractDistributedObject)1 InitializingObject (com.hazelcast.spi.impl.InitializingObject)1 EventService (com.hazelcast.spi.impl.eventservice.EventService)1 TenantControlServiceImpl (com.hazelcast.spi.impl.tenantcontrol.impl.TenantControlServiceImpl)1 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)1