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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations