Search in sources :

Example 1 with Clustered

use of fish.payara.cluster.Clustered in project Payara by payara.

the class ClusterScopeContext method get.

@Override
@SuppressWarnings("unchecked")
public <TT> TT get(Contextual<TT> contextual) {
    final Bean<TT> bean = (Bean<TT>) contextual;
    Clustered clusteredAnnotation = getAnnotation(beanManager, bean);
    String beanName = getBeanName(bean, clusteredAnnotation);
    TT beanInstance = (TT) clusteredLookup.getClusteredSingletonMap().get(beanName);
    if (clusteredAnnotation.callPostConstructOnAttach() && beanInstance != null && getFromApplicationScoped(contextual, Optional.<CreationalContext<TT>>absent()) == null) {
        beanManager.getContext(ApplicationScoped.class).get(contextual, beanManager.createCreationalContext(contextual));
    }
    return beanInstance;
}
Also used : Clustered(fish.payara.cluster.Clustered) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Bean(javax.enterprise.inject.spi.Bean)

Example 2 with Clustered

use of fish.payara.cluster.Clustered in project Payara by payara.

the class ClusteredAnnotationProcessor method processAnnotatedType.

public <X> void processAnnotatedType(ProcessAnnotatedType<X> annotatedType, BeanManager beanManager) {
    Clustered clusteredAnnotation = annotatedType.getAnnotatedType().getAnnotation(Clustered.class);
    if (clusteredAnnotation != null && !isEJB(annotatedType)) {
        validate(annotatedType.getAnnotatedType(), beanManager);
        annotatedType.setAnnotatedType(new ClusteredAnnotatedType<>(annotatedType.getAnnotatedType()));
    }
}
Also used : Clustered(fish.payara.cluster.Clustered)

Example 3 with Clustered

use of fish.payara.cluster.Clustered in project Payara by payara.

the class SingletonHandler method doSingletonSpecificProcessing.

private void doSingletonSpecificProcessing(EjbSessionDescriptor desc, Class<?> ejbClass) throws AnnotationProcessorException {
    Class<?> clz = ejbClass;
    Startup st = clz.getAnnotation(Startup.class);
    if (st != null) {
        // Only set if not explicitly set in .xml
        desc.setInitOnStartupIfNotAlreadySet(true);
    }
    DependsOn dep = clz.getAnnotation(DependsOn.class);
    if (dep != null) {
        desc.setDependsOnIfNotSet(dep.value());
    }
    Clustered clusteredAnnotation = clz.getAnnotation(Clustered.class);
    if (clusteredAnnotation != null) {
        desc.setClustered(true);
        desc.setClusteredKeyValue(clusteredAnnotation.keyName());
        desc.setDontCallPostConstructOnAttach(!clusteredAnnotation.callPostConstructOnAttach());
        desc.setDontCallPreDestroyOnDetach(!clusteredAnnotation.callPreDestoyOnDetach());
    }
}
Also used : DependsOn(javax.ejb.DependsOn) Clustered(fish.payara.cluster.Clustered) Startup(javax.ejb.Startup)

Example 4 with Clustered

use of fish.payara.cluster.Clustered in project Payara by payara.

the class ClusterScopedInterceptor method preDestroy.

@PreDestroy
Object preDestroy(InvocationContext invocationContext) throws Exception {
    Class<?> beanClass = invocationContext.getTarget().getClass().getSuperclass();
    Clustered clusteredAnnotation = getAnnotation(beanManager, beanClass);
    clusteredLookup.setClusteredSessionKey(beanClass);
    IAtomicLong count = clusteredLookup.getClusteredUsageCount();
    if (count.decrementAndGet() <= 0) {
        clusteredLookup.getClusteredSingletonMap().delete(clusteredLookup.getClusteredSessionKey());
        count.destroy();
    } else if (!clusteredAnnotation.callPreDestoyOnDetach()) {
        return null;
    }
    return invocationContext.proceed();
}
Also used : Clustered(fish.payara.cluster.Clustered) IAtomicLong(com.hazelcast.core.IAtomicLong) PreDestroy(javax.annotation.PreDestroy)

Example 5 with Clustered

use of fish.payara.cluster.Clustered in project Payara by payara.

the class ClusterScopedInterceptor method lockAndRefresh.

@AroundInvoke
public Object lockAndRefresh(InvocationContext invocationContext) throws Exception {
    Class<?> beanClass = invocationContext.getMethod().getDeclaringClass();
    Clustered clusteredAnnotation = getAnnotation(beanManager, beanClass);
    try {
        lock(beanClass, clusteredAnnotation);
        return invocationContext.proceed();
    } finally {
        refresh(beanClass);
        unlock(beanClass, clusteredAnnotation);
    }
}
Also used : Clustered(fish.payara.cluster.Clustered) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

Clustered (fish.payara.cluster.Clustered)5 IAtomicLong (com.hazelcast.core.IAtomicLong)1 PreDestroy (javax.annotation.PreDestroy)1 DependsOn (javax.ejb.DependsOn)1 Startup (javax.ejb.Startup)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Bean (javax.enterprise.inject.spi.Bean)1 AroundInvoke (javax.interceptor.AroundInvoke)1