| Method from org.jboss.ejb.StatefulSessionContainer Detail: |
protected Interceptor createContainerInterceptor() {
return new ContainerInterceptor();
}
|
public EJBObject createHome(Invocation mi) throws Exception {
StatefulSessionEnterpriseContext ctx = (StatefulSessionEnterpriseContext) mi.getEnterpriseContext();
createSession(mi.getMethod(), mi.getArguments(), ctx);
return ctx.getEJBObject();
}
|
protected void createInstanceCache() throws Exception {
// Try to register the instance cache as an MBean
try
{
ObjectName containerName = super.getJmxName();
Hashtable props = containerName.getKeyPropertyList();
props.put("plugin", "cache");
ObjectName cacheName = new ObjectName(containerName.getDomain(), props);
server.registerMBean(instanceCache, cacheName);
}
catch (Throwable t)
{
log.debug("Failed to register cache as mbean", t);
}
// Init instance cache
instanceCache.create();
}
creates and registers the instance cache |
public EJBLocalObject createLocalHome(Invocation mi) throws Exception {
StatefulSessionEnterpriseContext ctx = (StatefulSessionEnterpriseContext) mi.getEnterpriseContext();
createSession(mi.getMethod(), mi.getArguments(), ctx);
return ctx.getEJBLocalObject();
}
|
protected void createPersistenceManager() throws Exception {
persistenceManager.create();
}
create persistence manager |
protected void createService() throws Exception {
super.createService();
// Get the Handle.getEJBObject method for permission checks
try
{
getEJBObject = Handle.class.getMethod("getEJBObject", new Class[0]);
}
catch (Exception e)
{
log.warn("Failed to grant access to the Handle.getEJBObject method");
}
ejbObjectRemove = EJBObject.class.getMethod("remove", null);
ejbLocalObjectRemove = EJBLocalObject.class.getMethod("remove", null);
}
|
protected void destroyInstanceCache() {
// Destroy instance cache
instanceCache.destroy();
instanceCache.setContainer(null);
try
{
ObjectName containerName = super.getJmxName();
Hashtable props = containerName.getKeyPropertyList();
props.put("plugin", "cache");
ObjectName cacheName = new ObjectName(containerName.getDomain(), props);
server.unregisterMBean(cacheName);
}
catch (Throwable ignore)
{
}
}
|
protected void destroyPersistenceManager() {
// Destroy persistence
persistenceManager.destroy();
persistenceManager.setContainer(null);
}
|
public EJBObject getEJBObject(Invocation mi) throws RemoteException {
// All we need is an EJBObject for this Id, the first argument is the Id
EJBProxyFactory ci = getProxyFactory();
if (ci == null)
{
String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor";
throw new IllegalStateException(msg);
}
Object id = mi.getArguments()[0];
if (id == null)
throw new IllegalStateException("Cannot get a session interface with a null id");
// Does the session still exist?
InstanceCache cache = getInstanceCache();
BeanLock lock = getLockManager().getLock(id);
lock.sync();
try
{
if (cache.get(id) == null)
throw new RemoteException("Session no longer exists: " + id);
}
finally
{
lock.releaseSync();
getLockManager().removeLockRef(id);
}
// Ok lets create the proxy
return (EJBObject) ci.getStatefulSessionEJBObject(id);
}
A method for the getEJBObject from the handle |
public InstanceCache getInstanceCache() {
return instanceCache;
}
|
public Set getMethodPermissions(Method m,
InvocationType iface) {
if (m.equals(getEJBObject) == false)
return super.getMethodPermissions(m, iface);
Class[] sig = {};
Set< String > permissions = getBeanMetaData().getMethodPermissions("create",
sig, iface);
//Convert this into Set of Principals
Set< Principal > principalSet = new HashSet< Principal >();
for(String perm: permissions)
{
principalSet.add(new SimplePrincipal(perm));
}
return principalSet;
}
Override getMethodPermissions to work around the fact that stateful
session handles obtain their ejb objects by doing an invocation on the
container as a home method invocation using the Handle.getEJBObject
method. |
public StatefulSessionPersistenceManager getPersistenceManager() {
return persistenceManager;
}
|
public void remove(Invocation mi) throws RemoveException, RemoteException {
// if the session is removed already then let the user know they have a problem
StatefulSessionEnterpriseContext ctx = (StatefulSessionEnterpriseContext) mi.getEnterpriseContext();
if (ctx.getId() == null)
{
throw new RemoveException("SFSB has been removed already");
}
// Remove from storage
try
{
AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_REMOVE);
getPersistenceManager().removeSession(ctx);
}
finally
{
AllowedOperationsAssociation.popInMethodFlag();
}
// We signify "removed" with a null id
ctx.setId(null);
removeCount++;
}
|
public void removeHome(Invocation mi) throws RemoveException, RemoteException {
throw new Error("Not Yet Implemented");
}
|
public void removeLocalHome(Invocation mi) throws RemoveException, RemoteException {
throw new UnreachableStatementException();
}
|
public void setInstanceCache(InstanceCache ic) {
this.instanceCache = ic;
ic.setContainer(this);
}
|
public void setPersistenceManager(StatefulSessionPersistenceManager pm) {
persistenceManager = pm;
pm.setContainer(this);
}
|
protected void setupHomeMapping() throws Exception {
// Adrian Brock: This should go away when we don't support EJB1x
boolean isEJB1x = metaData.getApplicationMetaData().isEJB1x();
Map map = new HashMap();
if (homeInterface != null)
{
Method[] m = homeInterface.getMethods();
for (int i = 0; i < m.length; i++)
{
try
{
// Implemented by container
if (isEJB1x == false && m[i].getName().startsWith("create"))
{
map.put(m[i], getClass().getMethod("createHome",
new Class[]{Invocation.class}));
}
else
{
map.put(m[i], getClass().getMethod(m[i].getName() + "Home",
new Class[]{Invocation.class}));
}
}
catch (NoSuchMethodException e)
{
log.info(m[i].getName() + " in bean has not been mapped");
}
}
}
if (localHomeInterface != null)
{
Method[] m = localHomeInterface.getMethods();
for (int i = 0; i < m.length; i++)
{
try
{
// Implemented by container
if (isEJB1x == false && m[i].getName().startsWith("create"))
{
map.put(m[i], getClass().getMethod("createLocalHome",
new Class[]{Invocation.class}));
}
else
{
map.put(m[i], getClass().getMethod(m[i].getName() + "LocalHome",
new Class[]{Invocation.class}));
}
}
catch (NoSuchMethodException e)
{
log.info(m[i].getName() + " in bean has not been mapped");
}
}
}
try
{
// Get getEJBObject from on Handle, first get the class
Class handleClass = Class.forName("javax.ejb.Handle");
//Get only the one called handle.getEJBObject
Method getEJBObjectMethod = handleClass.getMethod("getEJBObject", new Class[0]);
//Map it in the home stuff
map.put(getEJBObjectMethod, getClass().getMethod("getEJBObject",
new Class[]{Invocation.class}));
}
catch (NoSuchMethodException e)
{
log.debug("Couldn't find getEJBObject method on container");
}
homeMapping = map;
}
|
protected void startInstanceCache() throws Exception {
instanceCache.start();
}
|
protected void startPersistenceManager() throws Exception {
persistenceManager.start();
}
|
protected void stopInstanceCache() {
instanceCache.stop();
}
|
protected void stopPersistenceManager() {
persistenceManager.stop();
}
|