Package org.glassfish.ejb.mdb
Class MessageBeanContainer
- java.lang.Object
-
- com.sun.ejb.containers.BaseContainer
-
- org.glassfish.ejb.mdb.MessageBeanContainer
-
- All Implemented Interfaces:
Container
,JavaEEContainer
,MessageBeanProtocolManager
,EjbContainerFacade
public final class MessageBeanContainer extends BaseContainer implements MessageBeanProtocolManager
This class provides container functionality specific to message-driven EJBs. At deployment time, one instance of the MessageDrivenBeanContainer is created for each message-driven bean in an application.The 3 states of a Message-driven EJB (an EJB can be in only 1 state at a time): 1. POOLED : ready for invocations, no transaction in progress 2. INVOKING : processing an invocation 3. DESTROYED : does not exist A Message-driven Bean can hold open DB connections across invocations. It's assumed that the Resource Manager can handle multiple incomplete transactions on the same connection.
- Author:
- Kenneth Saks
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MessageBeanContainer.MessageDeliveryType
-
Nested classes/interfaces inherited from class com.sun.ejb.containers.BaseContainer
BaseContainer.ContainerInfo, BaseContainer.ContainerType, BaseContainer.PreInvokeException
-
-
Field Summary
-
Fields inherited from class com.sun.ejb.containers.BaseContainer
cacheProbeListener, cacheProbeNotifier, callFlowInfo, componentId, CONTAINER_INITIALIZING, CONTAINER_ON_HOLD, CONTAINER_STARTED, CONTAINER_STOPPED, CONTAINER_UNDEPLOYED, containerInfo, containerState, containerStateManager, containerTransactionManager, containerType, debugMonitorFlag, ejbActivateMethod, ejbClass, ejbContainerUtilImpl, ejbDescriptor, ejbGeneratedOptionalLocalBusinessIntfClass, ejbHome, ejbHomeImpl, ejbHomeStub, ejbIntfMethodInfo, ejbIntfMethods, ejbLocalBusinessHome, ejbLocalBusinessHomeImpl, ejbLocalHome, ejbLocalHomeImpl, EJBLocalObject_getPrimaryKey, EJBObject_getPrimaryKey, ejbOptionalLocalBusinessHome, ejbOptionalLocalBusinessHomeImpl, ejbOptionalLocalBusinessHomeIntf, ejbPassivateMethod, ejbProbeListener, ejbProbeNotifier, ejbRemoteBusinessHome, ejbRemoteBusinessHomeImpl, ejbRemoteBusinessHomeStub, ejbRemoveMethod, envProps, executorProbeListener, hasLocalBusinessView, hasLocalHomeView, hasOptionalLocalBusinessView, hasRemoteBusinessView, hasRemoteHomeView, homeIntf, injectionManager, interceptorManager, invocationInfoMap, invocationManager, isBeanManagedTran, isLocal, isMessageDriven, isRemote, isSession, isSingleton, isStatefulSession, isStatelessSession, isWebServiceEndpoint, jcdiService, loader, localBusinessHomeIntf, localBusinessIntfs, localHomeIntf, logParams, metadata, namingManager, NO_PARAMS, optIntfClassLoader, poolProbeListener, remoteBusinessHomeIntf, remoteBusinessIntfInfo, remoteHomeRefFactory, remoteIntf, scheduleIds, securityManager, sfsbSerializedClass, SINGLETON_BEAN_POOL_PROP, timerProbeListener, timerProbeNotifier, transactionManager, webServiceEndpointIntf, webServiceInvocationInfoMap
-
Fields inherited from interface com.sun.ejb.Container
SEC_CHECKED, SEC_EXCLUDED, SEC_NOT_INITIALIZED, SEC_UNCHECKED, secAttrStrings, TX_BEAN_MANAGED, TX_MANDATORY, TX_NEVER, TX_NOT_INITIALIZED, TX_NOT_SUPPORTED, TX_REQUIRED, TX_REQUIRES_NEW, TX_SUPPORTS, txAttrStrings
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected MessageBeanContextImpl
_constructEJBContextImpl(Object instance)
Must be overridden for any container that supports injectionprotected ComponentContext
_getContext(EjbInvocation inv)
void
activateEJB(Object ctx, Object instanceKey)
Deprecated.not called and not used in Payara 5protected void
addLocalRemoteInvocationInfo()
protected void
afterBegin(EJBContextImpl context)
protected void
afterCompletion(EJBContextImpl ctx, int status)
void
afterMessageDelivery(ResourceHandle resourceHandle)
protected void
beforeCompletion(EJBContextImpl context)
void
beforeMessageDelivery(Method method, MessageBeanContainer.MessageDeliveryType deliveryType, boolean txImported, ResourceHandle resourceHandle)
Actual message delivery happens in three steps : 1) beforeMessageDelivery(Message, MessageListener) This is our chance to make the message delivery itself part of the instance's global transaction.protected boolean
callEJBTimeout(RuntimeTimerState timerState, EJBTimerService timerService)
Override callEJBTimeout from BaseContainer since delivery to message driven beans is a bit different from session/entity.EJBObjectImpl
createEJBObjectImpl()
MessageBeanListener
createMessageBeanListener(ResourceHandle resource)
Create a MessageBeanListener.Object
createMessageBeanProxy(InvocationHandler handler)
Generates the appropriate Proxy based on the message listener type.Object
deliverMessage(Object[] params)
void
destroyMessageBeanListener(MessageBeanListener listener)
Return the MessageBeanListener to the container.protected void
doConcreteContainerShutdown(boolean appBeingUndeployed)
Called by BaseContainer during container shutdown sequenceprotected void
forceDestroyBean(EJBContextImpl sc)
Force destroy the EJB.EJBObjectImpl
getEJBObjectImpl(byte[] instanceKey)
Called when a remote invocation arrives for an EJB.long
getMessageCount()
String
getMonitorAttributeValues()
protected EjbMonitoringStatsProvider
getMonitoringStatsProvider(String appName, String modName, String ejbName)
BeanPoolDescriptor
getPoolDescriptor()
Returns the message-bean container's pool properties.protected void
initializeHome()
Called from the ContainerFactory during initialization.protected boolean
isCreateHomeFinder(Method method)
boolean
isDeliveryTransacted(Method method)
This is used by the message provider to find out whether message deliveries will be transacted or not.boolean
passivateEJB(ComponentContext context)
void
postInvoke(EjbInvocation inv)
TODO public void appendStats(StringBuilder sbuf) { sbuf.append("\nMessageBeanContainer: ").append("CreateCount=").append( statCreateCount).append("; ").append("RemoveCount=").append( statRemoveCount).append("; ").append("MsgCount=").append( statMessageCount).append("; "); sbuf.append("]"); }void
preInvoke(EjbInvocation inv)
Called from EJBObject/EJBHome before invoking on EJB.protected void
registerMonitorableComponents(Method[] msgListenerMethods)
void
releaseContext(EjbInvocation inv)
Return instance to a pooled state.protected void
removeBean(EJBLocalRemoteObject ejbo, Method removeMethod, boolean local)
boolean
scanForEjbCreateMethod()
void
setEJBHome(jakarta.ejb.EJBHome ejbHome)
void
startApplication(boolean deploy)
Called when the application containing this message-bean has successfully gotten through the initial load phase of each module.protected static int
stringToInt(String val, String appName, Logger logger)
boolean
userTransactionMethodsAllowed(ComponentInvocation inv)
EJB spec makes a distinction between access to the UserTransaction object itself and access to its methods.protected int
validateValue(int value, int lowLimit, int highLimit, int deft, String emsg, String appName, Logger logger)
-
Methods inherited from class com.sun.ejb.containers.BaseContainer
_constructEJBInstance, _createJCDIInjectionContext, _createJCDIInjectionContext, addInvocationInfo, addProxyInterfacesSetClass, adjustHomeTargetMethodInfo, adjustInvocationInfo, assertValidLocalObject, assertValidRemoteObject, authorize, authorizeLocalGetPrimaryKey, authorizeLocalMethod, authorizeRemoteGetPrimaryKey, authorizeRemoteMethod, cancelTimers, checkExceptionClientTx, checkExists, checkUnfinishedTx, checkUserTransactionLookup, cleanupInstance, containerStateToString, createCallFlowAgent, createEjbInstanceAndContext, createEjbInstanceForInterceptors, createEjbInvocation, createEjbInvocation, createEJBLocalObjectImpl, createEmptyContextAndInterceptors, createMonitoringRegistry, createRemoteReferenceWithId, delistExtendedEntityManagers, doAfterBegin, doEJBHomeRemove, doFlush, doTimerInvocationInit, enlistExtendedEntityManagers, externalPostInvoke, externalPreInvoke, findFlushEnabledAttr, getApplicationId, getClassLoader, getComponentId, getContainerClassLoader, getContainerId, getContainerType, getContext, getDebugMonitorFlag, getDescriptor, getEJBClass, getEjbDescriptor, getEJBHome, getEJBHomeInvocationHandler, getEJBHomeStub, getEJBLocalBusinessHome, getEJBLocalHome, getEJBLocalHomeInvocationHandler, getEJBLocalObjectForPrimaryKey, getEJBLocalObjectForPrimaryKey, getEJBLocalObjectImpl, getEJBMetaData, getEJBObjectForPrimaryKey, getInvocationKey, getJaccEjb, getJavaGlobalJndiNamePrefix, getMonitoringMethodsArray, getMonitoringMethodsArray, getPassByReference, getPre30LifecycleMethodNames, getProtocolManager, getSecurityManager, getTargetObject, getTimeoutMethod, getTxAttr, getTxAttr, getTxAttrForLifecycleCallback, getUserTransaction, getUseThreadPoolId, incrementCreatedTimedObject, incrementDeliveredTimedObject, incrementRemovedTimedObject, initialize, initializeProtocolManager, injectEjbInstance, instantiateEJBLocalBusinessObjectImpl, instantiateEJBLocalObjectImpl, instantiateEJBLocalObjectImpl, instantiateEJBObjectImpl, instantiateEJBObjectImpl, instantiateOptionalEJBLocalBusinessObjectImpl, instantiateRemoteBusinessObjectImpl, intercept, intercept, invokeBeanMethod, invokeFindByPrimaryKey, invokeTargetBeanMethod, isApplicationException, isEjbTimeoutMethod, isHAEnabled, isIdentical, isJCDIEnabled, isLocalInterfaceSupported, isLocalObject, isRemoteInterfaceSupported, isRemoteObject, isStopped, isSystemUncheckedException, isTimedObject, isUndeployed, lookupExtendedEntityManager, onEnteringContainer, onLeavingContainer, onReady, onShutdown, onTermination, postCreate, postEjbTimeout, postFind, postInvoke, postInvokeNoTx, postInvokeTx, postProcessInvocationInfo, preInitialize, preInvokeNoTx, preInvokeTx, prepareEjbTimeoutParams, preSelect, registerMonitorableComponents, registerTimerMonitorableComponent, releaseTargetObject, removeBeanUnchecked, removeBeanUnchecked, resumeTransaction, setDebugMonitorFlag, setEJBMetaData, setStartedState, setStoppedState, setUndeployedState, suspendTransaction, toString, undeploy, useClientTx, validateEMForClientTx, validateTxAttr, webServicePostInvoke
-
-
-
-
Method Detail
-
registerMonitorableComponents
protected void registerMonitorableComponents(Method[] msgListenerMethods)
-
getMonitoringStatsProvider
protected EjbMonitoringStatsProvider getMonitoringStatsProvider(String appName, String modName, String ejbName)
- Specified by:
getMonitoringStatsProvider
in classBaseContainer
-
scanForEjbCreateMethod
public boolean scanForEjbCreateMethod()
- Overrides:
scanForEjbCreateMethod
in classBaseContainer
-
initializeHome
protected void initializeHome() throws Exception
Description copied from class:BaseContainer
Called from the ContainerFactory during initialization.- Overrides:
initializeHome
in classBaseContainer
- Throws:
Exception
-
addLocalRemoteInvocationInfo
protected void addLocalRemoteInvocationInfo() throws Exception
- Overrides:
addLocalRemoteInvocationInfo
in classBaseContainer
- Throws:
Exception
-
isCreateHomeFinder
protected boolean isCreateHomeFinder(Method method)
- Overrides:
isCreateHomeFinder
in classBaseContainer
-
validateValue
protected int validateValue(int value, int lowLimit, int highLimit, int deft, String emsg, String appName, Logger logger)
-
getMonitorAttributeValues
public String getMonitorAttributeValues()
-
userTransactionMethodsAllowed
public boolean userTransactionMethodsAllowed(ComponentInvocation inv)
Description copied from class:BaseContainer
EJB spec makes a distinction between access to the UserTransaction object itself and access to its methods. getUserTransaction covers the first check and this method covers the second. It is called by the UserTransaction implementation to verify access.- Specified by:
userTransactionMethodsAllowed
in interfaceContainer
- Overrides:
userTransactionMethodsAllowed
in classBaseContainer
-
getEJBObjectImpl
public EJBObjectImpl getEJBObjectImpl(byte[] instanceKey)
Description copied from class:BaseContainer
Called when a remote invocation arrives for an EJB. Implemented in subclasses.- Specified by:
getEJBObjectImpl
in classBaseContainer
-
createEJBObjectImpl
public EJBObjectImpl createEJBObjectImpl() throws jakarta.ejb.CreateException
- Specified by:
createEJBObjectImpl
in classBaseContainer
- Throws:
jakarta.ejb.CreateException
-
removeBean
protected void removeBean(EJBLocalRemoteObject ejbo, Method removeMethod, boolean local) throws jakarta.ejb.RemoveException, jakarta.ejb.EJBException
- Specified by:
removeBean
in classBaseContainer
- Throws:
jakarta.ejb.RemoveException
jakarta.ejb.EJBException
-
callEJBTimeout
protected boolean callEJBTimeout(RuntimeTimerState timerState, EJBTimerService timerService) throws Exception
Override callEJBTimeout from BaseContainer since delivery to message driven beans is a bit different from session/entity.- Overrides:
callEJBTimeout
in classBaseContainer
- Returns:
- Throws:
Exception
-
forceDestroyBean
protected void forceDestroyBean(EJBContextImpl sc)
Force destroy the EJB. Called from postInvokeTx. Note: EJB2.0 section 18.3.1 says that discarding an EJB means that no methods other than finalize() should be invoked on it.- Specified by:
forceDestroyBean
in classBaseContainer
-
preInvoke
public void preInvoke(EjbInvocation inv)
Description copied from class:BaseContainer
Called from EJBObject/EJBHome before invoking on EJB. Set the EJB instance in the EjbInvocation. It must be ensured that the following general pattern is followed by various parts of the EJBContainer code: try { container.preInvoke(inv); returnValue = container.intercept(inv); } catch (Exception1 e1) { ... } catch (Exception2 e2) { ... } finally { container.postInvoke(); }- Specified by:
preInvoke
in interfaceContainer
- Overrides:
preInvoke
in classBaseContainer
-
_getContext
protected ComponentContext _getContext(EjbInvocation inv)
- Specified by:
_getContext
in classBaseContainer
-
releaseContext
public void releaseContext(EjbInvocation inv)
Return instance to a pooled state.- Specified by:
releaseContext
in classBaseContainer
-
postInvoke
public void postInvoke(EjbInvocation inv)
TODO public void appendStats(StringBuilder sbuf) { sbuf.append("\nMessageBeanContainer: ").append("CreateCount=").append( statCreateCount).append("; ").append("RemoveCount=").append( statRemoveCount).append("; ").append("MsgCount=").append( statMessageCount).append("; "); sbuf.append("]"); }- Specified by:
postInvoke
in interfaceContainer
- Overrides:
postInvoke
in classBaseContainer
-
createMessageBeanListener
public MessageBeanListener createMessageBeanListener(ResourceHandle resource) throws ResourcesExceededException
Create a MessageBeanListener.- Specified by:
createMessageBeanListener
in interfaceMessageBeanProtocolManager
- Parameters:
resource
- handle associated with this listener. can be null.- Throws:
ResourcesExceededException
-
destroyMessageBeanListener
public void destroyMessageBeanListener(MessageBeanListener listener)
Description copied from interface:MessageBeanProtocolManager
Return the MessageBeanListener to the container. Since a MessageBeanListener is typically associated with active resources in the MessageBeanContainer, it is the responsibility of the MessageBeanClient to manage them judiciously.- Specified by:
destroyMessageBeanListener
in interfaceMessageBeanProtocolManager
-
isDeliveryTransacted
public boolean isDeliveryTransacted(Method method)
Description copied from interface:MessageBeanProtocolManager
This is used by the message provider to find out whether message deliveries will be transacted or not. The message delivery preferences must not change during the lifetime of a message endpoint. This information is only a hint and may be useful to perform optimizations on message delivery.- Specified by:
isDeliveryTransacted
in interfaceMessageBeanProtocolManager
- Parameters:
method
- One of the methods used to deliver messages, e.g. onMessage method for jakarta.jms.MessageListener. Note that if themethod
is not one of the methods for message delivery, the behavior of this method is not defined.- Returns:
-
getPoolDescriptor
public BeanPoolDescriptor getPoolDescriptor()
Description copied from interface:MessageBeanProtocolManager
Returns the message-bean container's pool properties.- Specified by:
getPoolDescriptor
in interfaceMessageBeanProtocolManager
-
createMessageBeanProxy
public Object createMessageBeanProxy(InvocationHandler handler) throws Exception
Generates the appropriate Proxy based on the message listener type.- Specified by:
createMessageBeanProxy
in interfaceMessageBeanProtocolManager
- Parameters:
handler
- InvocationHandler responsible for calls on the proxy- Returns:
- an object implementing MessageEndpoint and the appropriate MDB view
- Throws:
Exception
-
_constructEJBContextImpl
protected MessageBeanContextImpl _constructEJBContextImpl(Object instance)
Description copied from class:BaseContainer
Must be overridden for any container that supports injection- Overrides:
_constructEJBContextImpl
in classBaseContainer
- Returns:
EJBContextImpl
-
afterBegin
protected void afterBegin(EJBContextImpl context)
- Specified by:
afterBegin
in classBaseContainer
-
beforeCompletion
protected void beforeCompletion(EJBContextImpl context)
- Specified by:
beforeCompletion
in classBaseContainer
-
afterCompletion
protected void afterCompletion(EJBContextImpl ctx, int status)
- Specified by:
afterCompletion
in classBaseContainer
-
passivateEJB
public boolean passivateEJB(ComponentContext context)
- Specified by:
passivateEJB
in classBaseContainer
-
activateEJB
@Deprecated public void activateEJB(Object ctx, Object instanceKey)
Deprecated.not called and not used in Payara 5
-
startApplication
public void startApplication(boolean deploy)
Called when the application containing this message-bean has successfully gotten through the initial load phase of each module. Now we can "turn on the spigot" and allow incoming requests, which could result in the creation of message-bean instances.- Specified by:
startApplication
in interfaceContainer
- Overrides:
startApplication
in classBaseContainer
- Parameters:
deploy
- true if this method is called during application deploy
-
doConcreteContainerShutdown
protected void doConcreteContainerShutdown(boolean appBeingUndeployed)
Called by BaseContainer during container shutdown sequence- Specified by:
doConcreteContainerShutdown
in classBaseContainer
- Parameters:
appBeingUndeployed
-
-
beforeMessageDelivery
public void beforeMessageDelivery(Method method, MessageBeanContainer.MessageDeliveryType deliveryType, boolean txImported, ResourceHandle resourceHandle)
Actual message delivery happens in three steps : 1) beforeMessageDelivery(Message, MessageListener) This is our chance to make the message delivery itself part of the instance's global transaction. 2) onMessage(Message, MessageListener) This is where the container delegates to the actual ejb instance's onMessage method. 3) afterMessageDelivery(Message, MessageListener) Perform transaction cleanup and error handling. We use the EjbInvocation manager's thread-specific state to track the invocation across these three calls.- Parameters:
method
-deliveryType
-txImported
-resourceHandle
-
-
afterMessageDelivery
public void afterMessageDelivery(ResourceHandle resourceHandle)
-
getMessageCount
public long getMessageCount()
-
-