| Method from org.jboss.ejb.SessionContainer Detail: |
public void addInterceptor(Interceptor in) {
if (interceptor == null)
{
interceptor = in;
}
else
{
Interceptor current = interceptor;
while (current.getNext() != null)
{
current = current.getNext();
}
current.setNext(in);
}
}
add an additional interceptor to the chain |
protected void checkCoherency() throws Exception {
// Check clustering cohrency wrt metadata
//
if (metaData.isClustered())
{
boolean clusteredProxyFactoryFound = false;
Iterator it = proxyFactories.keySet().iterator();
while (it.hasNext())
{
String invokerBinding = (String) it.next();
EJBProxyFactory ci = (EJBProxyFactory) proxyFactories.get(invokerBinding);
if (ci instanceof org.jboss.proxy.ejb.ClusterProxyFactory)
clusteredProxyFactoryFound = true;
}
if (!clusteredProxyFactoryFound)
{
log.warn("*** EJB '"
+ this.metaData.getEjbName()
+ "' deployed as CLUSTERED but not a single clustered-invoker is bound to container ***");
}
}
}
|
protected void createInstanceCache() throws Exception {
}
no instance cache per default |
protected void createInstancePool() throws Exception {
// Try to register the instance pool as an MBean
try
{
ObjectName containerName = super.getJmxName();
Hashtable props = containerName.getKeyPropertyList();
props.put("plugin", "pool");
ObjectName poolName = new ObjectName(containerName.getDomain(), props);
server.registerMBean(instancePool, poolName);
}
catch (Throwable t)
{
log.debug("Failed to register pool as mbean", t);
}
// Initialize pool
instancePool.create();
}
creates a new instance pool |
protected void createInterceptors() throws Exception {
Interceptor in = interceptor;
while (in != null)
{
in.setContainer(this);
in.create();
in = in.getNext();
}
}
Initialize the interceptors by calling the chain |
protected void createInvokers() throws Exception {
// Init container invoker
for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext();)
{
String invokerBinding = (String) it.next();
EJBProxyFactory ci = (EJBProxyFactory) proxyFactories.get(invokerBinding);
ci.create();
}
}
|
protected void createPersistenceManager() throws Exception {
}
no persistence manager per default |
protected void createService() throws Exception {
// Associate thread with classloader
ClassLoader oldCl = SecurityActions.getContextClassLoader();
SecurityActions.setContextClassLoader(getClassLoader());
pushENC();
try
{
// Acquire classes from CL
if (metaData.getHome() != null)
homeInterface = classLoader.loadClass(metaData.getHome());
if (metaData.getRemote() != null)
remoteInterface = classLoader.loadClass(metaData.getRemote());
if (((SessionMetaData) metaData).getServiceEndpoint() != null)
{
serviceEndpoint =
classLoader.loadClass(((SessionMetaData) metaData).getServiceEndpoint());
}
// Call default init
super.createService();
// Make some additional validity checks with regards to the container configuration
checkCoherency();
// Map the bean methods
setupBeanMapping();
// Map the home methods
setupHomeMapping();
// Map the interfaces to Long
setupMarshalledInvocationMapping();
createInvokers();
createInstanceCache();
createInstancePool();
createPersistenceManager();
createInterceptors();
}
finally
{
popENC();
// Reset classloader
SecurityActions.setContextClassLoader(oldCl);
}
}
|
protected void destroyInstanceCache() {
}
|
protected void destroyInstancePool() {
// Destroy pool
instancePool.destroy();
instancePool.setContainer(null);
try
{
ObjectName containerName = super.getJmxName();
Hashtable props = containerName.getKeyPropertyList();
props.put("plugin", "pool");
ObjectName poolName = new ObjectName(containerName.getDomain(), props);
server.unregisterMBean(poolName);
}
catch (Throwable ignore)
{
}
}
|
protected void destroyInterceptors() {
// Destroy all the interceptors in the chain
Interceptor in = interceptor;
while (in != null)
{
in.destroy();
in.setContainer(null);
in = in.getNext();
}
}
|
protected void destroyInvokers() {
// Destroy container invoker
for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext();)
{
String invokerBinding = (String) it.next();
EJBProxyFactory ci = (EJBProxyFactory) proxyFactories.get(invokerBinding);
ci.destroy();
ci.setContainer(null);
}
}
|
protected void destroyMarshalledInvocationMapping() {
MarshalledInvocation.removeHashes(homeInterface);
MarshalledInvocation.removeHashes(remoteInterface);
}
|
protected void destroyPersistenceManager() {
}
|
protected void destroyService() throws Exception {
// Associate thread with classloader
ClassLoader oldCl = SecurityActions.getContextClassLoader();
SecurityActions.setContextClassLoader(getClassLoader());
pushENC();
try
{
destroyInvokers();
destroyInstanceCache();
destroyInstancePool();
destroyPersistenceManager();
destroyInterceptors();
destroyMarshalledInvocationMapping();
homeInterface = null;
remoteInterface = null;
serviceEndpoint = null;
beanMapping.clear();
// Call default destroy
super.destroyService();
}
finally
{
popENC();
// Reset classloader
SecurityActions.setContextClassLoader(oldCl);
}
}
|
protected Map getBeanMapping() {
return beanMapping;
}
needed for sub-inner-class access (old jdk compiler bug) |
public EJBHome getEJBHome(Invocation mi) throws RemoteException {
EJBProxyFactory ci = getProxyFactory();
if (ci == null)
{
String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor";
throw new IllegalStateException(msg);
}
return (EJBHome) ci.getEJBHome();
}
|
public EJBLocalHome getEJBLocalHome(Invocation mi) {
return localProxyFactory.getEJBLocalHome();
}
|
public EJBMetaData getEJBMetaDataHome() throws RemoteException {
EJBProxyFactory ci = getProxyFactory();
if (ci == null)
{
String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor";
throw new IllegalStateException(msg);
}
return ci.getEJBMetaData();
}
|
public EJBMetaData getEJBMetaDataHome(Invocation mi) throws RemoteException {
return getEJBMetaDataHome();
}
|
public Handle getHandle(Invocation mi) throws RemoteException {
// TODO
return null;
}
While the following methods are implemented in the client in the case
of JRMP we would need to implement them to fully support other transport
protocols |
public HomeHandle getHomeHandleHome() throws RemoteException {
EJBProxyFactory ci = getProxyFactory();
if (ci == null)
{
String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor";
throw new IllegalStateException(msg);
}
EJBHome home = (EJBHome) ci.getEJBHome();
return home.getHomeHandle();
}
|
public HomeHandle getHomeHandleHome(Invocation mi) throws RemoteException {
return getHomeHandleHome();
}
|
protected Map getHomeMapping() {
return homeMapping;
}
needed for sub-inner-class access (old jdk compiler bug) |
public InstancePool getInstancePool() {
return instancePool;
}
|
public Interceptor getInterceptor() {
return interceptor;
}
|
public LocalProxyFactory getLocalProxyFactory() {
return localProxyFactory;
}
return local proxy factory |
public Object getPrimaryKey() throws RemoteException {
throw new RemoteException("Call to getPrimaryKey not allowed on session bean");
}
|
public Object getPrimaryKey(Invocation mi) throws RemoteException {
return getPrimaryKey();
}
|
public Class getServiceEndpoint() {
return serviceEndpoint;
}
|
public Object internalInvoke(Invocation mi) throws Exception {
// Invoke through interceptors
return getInterceptor().invoke(mi);
}
This method does invocation interpositioning of tx and security,
retrieves the instance from an object table, and invokes the method
on the particular instance |
public Object internalInvokeHome(Invocation mi) throws Exception {
Method method = mi.getMethod();
if (method != null && method.getName().equals("remove"))
{
// Handle or primary key?
Object arg = mi.getArguments()[0];
if (arg instanceof Handle)
{
if (arg == null)
throw new RemoteException("Null handle");
Handle handle = (Handle) arg;
EJBObject ejbObject = handle.getEJBObject();
ejbObject.remove();
return null;
}
else
throw new RemoveException("EJBHome.remove(Object) not allowed for session beans");
}
// Invoke through interceptors
return getInterceptor().invokeHome(mi);
}
|
public boolean isIdentical(Invocation mi) throws RemoteException {
EJBProxyFactory ci = getProxyFactory();
if (ci == null)
{
String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor";
throw new IllegalStateException(msg);
}
return ci.isIdentical(this, mi);
}
|
public void setInstancePool(InstancePool ip) {
if (ip == null)
throw new IllegalArgumentException("Null pool");
this.instancePool = ip;
ip.setContainer(this);
}
|
protected void setUpBeanMappingImpl(Map map,
Method[] methods,
String declaringClass) throws NoSuchMethodException {
for (int i = 0; i < methods.length; i++)
{
Method m = methods[i];
if (m.getDeclaringClass().getName().equals(declaringClass) == false)
{
// Implemented by bean
try
{
Method beanMethod = beanClass.getMethod(m.getName(), m.getParameterTypes());
map.put(m, beanMethod);
}
catch (NoSuchMethodException ex)
{
throw new NoSuchMethodException("Not found in bean class: " + m);
}
log.debug("Mapped " + m.getName() + " HASH " + m.hashCode() + "to " + map.get(m));
}
else
{
// Implemented by container
try
{
Method containerMethod = getClass().getMethod(m.getName(), new Class[]{Invocation.class});
map.put(m, containerMethod);
}
catch (NoSuchMethodException e)
{
throw new NoSuchMethodException("Not found in container class: " + m);
}
log.debug("Mapped Container method " + m.getName() + " HASH " + m.hashCode());
}
}
}
loop through methods and setup mapping |
protected void setupBeanMapping() throws NoSuchMethodException {
Map map = new HashMap();
if (remoteInterface != null)
{
Method[] m = remoteInterface.getMethods();
setUpBeanMappingImpl(map, m, "javax.ejb.EJBObject");
}
if (localInterface != null)
{
Method[] m = localInterface.getMethods();
setUpBeanMappingImpl(map, m, "javax.ejb.EJBLocalObject");
}
if (TimedObject.class.isAssignableFrom(beanClass))
{
Method[] m = new Method[]{TimedObject.class.getMethod("ejbTimeout", new Class[]{Timer.class})};
setUpBeanMappingImpl(map, m, "javax.ejb.Timer");
}
if (serviceEndpoint != null)
{
Method[] m = serviceEndpoint.getMethods();
setUpBeanMappingImpl(map, m, "java.rmi.Remote");
}
beanMapping = map;
}
build bean mappings for application logic |
abstract protected void setupHomeMapping() throws Exception
how home methods are treated by container |
protected void setupMarshalledInvocationMapping() throws Exception {
// Create method mappings for container invoker
if (homeInterface != null)
{
Method[] m = homeInterface.getMethods();
for (int i = 0; i < m.length; i++)
{
marshalledInvocationMapping.put(new Long(MarshalledInvocation.calculateHash(m[i])), m[i]);
}
}
if (remoteInterface != null)
{
Method[] m = remoteInterface.getMethods();
for (int j = 0; j < m.length; j++)
{
marshalledInvocationMapping.put(new Long(MarshalledInvocation.calculateHash(m[j])), m[j]);
}
}
// Get the getEJBObjectMethod
Method getEJBObjectMethod =
Class.forName("javax.ejb.Handle").getMethod("getEJBObject",
new Class[0]);
// Hash it
marshalledInvocationMapping.put(new Long(MarshalledInvocation.calculateHash(getEJBObjectMethod)), getEJBObjectMethod);
}
sets up marshalled invocation mappings |
protected void startInstanceCache() throws Exception {
}
no instance cache per default |
protected void startInstancePool() throws Exception {
instancePool.start();
}
|
protected void startInterceptors() throws Exception {
Interceptor in = interceptor;
while (in != null)
{
in.start();
in = in.getNext();
}
}
Start all interceptors in the chain |
protected void startInvokers() throws Exception {
for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext();)
{
String invokerBinding = (String) it.next();
EJBProxyFactory ci = (EJBProxyFactory) proxyFactories.get(invokerBinding);
ci.start();
}
}
|
protected void startPersistenceManager() throws Exception {
}
no persistence manager per default |
protected void startService() throws Exception {
// Associate thread with classloader
ClassLoader oldCl = SecurityActions.getContextClassLoader();
SecurityActions.setContextClassLoader(getClassLoader());
pushENC();
try
{
// Call default start
super.startService();
startInvokers();
startInstanceCache();
startInstancePool();
startPersistenceManager();
startInterceptors();
// Restore persisted ejb timers
restoreTimers();
}
finally
{
popENC();
// Reset classloader
SecurityActions.setContextClassLoader(oldCl);
}
}
|
protected void stopInstanceCache() {
}
|
protected void stopInstancePool() {
instancePool.stop();
}
|
protected void stopInterceptors() {
Interceptor in = interceptor;
while (in != null)
{
in.stop();
in = in.getNext();
}
}
Stop all interceptors in the chain |
protected void stopInvokers() {
for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext();)
{
String invokerBinding = (String) it.next();
EJBProxyFactory ci = (EJBProxyFactory) proxyFactories.get(invokerBinding);
ci.stop();
}
}
|
protected void stopPersistenceManager() {
}
|
protected void stopService() throws Exception {
// Associate thread with classloader
ClassLoader oldCl = SecurityActions.getContextClassLoader();
SecurityActions.setContextClassLoader(getClassLoader());
pushENC();
try
{
// Call default stop
super.stopService();
stopInvokers();
stopInstanceCache();
stopInstancePool();
stopPersistenceManager();
stopInterceptors();
}
finally
{
popENC();
// Reset classloader
SecurityActions.setContextClassLoader(oldCl);
}
}
|