use of com.sun.enterprise.deployment.ManagedBeanDescriptor in project Payara by payara.
the class ManagedBeanManagerImpl method createManagedBean.
public <T> T createManagedBean(Class<T> managedBeanClass, boolean invokePostConstruct) throws Exception {
ManagedBeanDescriptor managedBeanDesc = null;
try {
BundleDescriptor bundle = getBundle();
managedBeanDesc = bundle.getManagedBeanByBeanClass(managedBeanClass.getName());
} catch (Exception e) {
// OK. Can mean that it's not annotated with @ManagedBean but 299 can handle it.
}
return createManagedBean(managedBeanDesc, managedBeanClass, invokePostConstruct);
}
use of com.sun.enterprise.deployment.ManagedBeanDescriptor in project Payara by payara.
the class ManagedBeanManagerImpl method registerRuntimeInterceptor.
/**
* Apply a runtime interceptor instance to all managed beans in the given module
* @param interceptorInstance
* @param bundle bundle descripto
*/
public void registerRuntimeInterceptor(Object interceptorInstance, BundleDescriptor bundle) {
for (ManagedBeanDescriptor next : bundle.getManagedBeans()) {
JavaEEInterceptorBuilder interceptorBuilder = (JavaEEInterceptorBuilder) next.getInterceptorBuilder();
interceptorBuilder.addRuntimeInterceptor(interceptorInstance);
}
}
use of com.sun.enterprise.deployment.ManagedBeanDescriptor in project Payara by payara.
the class ManagedBeanManagerImpl method destroyManagedBean.
public void destroyManagedBean(Object managedBean, boolean validate) {
BundleDescriptor bundle = getBundle();
JCDIService jcdiService = habitat.getService(JCDIService.class);
if ((jcdiService != null) && jcdiService.isJCDIEnabled(bundle)) {
Map<Object, JCDIService.JCDIInjectionContext> bundleNonManagedObjs = jcdiManagedBeanInstanceMap.get(bundle);
// in a failure scenario it's possible that bundleNonManagedObjs is null
if (bundleNonManagedObjs == null) {
if (validate) {
throw new IllegalStateException("Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
}
_logger.log(Level.FINE, "Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
} else {
JCDIService.JCDIInjectionContext context = bundleNonManagedObjs.remove(managedBean);
if (context == null) {
if (validate) {
throw new IllegalStateException("Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
}
_logger.log(Level.FINE, "Unknown JCDI-enabled managed bean " + managedBean + " of class " + managedBean.getClass());
return;
}
// Call PreDestroy and cleanup
context.cleanup(true);
}
} else {
Object managedBeanInstance = null;
try {
Field proxyField = managedBean.getClass().getDeclaredField("__ejb31_delegate");
final Field finalF = proxyField;
java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction() {
public java.lang.Object run() throws Exception {
if (!finalF.isAccessible()) {
finalF.setAccessible(true);
}
return null;
}
});
Proxy proxy = (Proxy) proxyField.get(managedBean);
InterceptorInvoker invoker = (InterceptorInvoker) Proxy.getInvocationHandler(proxy);
managedBeanInstance = invoker.getTargetInstance();
} catch (Exception e) {
throw new IllegalArgumentException("invalid managed bean " + managedBean, e);
}
ManagedBeanDescriptor desc = bundle.getManagedBeanByBeanClass(managedBeanInstance.getClass().getName());
if (desc == null) {
throw new IllegalStateException("Could not retrieve managed bean descriptor for " + managedBean + " of class " + managedBean.getClass());
}
InterceptorInvoker invoker = (InterceptorInvoker) desc.getSupportingInfoForBeanInstance(managedBeanInstance);
try {
invoker.invokePreDestroy();
} catch (Exception e) {
_logger.log(Level.FINE, "Managed bean " + desc.getBeanClassName() + " PreDestroy", e);
}
desc.clearBeanInstanceInfo(managedBeanInstance);
}
}
use of com.sun.enterprise.deployment.ManagedBeanDescriptor in project Payara by payara.
the class ManagedBeanManagerImpl method unloadManagedBeans.
public void unloadManagedBeans(Application app) {
for (BundleDescriptor bundle : app.getBundleDescriptors()) {
if (!bundleEligible(bundle)) {
continue;
}
Map<Object, JCDIService.JCDIInjectionContext> jcdiInstances = jcdiManagedBeanInstanceMap.remove(bundle);
if (jcdiInstances != null) {
for (JCDIService.JCDIInjectionContext next : jcdiInstances.values()) {
try {
next.cleanup(true);
} catch (Exception e) {
_logger.log(Level.FINE, "Exception during JCDI cleanup for " + next, e);
}
}
}
for (ManagedBeanDescriptor next : bundle.getManagedBeans()) {
for (Object instance : next.getBeanInstances()) {
InterceptorInvoker invoker = (InterceptorInvoker) next.getSupportingInfoForBeanInstance(instance);
try {
invoker.invokePreDestroy();
} catch (Exception e) {
_logger.log(Level.FINE, "Managed bean " + next.getBeanClassName() + " PreDestroy", e);
}
}
com.sun.enterprise.container.common.spi.util.ComponentEnvManager compEnvManager = habitat.getService(com.sun.enterprise.container.common.spi.util.ComponentEnvManager.class);
try {
compEnvManager.unbindFromComponentNamespace(next);
} catch (javax.naming.NamingException ne) {
_logger.log(Level.FINE, "Managed bean " + next.getBeanClassName() + " unbind", ne);
}
org.glassfish.api.naming.GlassfishNamingManager namingManager = habitat.getService(org.glassfish.api.naming.GlassfishNamingManager.class);
String jndiName = next.getGlobalJndiName();
if (processType.isServer()) {
try {
namingManager.unpublishObject(jndiName);
} catch (javax.naming.NamingException ne) {
_logger.log(Level.FINE, "Error unpubishing managed bean " + next.getBeanClassName() + " with jndi name " + jndiName, ne);
}
} else {
appClientManagedBeans.remove(jndiName);
}
next.clearAllBeanInstanceInfo();
}
}
}
use of com.sun.enterprise.deployment.ManagedBeanDescriptor in project Payara by payara.
the class ManagedBeanManagerImpl method loadManagedBeans.
public void loadManagedBeans(Application app) {
JCDIService jcdiService = habitat.getService(JCDIService.class);
for (BundleDescriptor bundle : app.getBundleDescriptors()) {
if (!bundleEligible(bundle)) {
continue;
}
boolean isCDIBundle = (jcdiService != null && jcdiService.isJCDIEnabled(bundle));
for (ManagedBeanDescriptor next : bundle.getManagedBeans()) {
try {
Set<String> interceptorClasses = next.getAllInterceptorClasses();
Class targetClass = bundle.getClassLoader().loadClass(next.getBeanClassName());
InterceptorInfo interceptorInfo = new InterceptorInfo();
interceptorInfo.setTargetClass(targetClass);
interceptorInfo.setInterceptorClassNames(interceptorClasses);
interceptorInfo.setAroundConstructInterceptors(next.getAroundConstructCallbackInterceptors(targetClass, getConstructor(targetClass, isCDIBundle)));
interceptorInfo.setPostConstructInterceptors(next.getCallbackInterceptors(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT));
interceptorInfo.setPreDestroyInterceptors(next.getCallbackInterceptors(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY));
if (next.hasAroundInvokeMethod()) {
interceptorInfo.setHasTargetClassAroundInvoke(true);
}
Map<Method, List> interceptorChains = new HashMap<Method, List>();
for (Method m : targetClass.getMethods()) {
interceptorChains.put(m, next.getAroundInvokeInterceptors(m));
}
interceptorInfo.setAroundInvokeInterceptorChains(interceptorChains);
// TODO can optimize this out for the non-JAXRS, non-application specified interceptor case
interceptorInfo.setSupportRuntimeDelegate(true);
JavaEEInterceptorBuilderFactory interceptorBuilderFactory = habitat.getService(JavaEEInterceptorBuilderFactory.class);
JavaEEInterceptorBuilder builder = interceptorBuilderFactory.createBuilder(interceptorInfo);
next.setInterceptorBuilder(builder);
compEnvManager.bindToComponentNamespace(next);
String jndiName = next.getGlobalJndiName();
ManagedBeanNamingProxy namingProxy = new ManagedBeanNamingProxy(next, habitat);
if (processType.isServer()) {
namingManager.publishObject(jndiName, namingProxy, true);
} else {
// Can't store them in server's global naming service so keep
// them in local map.
appClientManagedBeans.put(jndiName, namingProxy);
}
} catch (Exception e) {
throw new RuntimeException("Error binding ManagedBean " + next.getBeanClassName() + " with name = " + next.getName(), e);
}
}
jcdiManagedBeanInstanceMap.put(bundle, Collections.synchronizedMap(new HashMap<Object, JCDIService.JCDIInjectionContext>()));
}
}
Aggregations