Dear Sir,
recently I encountered some problems dealing with my resource adapters.
Briefly, here is the scenario: One Message Driven Bean (MDB) calls a stateless EJB. Because the J2EE specifications forbid direct IO access from EJB components, I created a resource adapter called Logger. I retreieve a logger connection in each EJB create function, like this:

LoggerFactoryImpl loggerFactory = (LoggerFactoryImpl)initialContext.lookup("java:/Log");

logger = (Logger)loggerFactory.getLogger(logFileName, level);

logger.log(CLASS_NAME, Log.TRACE4, methodName, "Bean successfully started");

The resource adapter uses a NoTXConnectionManager. Inside stateless EJBs, I retrieve connections to distributted transactional XA resources :

com.ra.Resource.ConnectionFactoryImpl resourceFactory = (com.ra.Resource.ConnectionFactoryImpl)initialContext.lookup("java:/Resource1");

resource1Connection = resourceFactory.getConnection();

The XA resources are closed in the same method, while the Logger resource handlers are kept open and closed on ejbRemove()

The XA resources are committed OK, but I have problems trying to use the Logger non-transactional resource. The exception I've got looks like this:

10:51:46,093 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
java.lang.IllegalArgumentException: disconnect(ManagedConnection mc: null, Object c: com.ra.Log.Logger@97d3f0) called with unknown managed connection
        at org.jboss.resource.connectionmanager.BaseConnectionManager2.unregisterAssociation(BaseConnectionManager2.java:640)
        at org.jboss.resource.connectionmanager.BaseConnectionManager2.disconnect(BaseConnectionManager2.java:598)
        at org.jboss.resource.connectionmanager.CachedConnectionManager.disconnect(CachedConnectionManager.java:372)
        at org.jboss.resource.connectionmanager.CachedConnectionManager.popMetaAwareObject(CachedConnectionManager.java:151)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:190)
        at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:88)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:142)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
        at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:100)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
        at org.jboss.ejb.MessageDrivenContainer.invoke(MessageDrivenContainer.java:302)
        at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvoker.java:625)
        at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onMessage(JMSContainerInvoker.java:973)
        at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:234)
        at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:561)
        at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:377)
        at org.jboss.mq.SpySession.run(SpySession.java:252)
        at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:173)
        at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:642)
        at java.lang.Thread.run(Thread.java:536)
10:51:46,107 ERROR [JMSContainerInvoker] Exception in JMSCI message listener
javax.transaction.TransactionRolledbackException: disconnect(ManagedConnection mc: null, Object c: com.ra.Log.Logger@97d3f0) called with unknown managed connection; nested exception is:
        java.lang.IllegalArgumentException: disconnect(ManagedConnection mc: null, Object c: com.ra.Log.Logger@97d3f0) called with unknown managed connection
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:122)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:142)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
        at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:100)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
        at org.jboss.ejb.MessageDrivenContainer.invoke(MessageDrivenContainer.java:302)
        at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvoker.java:625)
        at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onMessage(JMSContainerInvoker.java:973)
        at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:234)
        at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:561)
        at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:377)
        at org.jboss.mq.SpySession.run(SpySession.java:252)
        at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:173)
        at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:642)
        at java.lang.Thread.run(Thread.java:536)
Caused by: java.lang.IllegalArgumentException: disconnect(ManagedConnection mc: null, Object c: com.ra.Log.Logger@97d3f0) called with unknown managed connection
        at org.jboss.resource.connectionmanager.BaseConnectionManager2.unregisterAssociation(BaseConnectionManager2.java:640)
        at org.jboss.resource.connectionmanager.BaseConnectionManager2.disconnect(BaseConnectionManager2.java:598)
        at org.jboss.resource.connectionmanager.CachedConnectionManager.disconnect(CachedConnectionManager.java:372)
        at org.jboss.resource.connectionmanager.CachedConnectionManager.popMetaAwareObject(CachedConnectionManager.java:151)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:190)
        at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:88)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
        ... 14 more

Digging through the org.jboss.resource.connectionmanager sources, here is what I found:

The invoke() method will push the meta-aware object on the stack, then will execute the method and then will make a pop from the stack. When the MDBean calls the EJB, the ejbCreate() method is called first. In the create method, I make a lookup() for a Logger connection. Once found, this connection is sent to CachedConnectionManager for registration (method registerConnection). Here is the error: because the invoke and push haven't been called yet, the CachedConnectionManager stack indicator is set to MDBean. Thus, the method peekMetaAwareObject() will return the MDBean key instead of the stateless EJB key and my logger is registered under MDBean. Again, this is valid only when the logger is created in the create() method. Am I correct in my assumption? If so, is there any chance to correct this problem in a future release, or do I have to move my logger lookup from the ejbCreate() method?

I realize the error stack trace is a little dizzy so , if you need the entire output (I added some debug informations in CachedConnectionManager and BaseConnectionManager2), please let me know.

 

Thanks for all your support, David

Radu

 

Reply via email to