Search in sources :

Example 1 with Container

use of com.sun.ejb.Container in project Payara by payara.

the class EjbContainerServicesImpl method isRemoved.

public boolean isRemoved(Object ejbRef) {
    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);
    if (localObjectImpl == null) {
        throw new UnsupportedOperationException("Invalid ejb ref");
    }
    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();
    boolean isStatefulBean = false;
    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        isStatefulBean = sessionDesc.isStateful();
    }
    if (!isStatefulBean) {
        // stateless/singleton references via 299 will fail until bug is fixed.
        return false;
    // TODO reenable this per SessionObjectReference.isRemoved SPI
    // throw new UnsupportedOperationException("ejbRef for ejb " +
    // ejbDesc.getName() + " is not a stateful bean ");
    }
    boolean removed = false;
    try {
        ((BaseContainer) container).checkExists(localObjectImpl);
    } catch (Exception e) {
        removed = true;
    }
    return removed;
}
Also used : Container(com.sun.ejb.Container) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException)

Example 2 with Container

use of com.sun.ejb.Container in project Payara by payara.

the class EjbContainerServicesImpl method remove.

public void remove(Object ejbRef) {
    EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);
    if (localObjectImpl == null) {
        throw new UnsupportedOperationException("Invalid ejb ref");
    }
    Container container = localObjectImpl.getContainer();
    EjbDescriptor ejbDesc = container.getEjbDescriptor();
    boolean isStatefulBean = false;
    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        isStatefulBean = sessionDesc.isStateful();
    }
    if (!isStatefulBean) {
        // stateless/singleton references via 299 could fail until bug is fixed.
        return;
    // TODO reenable this after bug is fixed
    // throw new UnsupportedOperationException("ejbRef for ejb " +
    // ejbDesc.getName() + " is not a stateful bean ");
    }
    try {
        localObjectImpl.remove();
    } catch (EJBException e) {
        LogFacade.getLogger().log(Level.FINE, "EJBException during remove. ", e);
    } catch (javax.ejb.RemoveException re) {
        throw new NoSuchEJBException(re.getMessage(), re);
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) Container(com.sun.ejb.Container) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 3 with Container

use of com.sun.ejb.Container in project Payara by payara.

the class EjbApplication method loadContainers.

/**
 * Initial phase of continer initialization.  This creates the concrete container
 * instance for each EJB component, registers JNDI entries, etc.  However, no
 * EJB bean instances or invocations occur during this phase.  Those must be
 * delayed until start() is called.
 * @param startupContext
 * @return
 */
boolean loadContainers(ApplicationContext startupContext) {
    DeploymentContext dc = (DeploymentContext) startupContext;
    String dcMapToken = "org.glassfish.ejb.startup.SingletonLCM";
    singletonLCM = dc.getTransientAppMetaData(dcMapToken, SingletonLifeCycleManager.class);
    if (singletonLCM == null) {
        singletonLCM = new SingletonLifeCycleManager(initializeInOrder);
        dc.addTransientAppMetaData(dcMapToken, singletonLCM);
    }
    if (!initializeInOrder) {
        dc.addTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.FALSE);
        List<EjbApplication> ejbAppList = dc.getTransientAppMetaData(CONTAINER_LIST_KEY, List.class);
        if (ejbAppList == null) {
            ejbAppList = new ArrayList<EjbApplication>();
            dc.addTransientAppMetaData(CONTAINER_LIST_KEY, ejbAppList);
        }
        ejbAppList.add(this);
    }
    try {
        policyLoader.loadPolicy();
        for (EjbDescriptor desc : ejbs) {
            // Initialize each ejb container (setup component environment, register JNDI objects, etc.)
            // Any instance instantiation , timer creation/restoration, message inflow is delayed until
            // start phase.
            ContainerFactory ejbContainerFactory = services.getService(ContainerFactory.class, desc.getContainerFactoryQualifier());
            if (ejbContainerFactory == null) {
                String errMsg = localStrings.getLocalString("invalid.container.module", "Container module is not available", desc.getEjbTypeForDisplay());
                throw new RuntimeException(errMsg);
            }
            Container container = ejbContainerFactory.createContainer(desc, ejbAppClassLoader, dc);
            containers.add(container);
            if (desc instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) desc).isSingleton()) {
                singletonLCM.addSingletonContainer(this, (AbstractSingletonContainer) container);
            }
        }
    } catch (Throwable t) {
        abortInitializationAfterException();
        throw new RuntimeException("EJB Container initialization error", t);
    } finally {
        // clean up the thread local current classloader after codegen to ensure it isn't
        // referencing the deployed application
        CurrentClassLoader.set(this.getClass().getClassLoader());
        Wrapper._clear();
    }
    return true;
}
Also used : DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Container(com.sun.ejb.Container) AbstractSingletonContainer(com.sun.ejb.containers.AbstractSingletonContainer) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer) ContainerFactory(com.sun.ejb.ContainerFactory) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 4 with Container

use of com.sun.ejb.Container in project Payara by payara.

the class EjbApplication method start.

public boolean start(ApplicationContext startupContext) throws Exception {
    started = true;
    if (!initializeInOrder) {
        Boolean alreadyMarked = dc.getTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.class);
        if (!alreadyMarked.booleanValue()) {
            List<EjbApplication> ejbAppList = dc.getTransientAppMetaData(CONTAINER_LIST_KEY, List.class);
            for (EjbApplication app : ejbAppList) {
                app.markAllContainersAsStarted();
            }
            dc.addTransientAppMetaData(EJB_APP_MARKED_AS_STARTED_STATUS, Boolean.TRUE);
        }
    }
    try {
        DeployCommandParameters params = ((DeploymentContext) startupContext).getCommandParameters(DeployCommandParameters.class);
        for (Container container : containers) {
            container.startApplication(params.origin.isDeploy());
        }
        singletonLCM.doStartup(this);
    } catch (Exception e) {
        abortInitializationAfterException();
        throw e;
    }
    return true;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Container(com.sun.ejb.Container) AbstractSingletonContainer(com.sun.ejb.containers.AbstractSingletonContainer) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer)

Example 5 with Container

use of com.sun.ejb.Container in project Payara by payara.

the class SunContainerHelper method getPersistenceManagerFactory.

/**
 * Called in a CMP environment to lookup PersistenceManagerFactory
 * referenced by this Container instance as the CMP resource.
 *
 * This is SunContainerHelper specific code.
 *
 * @see getContainer(Object)
 * @param container a Container instance for the request.
 */
public PersistenceManagerFactory getPersistenceManagerFactory(Object container) {
    Object rc = null;
    PersistenceManagerFactoryImpl pmf = null;
    ResourceReferenceDescriptor cmpResource = ((Container) container).getEjbDescriptor().getEjbBundleDescriptor().getCMPResourceReference();
    String name = cmpResource.getJndiName();
    try {
        InitialContext ic = new InitialContext();
        rc = ic.lookup(name);
        if (rc instanceof PersistenceManagerFactoryImpl) {
            pmf = (PersistenceManagerFactoryImpl) rc;
        } else if (rc instanceof javax.sql.DataSource) {
            pmf = new PersistenceManagerFactoryImpl();
            pmf.setConnectionFactoryName(ConnectorsUtil.getPMJndiName(name));
            Iterator it = cmpResource.getProperties();
            if (it != null) {
                while (it.hasNext()) {
                    NameValuePairDescriptor prop = (NameValuePairDescriptor) it.next();
                    String n = prop.getName();
                    // Any value that is not "true" is treated as "false":
                    boolean value = Boolean.valueOf(prop.getValue()).booleanValue();
                    pmf.setBooleanProperty(n, value);
                }
            }
        } else {
            RuntimeException e = new JDOFatalUserException(I18NHelper.getMessage(// NOI18N
            messages, // NOI18N
            "ejb.jndi.unexpectedinstance", name, rc.getClass().getName()));
            logger.severe(e.toString());
            throw e;
        }
    } catch (javax.naming.NamingException ex) {
        RuntimeException e = new JDOFatalUserException(I18NHelper.getMessage(messages, "ejb.jndi.lookupfailed", name), // NOI18N
        ex);
        logger.severe(e.toString());
        throw e;
    }
    return pmf;
}
Also used : JDOFatalUserException(com.sun.jdo.api.persistence.support.JDOFatalUserException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) PersistenceManagerFactoryImpl(com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl) Container(com.sun.ejb.Container) DataSource(javax.sql.DataSource) Iterator(java.util.Iterator) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Aggregations

Container (com.sun.ejb.Container)7 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)4 AbstractSingletonContainer (com.sun.ejb.containers.AbstractSingletonContainer)3 ApplicationContainer (org.glassfish.api.deployment.ApplicationContainer)3 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)3 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)3 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)3 EJBException (javax.ejb.EJBException)2 NoSuchEJBException (javax.ejb.NoSuchEJBException)2 ContainerFactory (com.sun.ejb.ContainerFactory)1 JDOFatalUserException (com.sun.jdo.api.persistence.support.JDOFatalUserException)1 PersistenceManagerFactoryImpl (com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 EJBLocalObject (javax.ejb.EJBLocalObject)1 EJBObject (javax.ejb.EJBObject)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 DataSource (javax.sql.DataSource)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1