| Method from org.jboss.ejb.Container Detail: |
abstract public void addInterceptor(Interceptor in)
|
public void addProxyFactory(String invokerBinding,
EJBProxyFactory factory) {
proxyFactories.put(invokerBinding, factory);
}
|
public void cleanENC() {
ENCFactory.getEncById().remove(getJmxName());
}
|
public Object createBeanClassInstance() throws Exception {
return getBeanClass().newInstance();
}
Returns a new instance of the bean class or a subclass of the bean class.
This factory style method is speciffically used by a container to supply
an implementation of the abstract accessors in EJB2.0, but could be
usefull in other situations. This method should ALWAYS be used instead
of getBeanClass().newInstance(); |
abstract Interceptor createContainerInterceptor()
|
protected void createService() throws Exception {
// Acquire classes from CL
beanClass = classLoader.loadClass(metaData.getEjbClass());
if (metaData.getLocalHome() != null)
localHomeInterface = classLoader.loadClass(metaData.getLocalHome());
if (metaData.getLocal() != null)
localInterface = classLoader.loadClass(metaData.getLocal());
localProxyFactory.setContainer(this);
localProxyFactory.create();
if (localHomeInterface != null)
ejbModule.addLocalHome(this, localProxyFactory.getEJBLocalHome());
ejbModule.createMissingPermissions(this, metaData);
// Allow the policy to incorporate the policy configs
Policy.getPolicy().refresh();
}
The EJBDeployer calls this method. The EJBDeployer has set
all the plugins and interceptors that this bean requires and now proceeds
to initialize the chain. The method looks for the standard classes in
the URL, sets up the naming environment of the bean. The concrete
container classes should override this method to introduce
implementation specific initialization behaviour. |
protected void destroyService() throws Exception {
cleanENC();
localProxyFactory.destroy();
ejbModule.removeLocalHome(this);
beanClass = null;
homeInterface = null;
remoteInterface = null;
localHomeInterface = null;
localInterface = null;
methodPermissionsCache.clear();
// InvocationStatistics holds refs to Methods from
// application classes, so to avoid a classloader
// leak, lets not just resetStats() but also replace
// the object
invokeStats.resetStats(); // in case someone else has a ref
invokeStats = new InvocationStatistics();
marshalledInvocationMapping.clear();
}
A default implementation of destroying the container service (no-op).
The concrete container classes should override this method to introduce
implementation specific destroy behaviour. |
public Class getBeanClass() {
return beanClass;
}
Returns the bean class instance of this container. |
public BeanMetaData getBeanMetaData() {
return metaData;
}
Returns the metadata of this container. |
public ClassLoader getClassLoader() {
return classLoader;
}
Returns the classloader for this container. |
public long getCreateCount() {
return createCount;
}
Gets the number of create invocations that have been made |
public String getDefaultSecurityDomain() {
return defaultSecurityDomain;
}
|
public final DeploymentInfo getDeploymentInfo() {
return null;
} Deprecated! use - DeploymentUnit accessors
Gets the DeploymentInfo for this Container |
public final VFSDeploymentUnit getDeploymentUnit() {
return unit;
}
|
public EjbModule getEjbModule() {
return ejbModule;
}
Gets the application deployment unit for this container. All the bean
containers within the same application unit share the same instance. |
public Context getEnvContext() throws NamingException {
pushENC();
try
{
return (Context)new InitialContext().lookup("java:comp/env");
}
finally
{
popENC();
}
}
Get the components environment context |
public Class getHomeClass() {
return homeInterface;
}
this actually should be called remotehome, but for interface compliance purposes
we keep it like that |
public InvocationStatistics getInvokeStats() {
return invokeStats;
}
Gets the invocation statistics collection |
public String getJaccContextID() {
return jaccContextID;
}
|
public ObjectName getJmxName() {
if (jmxName == null)
{
BeanMetaData beanMetaData = getBeanMetaData();
if (beanMetaData == null)
{
throw new IllegalStateException("Container metaData is null");
}
String jndiName = beanMetaData.getContainerObjectNameJndiName();
if (jndiName == null)
{
throw new IllegalStateException("Container jndiName is null");
}
// The name must be escaped since the jndiName may be arbitrary
String name = BASE_EJB_CONTAINER_NAME + ",jndiName=" + jndiName;
try
{
jmxName = ObjectNameConverter.convert(name);
}
catch (MalformedObjectNameException e)
{
throw new RuntimeException("Failed to create ObjectName, msg=" + e.getMessage());
}
}
return jmxName;
}
Build a JMX name using the pattern jboss.j2ee:service=EJB,jndiName=[jndiName]
where the [jndiName] is either the bean remote home JNDI binding, or
the local home JNDI binding if the bean has no remote interfaces. |
public Class getLocalClass() {
try
{
EJBOBJECT_REMOVE = EJBObject.class.getMethod("remove", new Class[0]);
EJB_TIMEOUT = TimedObject.class.getMethod("ejbTimeout", new Class[] { Timer.class });
}
catch (Throwable t)
{
throw new NestedRuntimeException(t);
}
return localInterface;
}
|
public Class getLocalHomeClass() {
return localHomeInterface;
}
|
public BeanLockManager getLockManager() {
return lockManager;
}
|
public MessageDestinationMetaData getMessageDestination(String link) {
return EjbUtil50.findMessageDestination(null, unit, link);
}
|
public Set getMethodPermissions(Method m,
InvocationType iface) {
Set< Principal > permissions;
if (methodPermissionsCache.containsKey(m))
{
permissions = (Set)methodPermissionsCache.get(m);
}
else if (m.equals(EJB_TIMEOUT))
{
// No role is required to access the ejbTimeout as this is
permissions = new HashSet< Principal >();
permissions.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
methodPermissionsCache.put(m, permissions);
}
else
{
String name = m.getName();
Class[] sig = m.getParameterTypes();
Set< String > roles = getBeanMetaData().getMethodPermissions(name, sig, iface);
permissions = new HashSet< Principal >();
if (roles != null)
{
for (String role : roles)
permissions.add(new SimplePrincipal(role));
}
methodPermissionsCache.put(m, permissions);
}
return permissions;
}
Returns the permissions for a method. (a set of roles) |
public PolicyRegistration getPolicyRegistration() {
return policyRegistration;
}
|
public EJBProxyFactory getProxyFactory() {
EJBProxyFactory factory = (EJBProxyFactory)proxyFactoryTL.get();
// There's no factory thread local which means this is probably
// a local invocation. Just use the first (usually only)
// proxy factory.
// TODO: define a default factory in the meta data or
// even better, let the return over the original transport
// plugin the transport layer for the generated proxy
if (factory == null && remoteInterface != null)
{
Iterator i = proxyFactories.values().iterator();
if (i.hasNext())
factory = (EJBProxyFactory)i.next();
}
return factory;
}
|
public RealmMapping getRealmMapping() {
return rm;
}
|
public Class getRemoteClass() {
return remoteInterface;
}
|
public long getRemoveCount() {
return removeCount;
}
Gets the number of remove invocations that have been made |
public String getSecurityContextClassName() {
return securityContextClassName;
}
|
public ISecurityManagement getSecurityManagement() {
return securityManagement;
}
|
public AuthenticationManager getSecurityManager() {
return sm;
}
|
public Object getSecurityProxy() {
return securityProxy;
}
|
public EJBTimerService getTimerService() {
return timerService;
}
|
public TimerService getTimerService(Object pKey) throws IllegalStateException {
if (this instanceof StatefulSessionContainer)
throw new IllegalStateException("Statefull Session Beans are not allowed to access the TimerService");
// Validate that the bean implements the TimedObject interface
if (TimedObject.class.isAssignableFrom(beanClass) == false)
{
// jbcts-381
return EJBTimerServiceImpl.FOR_NON_TIMED_OBJECT;
}
TimerService timerService = null;
try
{
timerService = this.timerService.createTimerService(getJmxName(), pKey, this);
}
catch (Exception e)
{
throw new EJBException("Could not create timer service", e);
}
return timerService;
}
Creates the single Timer Service for this container if not already created |
public TransactionManager getTransactionManager() {
return tm;
}
Returns this container's transaction manager. |
public ClassLoader getWebClassLoader() {
return webClassLoader;
}
Get the class loader for dynamic class loading via http. |
abstract public Object internalInvoke(Invocation mi) throws Exception
This method is called when a method call comes
in on an EJBObject. The Container forwards this call to the interceptor
chain for further processing. |
abstract public Object internalInvokeHome(Invocation mi) throws Exception
This method is called when a method call comes
in on the Home object. The Container forwards this call to the
interceptor chain for further processing. |
public Object invoke(Invocation mi) throws Exception {
ClassLoader callerClassLoader = SecurityActions.getContextClassLoader();
long start = System.currentTimeMillis();
Method m = null;
Object type = null;
String contextID = getJaccContextID();
try
{
pushENC();
// JBAS-3732 - Remove classloader.equals optimization
SecurityActions.setContextClassLoader(this.classLoader);
// Set the JACC context id
mi.setValue(InvocationKey.JACC_CONTEXT_ID, contextID);
contextID = SecurityActions.setContextID(contextID);
// Set the standard JACC policy context handler data is not a SEI msg
if (mi.getType() != InvocationType.SERVICE_ENDPOINT)
{
EJBArgsPolicyContextHandler.setArgs(mi.getArguments());
}
else
{
SOAPMessage msg = (SOAPMessage)mi.getValue(InvocationKey.SOAP_MESSAGE);
SOAPMsgPolicyContextHandler.setMessage(msg);
}
// Set custom JACC policy handlers
BeanMetaDataPolicyContextHandler.setMetaData(this.getBeanMetaData());
// Check against home, remote, localHome, local, getHome,
// getRemote, getLocalHome, getLocal
type = mi.getType();
// stat gathering: concurrent calls
this.invokeStats.callIn();
if (type == InvocationType.REMOTE || type == InvocationType.LOCAL ||
// web service calls come in as "ordinary" application invocations
type == InvocationType.SERVICE_ENDPOINT)
{
if (mi instanceof MarshalledInvocation)
{
((MarshalledInvocation)mi).setMethodMap(marshalledInvocationMapping);
if (log.isTraceEnabled())
{
log.trace("METHOD REMOTE INVOKE " + mi.getObjectName() + "||" + mi.getMethod().getName() + "||");
}
}
m = mi.getMethod();
Object obj = internalInvoke(mi);
return obj;
}
else if (type == InvocationType.HOME || type == InvocationType.LOCALHOME)
{
if (mi instanceof MarshalledInvocation)
{
((MarshalledInvocation)mi).setMethodMap(marshalledInvocationMapping);
if (log.isTraceEnabled())
{
log.trace("METHOD HOME INVOKE " + mi.getObjectName() + "||" + mi.getMethod().getName() + "||" + mi.getArguments().toString());
}
}
m = mi.getMethod();
Object obj = internalInvokeHome(mi);
return obj;
}
else
{
throw new MBeanException(new IllegalArgumentException("Unknown invocation type: " + type));
}
}
/**
* Having to catch this exception here in case can not
* unmarshall arguments, values, etc. Then, convert to
* UnmarshalException as defined by spec (JBAS-2999)
*/
catch (JBossLazyUnmarshallingException e)
{
InvocationType calltype = mi.getType();
boolean isLocal = calltype == InvocationType.LOCAL || calltype == InvocationType.LOCALHOME;
// handle unmarshalling exception which should only come if problem unmarshalling
// invocation payload, arguments, or value on remote end.
if (isLocal)
{
throw new EJBException("UnmarshalException", e);
}
else
{
throw new MarshalException("MarshalException", e);
}
}
finally
{
if (m != null)
{
long end = System.currentTimeMillis();
long elapsed = end - start;
this.invokeStats.updateStats(m, elapsed);
}
// stat gathering: concurrent calls
this.invokeStats.callOut();
popENC();
// Restore the incoming class loader
SecurityActions.setContextClassLoader(callerClassLoader);
// Restore the incoming context id
contextID = SecurityActions.setContextID(contextID);
if (mi.getType() == InvocationType.SERVICE_ENDPOINT)
{
// Remove msg from ThreadLocal to prevent leakage into the thread pool
SOAPMsgPolicyContextHandler.setMessage(null);
}
else
{
// Remove args from ThreadLocal to prevent leakage into the thread pool
EJBArgsPolicyContextHandler.setArgs(null);
}
// Remove metadata from ThreadLocal to prevent leakage into the thread pool
BeanMetaDataPolicyContextHandler.setMetaData(null);
}
}
The detached invoker operation. |
public boolean isCallByValue() {
if (ejbModule.isCallByValue())
return true;
return metaData.isCallByValue();
}
Whether the bean is call by value |
public boolean isJaccEnabled() {
return isJaccEnabled;
}
Get the flag whether JACC is enabled |
public EJBProxyFactory lookupProxyFactory(String binding) {
return (EJBProxyFactory)proxyFactories.get(binding);
}
|
public void popENC() {
ENCFactory.popContextId();
}
|
public void pushENC() {
ENCFactory.pushContextId(getJmxName());
}
push the ENC onto the stack so that java:comp works |
public void removeTimerService(Object pKey) throws IllegalStateException {
try
{
if (pKey != null)
{
// entity bean- >remove()
timerService.removeTimerService(getJmxName(), pKey);
}
else
{
// container stop, we choose whether active timers
// should be persisted (default), or not (legacy)
timerService.removeTimerService(getJmxName(), getBeanMetaData().getTimerPersistence());
}
}
catch (Exception e)
{
log.error("Could not remove timer service", e);
}
}
Removes Timer Service for this container |
protected void restoreTimers() {
try
{
// TODO: this name needs to be externalized
// pass to the ejb timer service the container ObjectName
timerService.restoreTimers(getServiceName(), getClassLoader());
}
catch (Exception e)
{
log.warn("Could not restore ejb timers", e);
}
}
Restore any timers previously persisted for this container |
public void setBeanMetaData(BeanMetaData metaData) {
this.metaData = metaData;
}
Sets the meta data for this container. The meta data consists of the
properties found in the XML descriptors. |
public void setClassLoader(ClassLoader cl) {
this.classLoader = cl;
}
Sets the class loader for this container. All the classes and resources
used by the bean in this container will use this classloader. |
public void setDefaultSecurityDomain(String defaultSecurityDomain) {
this.defaultSecurityDomain = defaultSecurityDomain;
}
|
public final void setDeploymentInfo(DeploymentInfo di) {
} Deprecated! use - DeploymentUnit accessors
Sets the DeploymentInfo of this Container |
public final void setDeploymentUnit(VFSDeploymentUnit di) {
this.unit = di;
}
|
public void setEjbModule(EjbModule app) {
ejbModule = app;
}
Sets the application deployment unit for this container. All the bean
containers within the same application unit share the same instance. |
public void setJaccContextID(String id) {
jaccContextID = id;
}
|
public void setJaccEnabled(boolean isJaccEnabled) {
this.isJaccEnabled = isJaccEnabled;
}
Set the flag that JACC is enabled |
public void setLockManager(BeanLockManager lockManager) {
this.lockManager = lockManager;
lockManager.setContainer(this);
}
|
public void setPolicyRegistration(PolicyRegistration policyRegistration) {
this.policyRegistration = policyRegistration;
}
|
public void setProxyFactory(Object factory) {
proxyFactoryTL.set(factory);
}
|
public void setRealmMapping(RealmMapping rm) {
this.rm = rm;
}
|
public void setSecurityContextClassName(String securityContextClassName) {
this.securityContextClassName = securityContextClassName;
}
|
public void setSecurityManagement(ISecurityManagement securityManagement) {
this.securityManagement = securityManagement;
}
|
public void setSecurityManager(AuthenticationManager sm) {
this.sm = sm;
}
|
public void setSecurityProxy(Object proxy) {
this.securityProxy = proxy;
}
|
public void setTimerService(EJBTimerService timerService) {
this.timerService = timerService;
}
|
public void setTransactionManager(TransactionManager tm) {
this.tm = tm;
}
Sets a transaction manager for this container. |
public void setWebClassLoader(ClassLoader webClassLoader) {
this.webClassLoader = webClassLoader;
}
Set the class loader for dynamic class loading via http. |
protected void startService() throws Exception {
// Setup "java:comp/env" namespace
setupEnvironment();
localProxyFactory.start();
}
A default implementation of starting the container service.
The container registers it's dynamic MBean interface in the JMX base.
The concrete container classes should override this method to introduce
implementation specific start behaviour.
todo implement the service lifecycle methods in an xmbean interceptor so
non lifecycle managed ops are blocked when mbean is not started. |
protected void stopService() throws Exception {
localProxyFactory.stop();
removeTimerService(null);
teardownEnvironment();
}
A default implementation of stopping the container service (no-op). The
concrete container classes should override this method to introduce
implementation specific stop behaviour. |