JBoss development,
A new message was posted in the thread "Externalizing Scope: Resolving EJB References
and Endpoints":
http://community.jboss.org/message/524041#524041
Author : Andrew Rubinger
Profile :
http://community.jboss.org/people/ALRubinger
Message:
--------------------------------------------------------------
Some notes from our discussion today:
This cannot work:
//API:
/**
* All EJB3.x SFSBs will have this bound into JNDI
* at default: [appName]/moduleName/beanName/home
*/
interface StatefulSessionHome
{
void remove(StatefulSessionHandle)
boolean exists(StatefulSessionHandle);
<T> T create(T type) throws IllegalArgumentException;
}
//API:
/**
* All SFSB proxies may be cast to this type
* by the client
*/
interface StatefulSessionHandle
{
// Marker only from the client view
}
//SPI:
/**
* This is how the container knows the ID of the session to remove;
* all SFSB proxies will implement this method
*/
interface StatefulSessionHandleProvider extends StatefulSessionHandle
{
Object getId();
}
// Usage:
StatefulSessionHome home =
(StatefulSessionHome)context.lookup("beanName/home");
MyBusiness bean = home.create(MyBusiness.class);
home.remove((StatefulSessionHandle)bean);
// Traditional JNDI lookup removal:
MyBusiness bean = context.lookup("beanName/remote");
home.remove((StatefulSessionHandle)bean);
Again, this is because we can't define *any* methods upon a proxy which is for
business interfaces; we could introduce conflicts in method names. In the case above, no
user code could have "getId();" for example.
An alternative way is to do something like have a Home per EJB Container. Then the home
knows how to go into the internals of the proxy handler to extract the ID. Jaikiran wrote
up a nice example:
/***************** client (weld-int) *********************/
// user looks up or injects a SFSB (as usual)
UserSFSBInterface proxy = ...//get it as usual
// now get a StatefulSessionHandleProvider (this needs discussion, but let's say
it's available in JNDI for each SFSB)
StatefulSessionHandleProvider handleProvider =
ctx.lookup("beanName/handleprovider");
StatefulSessionHandle handle = handleProvider.getHandle(proxy);
// do some stuff
handle.destroy();
/***************** SPI*********************/
StatefulSessionHandleProvider
{
StatefulSessionHandle getHandle(Object proxy);
}
StatefulSessionHandle
{
destroy();
}
/***************** SPI implementation (for nointerface view) *********************/
// Individual handle provider impl
JavassistProxyBasedHandleProvider implements StatefulSessionHandleProvider
{
StatefulSessionHandle getHandle(Object proxy)
{
// do some checks on proxy
// and return a handle
new JavassistBasedSFSBHandle(proxy)
}
}
// JavassistBased handle for nointerface view
JavassistBasedSFSBHandle implements StatefulSessionHandle
{
Serializable sessionId;
JavassistBasedSFSBHandle(Object proxy)
{
// this knows the magic to get the session id from proxy
this.sessionId = doSomeMagicOnProxy();
}
destroy()
{
// destroy the session using hte session id
container.destroy(this.sessionId);
}
}
Too bad here we'd need a Home handle (HandleProvider in the example above) per
container type.
S,
ALR
--------------------------------------------------------------
To reply to this message visit the message page:
http://community.jboss.org/message/524041#524041