2 Replies Latest reply on Sep 4, 2009 6:39 AM by Jason Marshall

    JCA Problem: java.lang.IllegalStateException: Trying to retu

    Christian Groove Newbie

      Dear Sirs,

      i am developping my very first outbound connector and have
      still a litte problem on closing my connection handle.
      Aquireing and use of connection from a pool does work
      without any problem. Closing the connection from a
      session acutally cause a problem.

      I guess i have overseen something.

      The runtime environment:
      Operating-System: Fedora-11 Linux
      JAVA: Java version: 1.6.0_0,Sun Microsystems Inc.
      Java VM: OpenJDK Server VM 14.0-b15,Sun Microsystems Inc.
      (shipped with this Linux-OS)
      Jboss: 4.2.3.GA


      Here is the stack-trace from the closing-thread:
      ------------------------------------------------

      06:59:17,744 INFO [NoTxConnectionManager] Throwable from unregisterConnection
      java.lang.IllegalStateException: Trying to return an unknown connection2! null
      at org.jboss.resource.connectionmanager.CachedConnectionManager.unregisterConnection(CachedConnectionManager.java:342)
      at org.jboss.resource.connectionmanager.NoTxConnectionManager$NoTxConnectionEventListener.connectionClosed(NoTxConnectionManager.java:88)
      at de.dialog_leben.bfs.risikopruefung.connector.normrisk.resource.ManagedNrConnection.closeHandle(ManagedNrConnection.java:280)
      at de.dialog_leben.bfs.risikopruefung.connector.normrisk.resource.NormRiskConnectionImpl.close(NormRiskConnectionImpl.java:30)
      at de.dialog_leben.bfs.risikopruefung.business.test.normrisk.NRConnectorTest.testSimpleAccess(NRConnectorTest.java:89)
      at de.dialog_leben.bfs.risikopruefung.ejb.NormRiskTestAccessServiceBean.testSimpleAccess(NormRiskTestAccessServiceBean.java:42)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      (....)

      Here is the stack-trace from the registering-thread:
      ----------------------------------------------------
      07:08:14,445 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: de.dialog_leben.bfs.risikopruefung.connector.normrisk.resource.NormRiskConnectionImpl@dce075
      java.lang.Throwable: STACKTRACE
      at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:423)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:849)
      at de.dialog_leben.bfs.risikopruefung.connector.normrisk.driver.NormRiskConnectionFactoryImpl.getConnection(NormRiskConnectionFactoryImpl.java:87)
      at de.dialog_leben.bfs.risikopruefung.connector.normrisk.driver.NormRiskConnectionFactoryImpl.getConnection(NormRiskConnectionFactoryImpl.java:76)
      at de.dialog_leben.bfs.risikopruefung.business.test.normrisk.NRConnectorTest.testSimpleAccess(NRConnectorTest.java:82)
      at de.dialog_leben.bfs.risikopruefung.ejb.NormRiskTestAccessServiceBean.testSimpleAccess(NormRiskTestAccessServiceBean.java:42)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)


      In order to understand what's going wrong i downloaded JBoss-sourcecode
      and followed the debugger. I located the problem in the nested class/method:
      org.jboss.resource.connectionmanager.NoTxConnectionManager.NoTxConnectionManager/connectionClosed

      ce.getConnectionHandle());
      }

      The ce.getConnectionHandle() expression returns null, that seems to cause the problem.
      Therefore i think that i forgot to assign a connectionHandle in my ManagedConnection, cause
      ce referes to

      ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED) ;

      where this referes to my managed connection and ce Event was created in the
      managedConnection method closeHandle.

      Thank you for your help,
      Groovy

        • 1. Re: JCA Problem: java.lang.IllegalStateException: Trying to
          Christian Groove Newbie

          Salut mc's,

          the solution is quite simple. The (logical) close operation,
          that issues a closeSend of the ConnectionEvent class
          has to attach the connection handle to the ConnectionEvent,
          before broadcasting this event.

          so:
          ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED) ;
          (new) ce.setConnectionHandle(connection) ;

          does help me in the closeHandle method.

          Tanks
          Groovie

          • 2. Re: JCA Problem: java.lang.IllegalStateException: Trying to
            Jason Marshall Newbie

            Hi Thanks for the solution - that worked for me!
            Just for clarification to other readers that are new to JCA, the ConnectionHandle is the connection that your ConnectionFactory returns to the client component. So if you have implemented a common client interface for your resource adapter then your connection handle is the class that implemets javax.resource.cci.Connection.

            Normally your client connection would have a close event, which it delegates to the underlying managedConnection, passing a reference of itself to the managed connection, which it adds to the closed event before it fires it to its' listenteners.

            This lets Jboss which client connection it needs to release the managed connection from before returning it to the pool.

            I hope that adds some clarification.