public String getModuleID() { return getModuleContext().getModuleURI().toString(); }
public String getModuleID() { return getModuleContext().getModuleURI().toString(); }
public String getModuleName() { return getModuleContext().getId(); }
public String getModuleName() { return getModuleContext().getId(); }
private TimerStore newTimerStore(final BeanContext beanContext) { for (final DeploymentContext context : Arrays.asList(beanContext, beanContext.getModuleContext(), beanContext.getModuleContext().getAppContext())) { final String timerStoreClass = context.getProperties().getProperty(TIMER_STORE_CLASS); if (timerStoreClass != null) { logger.info("Found timer class: " + timerStoreClass); try { final Class<?> clazz = beanContext.getClassLoader().loadClass(timerStoreClass); try { final Constructor<?> constructor = clazz.getConstructor(TransactionManager.class); return TimerStore.class.cast(constructor.newInstance(EjbTimerServiceImpl.getDefaultTransactionManager())); } catch (final Exception ignored) { return TimerStore.class.cast(clazz.newInstance()); } } catch (final Exception e) { logger.error("Failed to instantiate " + timerStoreClass + ", using default memory timer store"); } } } return new MemoryTimerStore(EjbTimerServiceImpl.getDefaultTransactionManager()); }
private TimerStore newTimerStore(final BeanContext beanContext) { for (final DeploymentContext context : Arrays.asList(beanContext, beanContext.getModuleContext(), beanContext.getModuleContext().getAppContext())) { final String timerStoreClass = context.getProperties().getProperty(TIMER_STORE_CLASS); if (timerStoreClass != null) { logger.info("Found timer class: " + timerStoreClass); try { final Class<?> clazz = beanContext.getClassLoader().loadClass(timerStoreClass); try { final Constructor<?> constructor = clazz.getConstructor(TransactionManager.class); return TimerStore.class.cast(constructor.newInstance(EjbTimerServiceImpl.getDefaultTransactionManager())); } catch (final Exception ignored) { return TimerStore.class.cast(clazz.newInstance()); } } catch (final Exception e) { logger.error("Can't instantiate " + timerStoreClass + ", using default memory timer store"); } } } return new MemoryTimerStore(EjbTimerServiceImpl.getDefaultTransactionManager()); }
private String computeGlobalName(final BeanContext cdi, final Class<?> intrface) { final ModuleContext module = cdi.getModuleContext(); final AppContext application = module.getAppContext(); final String appName = application.isStandaloneModule() ? "" : application.getId() + "/"; final String moduleName = moduleName(cdi); String beanName = cdi.getEjbName(); if (intrface != null) { beanName = beanName + "!" + intrface.getName(); } return "global/" + appName + moduleName + beanName; }
private String computeGlobalName(final BeanContext cdi, final Class<?> intrface) { final ModuleContext module = cdi.getModuleContext(); final AppContext application = module.getAppContext(); final String appName = application.isStandaloneModule() ? "" : application.getId() + "/"; final String moduleName = cdi.getModuleName() + "/"; String beanName = cdi.getEjbName(); if (intrface != null) { beanName = beanName + "!" + intrface.getName(); } return "global/" + appName + moduleName + beanName; }
private AppContext findAppContext(final InvocationContext ic) { AppContext appContext = null; final ThreadContext tc = ThreadContext.getThreadContext(); if (tc != null && tc.getBeanContext() != null) { appContext = tc.getBeanContext().getModuleContext().getAppContext(); } if (appContext == null) { // we should never enter here for an EJB final ClassLoader loader = Thread.currentThread().getContextClassLoader(); appContext = AppFinder.findAppContextOrWeb(loader, AppFinder.AppContextTransformer.INSTANCE); } if (appContext == null) { LOGGER.warning(GovernanceCodes.TGI_CANT_FIND_APPCONTEXT, "Can't find AppContext for " + Thread.currentThread().getContextClassLoader() + " so method " + ic.getMethod() + " will not get governance activated"); return null; } return appContext; }
public static Object subclassProxy(final BeanContext beanContext) { try { return LocalBeanProxyFactory.newProxyInstance(beanContext.getModuleContext().getClassLoader(), new Handler(beanContext), beanContext.getBeanClass(), IntraVmProxy.class, Serializable.class); } catch (final InternalError ie) { // try without intravmproxy which is maybe not loadable (in OSGi it can happen) return LocalBeanProxyFactory.newProxyInstance(beanContext.getModuleContext().getClassLoader(), new Handler(beanContext), beanContext.getBeanClass(), Serializable.class); } }
public static Object subclassProxy(final BeanContext beanContext) { try { return LocalBeanProxyFactory.newProxyInstance(beanContext.getModuleContext().getClassLoader(), new Handler(beanContext), beanContext.getBeanClass(), IntraVmProxy.class, Serializable.class); } catch (final InternalError ie) { // try without intravmproxy which is maybe not loadable (in OSGi it can happen) return LocalBeanProxyFactory.newProxyInstance(beanContext.getModuleContext().getClassLoader(), new Handler(beanContext), beanContext.getBeanClass(), Serializable.class); } }
public static Collection<Timer> all() { final ThreadContext threadContext = ThreadContext.getThreadContext(); final BeanContext beanContext = threadContext.getBeanContext(); final ModuleContext module = beanContext.getModuleContext(); final Collection<Timer> timers = new HashSet<>(); for (final BeanContext c : module.getAppContext().getBeanContexts()) { if (c.getModuleContext() == module) { // filter by module if (c.getComponentType() != BeanType.STATEFUL) { final TimerService timerService = getTimerService(null, c, true); if (timerService == null) { continue; } final Collection<Timer> beanTimers = timerService.getTimers(); timers.addAll(beanTimers); } else { // for all instances final TimerService timerService = getTimerService(null, c, true); if (timerService == null) { continue; } final Collection<Timer> beanTimers = timerService.getTimers(); timers.addAll(beanTimers); } } } return timers; }
protected HttpListener createEjbWsContainer(URL moduleBaseUrl, PortData port, BeanContext beanContext, ServiceConfiguration config) { final Bus bus = CxfUtil.getBus(); final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader()); try { CxfCatalogUtils.loadOASISCatalog(bus, moduleBaseUrl, "META-INF/jax-ws-catalog.xml"); final EjbWsContainer container = new EjbWsContainer(bus, newTransportFactory(), port, beanContext, config); container.start(); wsContainers.put(beanContext.getDeploymentID().toString(), container); SystemInstance.get().fireEvent(new ServerCreated( container.getEndpoint().getServer(), beanContext.getModuleContext().getAppContext())); return container; } finally { if (oldLoader != null) { CxfUtil.clearBusLoader(oldLoader); } } }
protected HttpListener createEjbWsContainer(final URL moduleBaseUrl, final PortData port, final BeanContext beanContext, final ServiceConfiguration config) { final Bus bus = CxfUtil.getBus(); final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader()); try { CxfCatalogUtils.loadOASISCatalog(bus, moduleBaseUrl, "META-INF/jax-ws-catalog.xml"); final EjbWsContainer container = new EjbWsContainer(bus, httpTransportFactory, port, beanContext, config); container.start(); wsContainers.put(beanContext.getDeploymentID().toString(), container); SystemInstance.get().fireEvent(new ServerCreated( container.getEndpoint().getServer(), beanContext.getModuleContext().getAppContext())); return container; } finally { if (oldLoader != null) { CxfUtil.clearBusLoader(oldLoader); } } }
@Override public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) { final BeanContext beanContext = newContext.getBeanContext(); final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext(); if (webBeansContext == null) { return; } final ContextsService contextsService = webBeansContext.getContextsService(); final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false); if (requestContext == null) { contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT); newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext)); } }
protected Object businessMethod(final Class<?> interfce, final Method method, final Object[] args, final Object proxy) throws Throwable { final BeanContext beanContext = getBeanContext(); if (beanContext.isAsynchronous(method)) { return beanContext.getModuleContext() .getAppContext() .getAsynchronousPool() .invoke(new CUCallable<Object>(new Callable<Object>() { @Override public Object call() throws Exception { try { return synchronizedBusinessMethod(interfce, method, args); } catch (final ApplicationException ae) { logger.error("EjbObjectProxyHandler: Asynchronous call to '" + interfce.getSimpleName() + "' on '" + method.getName() + "' failed", ae); throw ae; } } }), method.getReturnType() == Void.TYPE); } else { return synchronizedBusinessMethod(interfce, method, args); } }
@Override public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) { final BeanContext beanContext = newContext.getBeanContext(); if (beanContext == null) { // OWBContextHolder will be null so calling contextExited will throw a NPE return; } final ModuleContext moduleContext = beanContext.getModuleContext(); //TODO its not clear what the scope for one of these context should be: ejb, module, or app //For now, go with the attachment of the BeanManager to AppContext final AppContext appContext = moduleContext.getAppContext(); final WebBeansContext owbContext = appContext.getWebBeansContext(); final Object oldOWBContext; if (owbContext != null) { oldOWBContext = singletonService.contextEntered(owbContext); } else { oldOWBContext = null; } final OWBContextHolder holder = new OWBContextHolder(oldOWBContext); newContext.set(OWBContextHolder.class, holder); }
protected Object homeMethod(final Class interfce, final Method method, final Object[] args, final Object proxy) throws Throwable { checkAuthorization(method); final BeanContext beanContext = getBeanContext(); if (beanContext.isAsynchronous(method)) { return beanContext.getModuleContext() .getAppContext() .getAsynchronousPool() .invoke(new CUCallable<Object>(new Callable<Object>() { @Override public Object call() throws Exception { try { return homeMethodInvoke(interfce, method, args); } catch (final ApplicationException ae) { logger.error("EjbHomeProxyHandler: Asynchronous call to '" + interfce.getSimpleName() + "' on '" + method.getName() + "' failed", ae); throw ae; } } }), method.getReturnType() == Void.TYPE); } else { return homeMethodInvoke(interfce, method, args); } }
@Override public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) { final BeanContext beanContext = newContext.getBeanContext(); if (beanContext == null) { // OWBContextHolder will be null so calling contextExited will throw a NPE return; } final ModuleContext moduleContext = beanContext.getModuleContext(); //TODO its not clear what the scope for one of these context should be: ejb, module, or app //For now, go with the attachment of the BeanManager to AppContext final AppContext appContext = moduleContext.getAppContext(); final WebBeansContext owbContext = appContext.getWebBeansContext(); final Object oldOWBContext; if (owbContext != null) { oldOWBContext = singletonService.contextEntered(owbContext); } else { oldOWBContext = null; } final OWBContextHolder holder = new OWBContextHolder(oldOWBContext); newContext.set(OWBContextHolder.class, holder); }
@Override public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) { final BeanContext beanContext = newContext.getBeanContext(); final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext(); if (webBeansContext == null) { return; } final ContextsService contextsService = webBeansContext.getContextsService(); final Context requestContext = contextsService.getCurrentContext(RequestScoped.class); if (requestContext == null) { contextsService.startContext(RequestScoped.class, null); newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext)); } }