Search in sources :

Example 1 with EJBContextImpl

use of com.sun.ejb.containers.EJBContextImpl in project Payara by payara.

the class ActiveTxCache method destroyReadyStoreOnUndeploy.

protected void destroyReadyStoreOnUndeploy() {
    if (readyStore == null) {
        return;
    }
    // destroy all EJB instances in readyStore
    synchronized (readyStore) {
        Iterator beans = readyStore.values();
        while (beans.hasNext()) {
            EJBContextImpl ctx = (EJBContextImpl) beans.next();
            transactionManager.componentDestroyed(ctx);
        }
    }
    readyStore.destroy();
    readyStore = null;
}
Also used : EJBContextImpl(com.sun.ejb.containers.EJBContextImpl) Iterator(java.util.Iterator)

Example 2 with EJBContextImpl

use of com.sun.ejb.containers.EJBContextImpl in project Payara by payara.

the class EjbNamingReferenceManagerImpl method getEJBContextObject.

public Object getEJBContextObject(String contextType) {
    ComponentInvocation currentInv = invMgr.getCurrentInvocation();
    if (currentInv == null) {
        throw new IllegalStateException("no current invocation");
    } else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
        throw new IllegalStateException("Illegal invocation type for EJB Context : " + currentInv.getInvocationType());
    }
    EjbInvocation ejbInv = (EjbInvocation) currentInv;
    Object returnObject = ejbInv.context;
    if (contextType.equals("javax.ejb.TimerService")) {
        if (EJBTimerService.getEJBTimerService() == null) {
            throw new IllegalStateException("EJB Timer Service not " + "available");
        }
        returnObject = new EJBTimerServiceWrapper(EJBTimerService.getEJBTimerService(), (EJBContextImpl) ejbInv.context);
    }
    return returnObject;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) EJBContextImpl(com.sun.ejb.containers.EJBContextImpl) EJBTimerServiceWrapper(com.sun.ejb.containers.EJBTimerServiceWrapper)

Example 3 with EJBContextImpl

use of com.sun.ejb.containers.EJBContextImpl in project Payara by payara.

the class JCDIServiceImpl method _createJCDIInjectionContext.

// instance could be null. If null, create a new one
@SuppressWarnings("unchecked")
private <T> JCDIInjectionContext<T> _createJCDIInjectionContext(EjbDescriptor ejb, T instance, Map<Class<?>, Object> ejbInfo) {
    BaseContainer baseContainer = null;
    EJBContextImpl ejbContext = null;
    JCDIInjectionContextImpl<T> jcdiCtx = null;
    CreationalContext<T> creationalContext = null;
    if (ejbInfo != null) {
        baseContainer = (BaseContainer) ejbInfo.get(BaseContainer.class);
        ejbContext = (EJBContextImpl) ejbInfo.get(EJBContextImpl.class);
    }
    BundleDescriptor topLevelBundleDesc = (BundleDescriptor) ejb.getEjbBundleDescriptor().getModuleDescriptor().getDescriptor();
    // First get BeanDeploymentArchive for this ejb
    BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName());
    WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication());
    WeldManager weldManager = bootstrap.getManager(bda);
    org.jboss.weld.ejb.spi.EjbDescriptor<T> ejbDesc = weldManager.getEjbDescriptor(ejb.getName());
    // get or create the ejb's creational context
    if (null != ejbInfo) {
        jcdiCtx = (JCDIInjectionContextImpl<T>) ejbInfo.get(JCDIService.JCDIInjectionContext.class);
    }
    if (null != jcdiCtx) {
        creationalContext = jcdiCtx.getCreationalContext();
    }
    if (null != jcdiCtx && creationalContext == null) {
        // The creational context may have been created by interceptors because they are created first
        // (see createInterceptorInstance below.)
        // And we only want to create the ejb's creational context once or we will have a memory
        // leak there too.
        Bean<T> bean = weldManager.getBean(ejbDesc);
        creationalContext = weldManager.createCreationalContext(bean);
        jcdiCtx.setCreationalContext(creationalContext);
    }
    // Create the injection target
    InjectionTarget<T> it = weldManager.createInjectionTarget(ejbDesc);
    if (null != jcdiCtx) {
        jcdiCtx.setInjectionTarget(it);
    }
    // JJS: 7/20/17 We must perform the around_construct interception because Weld does not know about
    // interceptors defined by descriptors.
    WeldCreationalContext<T> weldCreationalContext = (WeldCreationalContext) creationalContext;
    weldCreationalContext.setConstructorInterceptionSuppressed(true);
    JCDIAroundConstructCallback<T> aroundConstructCallback = new JCDIAroundConstructCallback<>(baseContainer, ejbContext);
    weldCreationalContext.registerAroundConstructCallback(aroundConstructCallback);
    if (null != jcdiCtx) {
        jcdiCtx.setJCDIAroundConstructCallback(aroundConstructCallback);
    }
    T beanInstance = instance;
    if (beanInstance == null) {
        // Create instance , perform constructor injection.
        beanInstance = it.produce(creationalContext);
    }
    if (null != jcdiCtx) {
        jcdiCtx.setInstance(beanInstance);
    }
    return jcdiCtx;
// Injection is not performed yet. Separate injectEJBInstance() call is required.
}
Also used : JCDIService(com.sun.enterprise.container.common.spi.JCDIService) EJBContextImpl(com.sun.ejb.containers.EJBContextImpl) WeldBootstrap(org.jboss.weld.bootstrap.WeldBootstrap) javax.enterprise.inject.spi(javax.enterprise.inject.spi) WeldManager(org.jboss.weld.manager.api.WeldManager) BaseContainer(com.sun.ejb.containers.BaseContainer) BundleDescriptor(com.sun.enterprise.deployment.BundleDescriptor) WeldCreationalContext(org.jboss.weld.contexts.WeldCreationalContext) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Example 4 with EJBContextImpl

use of com.sun.ejb.containers.EJBContextImpl in project Payara by payara.

the class NonBlockingPool method doResize.

protected void doResize() {
    if (poolClosed) {
        return;
    }
    // We need to set the context class loader for this (deamon) thread!!
    final Thread currentThread = Thread.currentThread();
    final ClassLoader previousClassLoader = currentThread.getContextClassLoader();
    final ClassLoader ctxClassLoader = containerClassLoader;
    long startTime = 0;
    boolean enteredResizeBlock = false;
    try {
        if (System.getSecurityManager() == null) {
            currentThread.setContextClassLoader(ctxClassLoader);
        } else {
            java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() {

                @Override
                public java.lang.Object run() {
                    currentThread.setContextClassLoader(ctxClassLoader);
                    return null;
                }
            });
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "[Pool-{0}]: Resize started at: {1} steadyPoolSize ::{2} resizeQuantity ::{3} maxPoolSize ::{4}", new Object[] { poolName, new java.util.Date(), steadyPoolSize, resizeQuantity, maxPoolSize });
        }
        startTime = System.currentTimeMillis();
        ArrayList<Object> removeList = new ArrayList<>();
        long populateCount = 0;
        synchronized (list) {
            if ((inResizing == true) || poolClosed) {
                return;
            }
            enteredResizeBlock = true;
            inResizing = true;
            int curSize = list.size();
            if (curSize > steadyPoolSize) {
                // possible to reduce pool size....
                if ((idleTimeoutInSeconds <= 0) || (resizeQuantity <= 0)) {
                    return;
                }
                int victimCount = (curSize > (steadyPoolSize + resizeQuantity)) ? resizeQuantity : (curSize - steadyPoolSize);
                long allowedIdleTime = System.currentTimeMillis() - idleTimeoutInSeconds * 1000L;
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "[Pool-{0}]: Resize:: reducing " + " pool size by: {1}", new Object[] { poolName, victimCount });
                }
                for (int i = 0; i < victimCount; i++) {
                    // removeList.add(list.remove(--curSize));
                    // destroyedCount++;
                    EJBContextImpl ctx = (EJBContextImpl) list.get(0);
                    if (ctx.getLastTimeUsed() <= allowedIdleTime) {
                        removeList.add(list.remove(0));
                        poolProbeNotifier.ejbObjectDestroyedEvent(beanId, appName, modName, ejbName);
                        destroyedCount++;
                    } else {
                        break;
                    }
                }
            } else if (curSize < steadyPoolSize) {
                // Need to populate....
                if (maintainSteadySize == false) {
                    return;
                }
                if (resizeQuantity <= 0) {
                    populateCount = steadyPoolSize - curSize;
                } else {
                    while ((curSize + populateCount) < steadyPoolSize) {
                        populateCount += resizeQuantity;
                    }
                    if ((curSize + populateCount) > maxPoolSize) {
                        populateCount -= (curSize + populateCount) - maxPoolSize;
                    }
                }
            }
        }
        if (removeList.size() > 0) {
            int sz = removeList.size();
            for (int i = 0; i < sz; i++) {
                try {
                    factory.destroy(removeList.get(i));
                } catch (Throwable th) {
                    _logger.log(Level.FINE, "exception in doResize", th);
                }
            }
        }
        if (populateCount > 0) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "[Pool-{0}]: Attempting to preload {1} beans. CurSize/MaxPoolSize: {2}/{3}", new Object[] { poolName, populateCount, list.size(), maxPoolSize });
            }
            preload((int) populateCount);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "[Pool-{0}" + "]: After preload " + "CurSize/MaxPoolSize: {1}/{2}", new Object[] { poolName, list.size(), maxPoolSize });
            }
        }
    } catch (Throwable th) {
        _logger.log(Level.WARNING, "[Pool-" + poolName + "]: Exception during reSize", th);
    } finally {
        if (enteredResizeBlock) {
            synchronized (list) {
                inResizing = false;
            }
        }
        if (System.getSecurityManager() == null) {
            currentThread.setContextClassLoader(previousClassLoader);
        } else {
            java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() {

                @Override
                public java.lang.Object run() {
                    currentThread.setContextClassLoader(previousClassLoader);
                    return null;
                }
            });
        }
    }
    long endTime = System.currentTimeMillis();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "[Pool-{0}]: Resize completed at: {1}; after reSize: {2}", new Object[] { poolName, new java.util.Date(), getAllAttrValues() });
        _logger.log(Level.FINE, "[Pool-{0}]: Resize took: {1} seconds.", new Object[] { poolName, (endTime - startTime) / 1000.0 });
    }
}
Also used : EJBContextImpl(com.sun.ejb.containers.EJBContextImpl) ArrayList(java.util.ArrayList)

Aggregations

EJBContextImpl (com.sun.ejb.containers.EJBContextImpl)4 BaseContainer (com.sun.ejb.containers.BaseContainer)1 EJBTimerServiceWrapper (com.sun.ejb.containers.EJBTimerServiceWrapper)1 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 javax.enterprise.inject.spi (javax.enterprise.inject.spi)1 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)1 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 WeldCreationalContext (org.jboss.weld.contexts.WeldCreationalContext)1 WeldManager (org.jboss.weld.manager.api.WeldManager)1