use of javax.enterprise.context.spi.Context in project core by weld.
the class InstanceImpl method destroy.
@Override
public void destroy(T instance) {
checkNotNull(instance);
// Attempt to destroy instance which is either a client proxy or a dependent session bean proxy
if (instance instanceof ProxyObject) {
ProxyObject proxy = (ProxyObject) instance;
if (proxy.getHandler() instanceof ProxyMethodHandler) {
ProxyMethodHandler handler = (ProxyMethodHandler) proxy.getHandler();
Bean<?> bean = handler.getBean();
if (isSessionBeanProxy(instance) && Dependent.class.equals(bean.getScope())) {
// Destroy internal reference to a dependent session bean
destroyDependentInstance(instance);
return;
} else {
// Destroy contextual instance of a normal-scoped bean
Context context = getBeanManager().getContext(bean.getScope());
if (context instanceof AlterableContext) {
AlterableContext alterableContext = (AlterableContext) context;
alterableContext.destroy(bean);
return;
} else {
throw BeanLogger.LOG.destroyUnsupported(context);
}
}
}
}
// Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy
destroyDependentInstance(instance);
}
use of javax.enterprise.context.spi.Context in project HotswapAgent by HotswapProjects.
the class BeanClassRefreshAgent method doReloadBeanInBeanContexts.
private static void doReloadBeanInBeanContexts(BeanManagerImpl beanManager, Class<?> beanClass, InjectionTargetBean<?> bean) {
try {
Map<Class<? extends Annotation>, Context> singleContextMap = getSingleContextMap(beanManager);
Context context = singleContextMap.get(bean.getScope());
if (context != null) {
doReloadBeanInContext(beanManager, beanClass, bean, context);
} else {
Map<Class<? extends Annotation>, List<Context>> allContexts = getContextMap(beanManager);
List<Context> ctxList = allContexts.get(bean.getScope());
if (ctxList != null) {
for (Context ctx : ctxList) {
doReloadBeanInContext(beanManager, beanClass, bean, ctx);
}
} else {
LOGGER.debug("No active contexts for bean '{}' in scope '{}'", beanClass.getName(), bean.getScope());
}
}
} catch (ContextNotActiveException e) {
LOGGER.warning("No active contexts for bean '{}'", e, beanClass.getName());
} catch (Exception e) {
LOGGER.warning("Context for '{}' failed to reload", e, beanClass.getName());
}
}
use of javax.enterprise.context.spi.Context in project HotswapAgent by HotswapProjects.
the class BeanReloadExecutor method doReloadBeanInBeanContexts.
private static void doReloadBeanInBeanContexts(BeanManagerImpl beanManager, Class<?> beanClass, ManagedBean<?> managedBean) {
try {
Map<Class<? extends Annotation>, List<Context>> contexts = getContextMap(beanManager);
List<Context> ctxList = contexts.get(managedBean.getScope());
if (ctxList != null) {
for (Context context : ctxList) {
doReloadBeanInContext(beanManager, beanClass, managedBean, context);
}
} else {
LOGGER.debug("No active contexts for bean '{}' in scope '{}'", beanClass.getName(), managedBean.getScope());
}
} catch (ContextNotActiveException e) {
LOGGER.warning("No active contexts for bean '{}'", e, beanClass.getName());
} catch (Exception e) {
LOGGER.warning("Context for '{}' failed to reload", e, beanClass.getName());
}
}
use of javax.enterprise.context.spi.Context in project AngularBeans by bessemHmidi.
the class AngularBeansCDIExtension method registerContext.
/**
* <p>
* Invoked by the container once all the annotated types has bean discovered, then registers
* the NGSessionScopeContext (and the NGSessionScoped custom CDI scope)
* </p>
*
* @see javax.enterprise.inject.spi.AfterBeanDiscovery
* @see javax.enterprise.inject.spi.BeanManager
* @see angularBeans.context.NGSessionScoped
* @see angularBeans.context.NGSessionScopeContext
*/
public void registerContext(@Observes final AfterBeanDiscovery event, BeanManager manager) {
Context context = NGSessionScopeContext.getINSTANCE();
event.addContext(context);
}
use of javax.enterprise.context.spi.Context in project tomee by apache.
the class CdiPlugin method getSessionBeanProxy.
@Override
public Object getSessionBeanProxy(final Bean<?> inBean, final Class<?> interfce, final CreationalContext<?> creationalContext) {
Object instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
synchronized (inBean) {
// singleton for the app so safe to sync on it
instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
final Class<? extends Annotation> scopeClass = inBean.getScope();
final CdiEjbBean<Object> cdiEjbBean = (CdiEjbBean<Object>) inBean;
final CreationalContext<Object> cc = (CreationalContext<Object>) creationalContext;
if (scopeClass == null || Dependent.class == scopeClass) {
// no need to add any layer, null = @New
return cdiEjbBean.createEjb(cc);
}
// only stateful normally
final InstanceBean<Object> bean = new InstanceBean<>(cdiEjbBean);
if (webBeansContext.getBeanManagerImpl().isNormalScope(scopeClass)) {
final BeanContext beanContext = cdiEjbBean.getBeanContext();
final Provider provider = webBeansContext.getNormalScopeProxyFactory().getInstanceProvider(beanContext.getClassLoader(), cdiEjbBean);
if (!beanContext.isLocalbean()) {
final List<Class> interfaces = new ArrayList<>();
final InterfaceType type = beanContext.getInterfaceType(interfce);
if (type != null) {
interfaces.addAll(beanContext.getInterfaces(type));
} else {
// can happen when looked up from impl instead of API in OWB -> default to business local
interfaces.addAll(beanContext.getInterfaces(InterfaceType.BUSINESS_LOCAL));
}
interfaces.add(Serializable.class);
interfaces.add(IntraVmProxy.class);
if (BeanType.STATEFUL.equals(beanContext.getComponentType()) || BeanType.MANAGED.equals(beanContext.getComponentType())) {
interfaces.add(BeanContext.Removable.class);
}
try {
instance = ProxyManager.newProxyInstance(interfaces.toArray(new Class<?>[interfaces.size()]), new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
try {
return method.invoke(provider.get(), args);
} catch (final InvocationTargetException ite) {
throw ite.getCause();
}
}
});
} catch (final IllegalAccessException e) {
throw new OpenEJBRuntimeException(e);
}
} else {
final NormalScopeProxyFactory normalScopeProxyFactory = webBeansContext.getNormalScopeProxyFactory();
final Class<?> proxyClass = normalScopeProxyFactory.createProxyClass(beanContext.getClassLoader(), beanContext.getBeanClass());
instance = normalScopeProxyFactory.createProxyInstance(proxyClass, provider);
}
cacheProxies.put(inBean, instance);
} else {
final Context context = webBeansContext.getBeanManagerImpl().getContext(scopeClass);
instance = context.get(bean, cc);
}
bean.setOwbProxy(instance);
return instance;
}
}
Aggregations