6 Replies Latest reply on May 8, 2002 8:39 AM by eguib

    JBoss3RC2: associations between connectionhandle and mc.

    vad

      Hi David,

      I'm testing now RC2, and I found a behavior I never had before : my managed connection is associated to more than one connectionhandle (via the reconnect() of CacheConnectionManager).As i remember, it is spec compliant.

      In my code i throw an exception if this occurs, but of course I expect that a mc is only associated to one connection handle at a time. If not, I would have to synchronize my mc, which I thought was the role of the appserver.

      Any advice?

      vad

        • 1. Re: JBoss3RC2: associations between connectionhandle and mc.
          davidjencks

          Could you give me some more info on what you are doing?

          The spec indicates all adapters must support ManagedConnection.associateConnection(); the xa wrapper still doesn't, which makes it hard to use with BMP.

          I don't know of any circumstances in which jboss could let your app use a managed connection from more than one thread simultaneously.

          The local tx connection managers (old and new) have always been able to get many handles from a managed connection, since the same mc must be used for every connection handle in a simgle transaction. What has changed is that the new cm releases the mc when control leaves the ejb (either calling another ejb or holding a handle over a method boundary). Releasing the handle has little effect for a local tx adapter, since the mc has to be reserved untill the end of the tx, but allows a mc to be reused immediately for an xa or no-tx adapter.

          • 2. Re: JBoss3RC2: associations between connectionhandle and mc.
            vad

            My resource adapter is non-transactional driver to CORBA servers. My mc wrap an instance of a CORBA object.

            here is how I implemented the relation between connection handle and mc :

            a ch is instanciated with a pointer to a mc and keeps it. The close() method of the ch just calls release() on its mc, where release() is a method of mine which fires ConnectionEvent.CONNECTION_CLOSED.

            On the mc side :

            ...
            protected Object handle = null ;
            protected Object handleLock = new Object() ;
            ...

            public void cleanup() throws javax.resource.ResourceException {
            synchronized (handleLock) {
            handle = null ;
            }
            }

            public void associateConnection(Object connectionHandle) throws ResourceException {
            synchronized (handleLock) {
            if (handle != null) {
            throw new javax.resource.spi.IllegalStateException("managedConnection already bound to one connection handle") ;
            }
            handle = connectionHandle ;
            }
            }

            //called by Connection Handle
            public void release() {
            fireConnectionEvent(new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED)) ;
            }


            If, as you say, the appserver guarantees that only one thread uses the mc at a time, it could be OK to have several ch on the same mc, I just would need
            to keep a stack of ch associated with my mc and close the mc only when the stack reaches 0.

            However a problem could occur : a first client gets a ch and makes a blocking remote corba call via the mc; a second client uses the same mc to make another remote call (with the very same stub...):
            I'm not sure of the behavior of my corba implementation (Iona/Orbix 3) but I fear either the second call will wait for the first to complete (defeating the purpose of pooling),
            or worse the responses could be messed...


            Do you think I'm misunderstanding things?


            • 3. Re: JBoss3RC2: associations between connectionhandle and mc.
              davidjencks

              I'm assuming what is happening is that associateConnection is being called when the handle is not null: thus we can assume cleanup was not called previously.

              My first reaction is that there must be a bug in the NoTxConnectionManager. With NoTxConnectionManager the managed connection should be cleaned up and re-pooled whenever control leaves an ejb. Cleanup should always be called before associateConnection.

              Just to make sure the problem isn't elsewhere, are all the connection handles obtained in ejbs?

              Thanks

              • 4. Re: JBoss3RC2: associations between connectionhandle and mc.
                vad

                Hi David,

                I can't reproduce the problem of bad association for the moment, because I have other probems:

                1°) I call my connector from ejbs and from inside my connector.

                From inside my CORBA connector, I call my JMS connector : after a few messages are sent, I get a resourceException: No ManagedConnections Available!
                it seems that those connections requested inside a connector are not returned to the pool.


                2°) I found that cleanup() is called twice (should not be a problem for me, but..), as you can see on this trace :

                10:22:48,940 TRACE [org.jboss.resource.connectionmanager.CachedConnectionManager] new stack for key: MyMessageDrivenBean@781402
                10:22:48,940 TRACE [org.jboss.resource.connectionmanager.RARDeployment] RARDeployment.getObjectInstance, name = 'test'
                10:22:48,940 TRACE [org.jboss.resource.connectionmanager.NoTxConnectionManager] subject: null
                10:22:48,940 DEBUG [org.jboss.resource.connectionmanager.IdleRemover] internalRegisterPool: registering pool with interval 900000 old interval: 450000
                10:22:48,940 INFO [myconnector.test] MyManagedConnectionFactory createManagedConnection
                10:22:48,940 TRACE [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] returning new ManagedConnection
                10:22:48,940 TRACE [org.jboss.resource.connectionmanager.NoTxConnectionManager] registering ConnectionEventListener for ManagedConnection: com.bnpparibas.eqd.barracuda.order.connector.force.ite2.Force2TraderManagedConnection@6dd9b3
                10:22:48,960 TRACE [org.jboss.resource.connectionmanager.CachedConnectionManager] registering connection from org.jboss.resource.connectionmanager.NoTxConnectionManager@14d18f, connection record: org.jboss.resource.connectionmanager.ConnectionRecord@4a1a68, key: MyMessageDrivenBean@781402
                10:22:48,990 INFO [myconnector] CORBA CALL time = 10
                10:22:49,000 TRACE [org.jboss.resource.connectionmanager.CachedConnectionManager] unregistering connection from org.jboss.resource.connectionmanager.NoTxConnectionManager@14d18f, object: null, key: MyMessageDrivenBean@781402
                10:22:49,000 TRACE [org.jboss.resource.connectionmanager.NoTxConnectionManager] unregisterConnection: 0
                10:22:49,000 INFO [myconnector.test_connection_1] cleanup
                10:22:49,000 TRACE [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] putting ManagedConnection back into pool
                10:22:49,000 INFO [myconnector.test_connection_1] cleanup



                3°) This one, I don't understand it : although it seems to be a problem of MDB container, as you can see the connectionmanager is involved :
                The onMessage() of my bean isn't even invoked.

                2002-05-07 11:04:38,208 INFO [MyMessageDrivenBean] Mybean ejbcreate
                2002-05-07 11:04:41,162 ERROR [org.jboss.ejb.plugins.jms.JMSContainerInvoker] Exception in JMSCI message listener
                javax.resource.ResourceException: No ManagedConnections Available!
                at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:122)
                at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:312)
                at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:433)
                at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnect(BaseConnectionManager2.java:545)
                at org.jboss.resource.connectionmanager.CachedConnectionManager.reconnect(CachedConnectionManager.java:332)
                at org.jboss.resource.connectionmanager.CachedConnectionManager.pushMetaAwareObject(CachedConnectionManager.java:135)
                at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:144)
                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:167)
                at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
                at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
                at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
                at org.jboss.ejb.MessageDrivenContainer.invoke(MessageDrivenContainer.java:308)
                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 myprovider.JMSSession.run(JMSSession.java:98)
                at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:175)
                at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:642)
                at java.lang.Thread.run(Thread.java:484)

                Thanks for your time!

                Vad
                (PS: I'm on holidays for the next few days)

                • 5. Re: JBoss3RC2: associations between connectionhandle and mc.
                  davidjencks

                  I've never thought about the possibility of calling a connector from inside a connector. Is there any chance you could send me some code indicating what you are doing?

                  davidjencks@directvinternet.com

                  • 6. Re: JBoss3RC2: associations between connectionhandle and mc.
                    eguib

                    vad

                    I'm also working with the NoTxConnectionManager and found that the current cvs release is working good. I did have similar problems (associateConnection called while another connection was there) and also in some situations my pool got empty (Connections were not returned to the pool).

                    The problem was with my connector implementation and as far as I can see this might be a problem with yours too.

                    > //called by Connection Handle
                    > public void release() {
                    > fireConnectionEvent(new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED)) ;
                    > }

                    You have to set not only the ManagedConnection in the event, but also the connectionHandle.
                    The NoTxConnectionEventListener.connectionClosed(ConnectionEvent ce) method is passing the connectionHandle to the CachedConnectionManager.unregisterConnection(...) and to unregisterConnection(...).

                    You could try this:

                    //called by Connection Handle
                    public void release() {
                    ConnectionEvent e = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
                    e.setConnectionHandle(handle);
                    fireConnectionEvent(e);
                    }

                    I also forgot to set the connectionhandle ... since I made change it works just perfect. According to the tests I made, I did not see the associateConnection(..) called any more (I'm using the connector from SFSB, and local SLSB).

                    Erwin