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