-
1. Re: Requesting the EJB container to remove an instance
wolfc Mar 9, 2009 3:17 AM (in response to pmuir)We could bind a 'home' interface and call it 'meta' instead.
-
2. Re: Requesting the EJB container to remove an instance
pmuir Mar 9, 2009 11:24 AM (in response to pmuir)I guess again it comes down to needing a way to uniquely identify an SFSB instance. I guess I can squirrel away the reference to the actual bean obtained from @PostConstruct and pass that through? Would that be good way to identify it from the EJB3.0
-
3. Re: Requesting the EJB container to remove an instance
pmuir Mar 12, 2009 7:44 PM (in response to pmuir)Hmm, this won't work, as I need this to be serializable. So, I guess we need some serializable identifier for a session bean instance. Perhaps we change to an EjbResolver for getting instances of SFSB that can return something like:
interface EJBInstance<T> { Serializable getId(); T getInstance(); }
rather than a JNDI lookup. -
4. Re: Requesting the EJB container to remove an instance
pmuir Mar 13, 2009 7:06 AM (in response to pmuir)I talked to ALR about this a bit, here is a precis:
"Andrew Rubinger" wrote:
So maybe you can explain a couple things then I'll weigh in? "This needs to be in a portable way"
The standard WB requirement - that WB must operate on other AS than JBoss - we can't have JBoss code in WB itself - if we do need to make a AS specific call we have to do it through the SPI"Andrew Rubinger" wrote:
And you want to invoke upon what object? The proxy from JNDI?
The problem is not that i need to invoke on an EJB but request the EJB container remove it.
Then, we talked about the background:
We need to remove ejbs (e.g. when the coversation context is destroyed), if there is a Session bean proxied instance stored in a context, it get's cleaned up automatically."Andrew Rubinger" wrote:
And you can't call @Remove ?
We can't call @Remove as there might be multiple @Remove methods (which one to we call?) or there might be parameters to the remove method (how do we know what they are)"Andrew Rubinger" wrote:
So you want to remove the backing session, and have no callback upon the SFSB. Which is possible but feels like a real back-door approach...
The @PreDestroy callback should still be executed. In other words, if we did this through bytecode instr, it would be like adding in a @Remove public void wbRemove() {} method
Then, I described a possible SPI Web Beans could use:interface EJBInstance<T> implements Serializable { public void remove(); T getInstance(); }
and an addition to the EJBResolver Web Beans SPI:interface EJBResolver { // ... EJBInstance resolve(String jndiName); }
Where Web Beans would use it like:// initial lookup EJBInstance ejb = ejbResolver.lookup(jndiName); // Some requests go by, JSR299 context needs destroying // destroy ejb.remove();
for example, in JBoss we could implement this like:class JBossEjbInstance<T> implements EjbInstance<T> { Object proxy; String jndiName; JBossEjbInstance(String jndiName) { this.jndiName = jndiName; } private init() { if (proxy == null) { proxy = getInitialContext().lookup(jndiName); if (!(proxy instanceof Serializable)) throw new IllegalStateException(); } } public T getInstance() { init(); return (T) instance; } public void remove() { ((StatefulSessionProxy) instance).remove(); } }
"Andrew Rubinger" wrote:
Why Serializable?
Because the proxy needs e.g. to be serialzied to http session -
5. Re: Requesting the EJB container to remove an instance
alrubinger Mar 13, 2009 9:33 AM (in response to pmuir)I recommended adding onto SessionProxy:
http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/proxy-spi/src/main/java/org/jboss/ejb3/proxy/spi/intf/SessionProxy.java
...to add a "removeTarget()" method. Usage becomes:Object proxy = jndiContext.lookup("MyBean/remote"); SessionProxy sProxy = (SessionProxy)proxy; sProxy.removeTarget();
...which would be No-op for SLSB/Singleton and remove the underlying bean context and session ID from the cache for SFSB.
S,
ALR -
6. Re: Requesting the EJB container to remove an instance
pmuir Mar 14, 2009 12:50 PM (in response to pmuir)I added http://anonsvn.jboss.org/repos/webbeans/ri/trunk/spi/src/main/java/org/jboss/webbeans/ejb/api/EjbReference.java which also adds the create() method for instantiating the EJB. This also includes Ken's recomendation of using the reference to obtain the correct proxy which implements the business interface.
I also wrote a naive implementation for JBoss http://anonsvn.jboss.org/repos/jbossas/projects/webbeans-ri-int/trunk/ejb/src/main/java/org/jboss/webbeans/integration/ejb/JBossEjbReference.java which uses the global local proxy that JBoss EJB3 binds, and holds a reference to the proxy locally to ensure the state is maintained over the lifecycle of the contextual instance.
I would appreciate help with both the remove() method (sounds like we need a new release of JBoss EJB3 for this?) and also ideas on how to better implement the create() and get(). -
7. Re: Requesting the EJB container to remove an instance
pmuir Mar 14, 2009 12:51 PM (in response to pmuir) -
8. Re: Requesting the EJB container to remove an instance
alrubinger Mar 14, 2009 4:49 PM (in response to pmuir)I'll implement "remove()" for us. It'll be dependent upon the new EJB3 release (due out this week).
Your implementation of JBossEjbReference will not work w/ SessionContext.getInvokedBusinessInterface() because it's looking up a non-deterministic proxy. Why did you chooe to go for:this.jndiName = fullJndiName.substring(0, fullJndiName.lastIndexOf("-"));
..?
"create" and "get" look good.
S.
ALR -
9. Re: Requesting the EJB container to remove an instance
alrubinger Mar 14, 2009 4:52 PM (in response to pmuir)On the EJB3 side:
https://jira.jboss.org/jira/browse/EJBTHREE-1773
S,
ALR -
10. Re: Requesting the EJB container to remove an instance
pmuir Mar 14, 2009 8:08 PM (in response to pmuir)"ALRubinger" wrote:
I'll implement "remove()" for us. It'll be dependent upon the new EJB3 release (due out this week).
I thought so. We're starting to have other deps on newer revs of JBoss AS (bug in Javassist proxies) so we'll bounce our minimum up to JBoss AS 5.1.0.CR1 once it's out.Your implementation of JBossEjbReference will not work w/ SessionContext.getInvokedBusinessInterface() because it's looking up a non-deterministic proxy. Why did you chooe to go for:
this.jndiName = fullJndiName.substring(0, fullJndiName.lastIndexOf("-"));
..?
"create" and "get" look good.
Because I'm lazy and wanted to get something roughly working ;-)
I would much prefer to use the deterministic proxy, but couldn't work out the best way to do it - if I created a new jboss.ejb3 EjbReference, I got a different SFSB instance each time.
Really, we need behaviour analagous to SessionContext.getBussinessInterface() here... Any suggestions? -
11. Re: Requesting the EJB container to remove an instance
alrubinger Mar 15, 2009 4:10 AM (in response to pmuir)"ALRubinger" wrote:
https://jira.jboss.org/jira/browse/EJBTHREE-1773
Done. Relevant unit test showing usage is:
http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1773/unit/RemoveRequestFromSessionProxyUnitTestCase.java"ALRubinger" wrote:
I'll implement "remove()" for us.
It's in a patch attached to WBINT-7. I didn't commit it due to the SNAPSHOT dependency upon org.jboss.ejb3:jboss-ejb3-proxy-spi (Don't know if you guys permit SNAPs).
S,
ALR -
12. Re: Requesting the EJB container to remove an instance
pmuir Mar 15, 2009 11:58 AM (in response to pmuir)I would prefer to wait until there is a release, so that we can update the EJB3 impl in JBoss to the correct version using the plugin updater.
Thanks :-)