1 Reply Latest reply on Jul 20, 2002 9:54 PM by davidjencks

    Problem in CachedConnectionManager in JBOSS

    guru

      Hi,

      I have written an JCA adapter for an EIS and deplyed it successfully in JBOSS.

      i also wrote a sessionbean(stateful) to acess the adapter.

      Even though the bean is deployed successfuly, i had problem interacting with the EIS.

      The problem is in res-sharing-scope tag in ejb-jar.xml
      if i say <res-sharing-scope>Unshareable<res-sharing-scope>
      it works fine. i mean able to interact and get connection to the EIS.

      but,
      if i put<res-sharing-scope>Shareable<res-sharing-scope>
      im getting exception saying not able to "Activate Bean, nested exception is ...." Activation failure

      Error Trace
      -------------------------------------------------------
      java.rmi.ServerException: Could not activate; nested exception is:
      java.io.FileNotFoundException: E:\jboss-3.0.0\server\default\db\sessions
      \com.vergil.bean.BAPI_COMPANYCODE_GETLIST_Bean\1026817330562.ser (The system can
      not find the file specified)
      java.io.FileNotFoundException: E:\jboss-3.0.0\server\default\db\sessions\com.ver
      gil.bean.BAPI_COMPANYCODE_GETLIST_Bean\1026817330562.ser (The system cannot find
      the file specified)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.(FileInputStream.java:64)
      at java.io.FileInputStream.(FileInputStream.java:95)
      at org.jboss.ejb.plugins.StatefulSessionFilePersistenceManager.activateS
      ession(StatefulSessionFilePersistenceManager.java:222)
      at org.jboss.ejb.plugins.StatefulSessionInstanceCache.activate(StatefulS
      essionInstanceCache.java:83)
      at org.jboss.ejb.plugins.AbstractInstanceCache.get(AbstractInstanceCache
      .java:177)
      at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(State
      fulSessionInstanceInterceptor.java:212)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:167)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
      1)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.StatefulSessionContainer.invoke(StatefulSessionContaine
      r.java:380)
      at org.jboss.ejb.Container.invoke(Container.java:705)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.jav
      a:102)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.
      java:73)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:7
      6)
      at org.jboss.proxy.ejb.StatefulSessionInterceptor.invoke(StatefulSession
      Interceptor.java:117)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
      at $Proxy22.disconnect(Unknown Source)
      at org.apache.jsp.BAPI_0005fCOMPANYCODE_0005fGETLIST$jsp._jspService(BAP
      I_0005fCOMPANYCODE_0005fGETLIST$jsp.java:180)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
      vlet.java:201)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
      81)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:371
      )
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:6
      07)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1387)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1326)
      at org.mortbay.http.HttpServer.service(HttpServer.java:757)
      at org.jboss.jetty.Jetty.service(Jetty.java:527)
      at org.mortbay.http.HttpConnection.service(HttpConnection.java:742)
      at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:915)
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:757)
      at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
      151)
      at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287)
      at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:715)
      at java.lang.Thread.run(Thread.java:484)
      16:32:37,062 INFO [STDOUT] 53641 [SocketListener-0] ERROR org.jboss.ejb.plugins
      .AbstractInstanceCache com.vergil.bean.BAPI_COMPANYCODE_GETLIST_Bean - Activatio
      n failure
      ---------------------------------------------------------

      in client side im getting error as :
      ---------------------------------------------------
      HTTP ERROR: 500 Could not activate; nested exception is: java.io.FileNotFoundException: E:\jboss-3.0.0\server\default\db\sessions\com.vergil.bean.BAPI_COMPANYCODE_GETLIST_Bean\1026817330562.ser (The system cannot find the file specified)
      ----------------------------------------------------

      When i looked at the JBOSS Forum davidjencks has given some solution for this
      commenting two lines in "CachedConnectionManager.java"

      But commenting even that two lines doesn't work. So i commented the lines that calls
      reconnect and disconnect method in the pushMetaAwareObject and popMetaAwareObject method.

      So now it works fine no matter wht the res-sharing-scope is .. (shareable or unshareable)

      i wud like to know whther these change i made is correct and also that this change will not have any side effects for other applications.

      Kindly post the comments on this question.

      thanks,
      Gurumurthy R.

      //"CachedConnectionManager.java"
      //========================================================

      // Source File Name: CachedConnectionManager.java

      package org.jboss.resource.connectionmanager;

      import java.util.*;
      import javax.resource.ResourceException;
      import javax.transaction.SystemException;
      import org.jboss.logging.Logger;
      import org.jboss.system.ServiceMBeanSupport;
      import org.jboss.tm.usertx.client.ServerVMClientUserTransaction;

      // Referenced classes of package org.jboss.resource.connectionmanager:
      // ConnectionRecord, ConnectionCacheListener, CachedConnectionManagerMBean

      public class CachedConnectionManager extends ServiceMBeanSupport
      implements org.jboss.tm.usertx.client.ServerVMClientUserTransaction.UserTransactionStartedListener, CachedConnectionManagerMBean
      {

      public CachedConnectionManager()
      {
      }

      public CachedConnectionManager getInstance()
      {
      return this;
      }

      protected void startService()
      throws Exception
      {
      ServerVMClientUserTransaction.getSingleton().registerTxStartedListener(this);
      }

      protected void stopService()
      throws Exception
      {
      ServerVMClientUserTransaction.getSingleton().unregisterTxStartedListener(this);
      }

      public void pushMetaAwareObject(Object key, Set unsharableResources)
      throws ResourceException
      {
      LinkedList stack = (LinkedList)currentObjects.get();
      if(stack == null)
      {
      if(log.isTraceEnabled())
      log.trace("new stack for key: " + key);
      stack = new LinkedList();
      currentObjects.set(stack);
      } else
      {
      if(log.isTraceEnabled())
      log.trace("old stack for key: " + key);
      if(!stack.isEmpty())
      {
      Object oldKey = stack.getLast();
      System.out.println("########################1 pushMetaAwareObject : disconnect = " + oldKey);
      //disconnect(oldKey, unsharableResources);
      }
      }
      stack.addLast(key);
      System.out.println("########################2 pushMetaAwareObject : reconnect = " + key);
      //reconnect(key, unsharableResources);
      }

      public void popMetaAwareObject(Set unsharableResources)
      throws ResourceException
      {
      LinkedList stack = (LinkedList)currentObjects.get();
      Object oldKey = stack.removeLast();
      if(log.isTraceEnabled())
      log.trace("popped object: " + oldKey);
      System.out.println("########################1 popMetaAwareObject : disconnect = " + oldKey);
      //disconnect(oldKey, unsharableResources);
      if(!stack.isEmpty())
      {
      Object key = stack.getLast();
      System.out.println("########################2 popMetaAwareObject : reconnect = " + key);
      //reconnect(key, unsharableResources);
      }
      }

      Object peekMetaAwareObject()
      {
      LinkedList stack = (LinkedList)currentObjects.get();
      if(stack == null)
      return null;
      if(!stack.isEmpty())
      return stack.getLast();
      else
      return null;
      }

      void registerConnection(ConnectionCacheListener cm, ConnectionRecord cr)
      {
      Object key = peekMetaAwareObject();
      if(log.isTraceEnabled())
      log.trace("registering connection from " + cm + ", connection record: " + cr + ", key: " + key);
      if(key == null)
      return;
      Map cmToConnectionsMap = null;
      synchronized(objectToConnectionManagerMap)
      {
      cmToConnectionsMap = (Map)objectToConnectionManagerMap.get(key);
      if(cmToConnectionsMap == null)
      {
      cmToConnectionsMap = new HashMap();
      objectToConnectionManagerMap.put(key, cmToConnectionsMap);
      }
      }
      synchronized(cmToConnectionsMap)
      {
      Collection conns = (Collection)cmToConnectionsMap.get(cm);
      if(conns == null)
      {
      conns = new ArrayList();
      cmToConnectionsMap.put(cm, conns);
      }
      conns.add(cr);
      }
      }

      void unregisterConnection(ConnectionCacheListener cm, Object c)
      {
      Object key = peekMetaAwareObject();
      if(log.isTraceEnabled())
      log.trace("unregistering connection from " + cm + ", object: " + c + ", key: " + key);
      if(key == null)
      return;
      Map cmToConnectionsMap = null;
      synchronized(objectToConnectionManagerMap)
      {
      cmToConnectionsMap = (Map)objectToConnectionManagerMap.get(key);
      if(cmToConnectionsMap == null)
      return;
      }
      synchronized(cmToConnectionsMap)
      {
      Collection conns = (Collection)cmToConnectionsMap.get(cm);
      if(conns == null)
      return;
      for(Iterator i = conns.iterator(); i.hasNext();)
      if(((ConnectionRecord)i.next()).connection == c)
      {
      i.remove();
      if(conns.size() == 0)
      {
      cmToConnectionsMap.remove(cm);
      if(cmToConnectionsMap.size() == 0)
      synchronized(objectToConnectionManagerMap)
      {
      objectToConnectionManagerMap.remove(key);
      }
      }
      return;
      }

      }
      }

      public void userTransactionStarted()
      throws SystemException
      {
      Object key = peekMetaAwareObject();
      if(log.isTraceEnabled())
      log.trace("user tx started, key: " + key);
      if(key == null)
      return;
      Map cmToConnectionsMap = null;
      synchronized(objectToConnectionManagerMap)
      {
      cmToConnectionsMap = (Map)objectToConnectionManagerMap.get(key);
      if(cmToConnectionsMap == null)
      return;
      }
      synchronized(cmToConnectionsMap)
      {
      ConnectionCacheListener cm;
      Collection conns;
      for(Iterator i = cmToConnectionsMap.keySet().iterator(); i.hasNext(); cm.transactionStarted(conns))
      {
      cm = (ConnectionCacheListener)i.next();
      conns = (Collection)cmToConnectionsMap.get(cm);
      }

      }
      }

      private void reconnect(Object key, Set unsharableResources)
      throws ResourceException
      {
      Map cmToConnectionsMap = null;
      synchronized(objectToConnectionManagerMap)
      {
      cmToConnectionsMap = (Map)objectToConnectionManagerMap.get(key);
      if(cmToConnectionsMap == null)
      return;
      }
      synchronized(cmToConnectionsMap)
      {
      ConnectionCacheListener cm;
      Collection conns;
      for(Iterator i = cmToConnectionsMap.keySet().iterator(); i.hasNext(); cm.reconnect(conns, unsharableResources))
      {
      cm = (ConnectionCacheListener)i.next();
      conns = (Collection)cmToConnectionsMap.get(cm);
      }

      }
      }

      private void disconnect(Object key, Set unsharableResources)
      throws ResourceException
      {
      Map cmToConnectionsMap = null;
      synchronized(objectToConnectionManagerMap)
      {
      cmToConnectionsMap = (Map)objectToConnectionManagerMap.get(key);
      if(cmToConnectionsMap == null)
      return;
      }
      synchronized(cmToConnectionsMap)
      {
      ConnectionCacheListener cm;
      Collection conns;
      for(Iterator i = cmToConnectionsMap.keySet().iterator(); i.hasNext(); cm.disconnect(conns, unsharableResources))
      {
      cm = (ConnectionCacheListener)i.next();
      conns = (Collection)cmToConnectionsMap.get(cm);
      }

      }
      }

      void unregisterConnectionCacheListener(ConnectionCacheListener cm)
      {
      if(log.isTraceEnabled())
      log.trace("unregisterConnectionCacheListener: " + cm);
      synchronized(objectToConnectionManagerMap)
      {
      for(Iterator i = objectToConnectionManagerMap.values().iterator(); i.hasNext();)
      {
      Map cmToConnectionsMap = (Map)i.next();
      if(cmToConnectionsMap != null)
      cmToConnectionsMap.remove(cm);
      }

      }
      }

      private final ThreadLocal currentObjects = new ThreadLocal();
      private final Map objectToConnectionManagerMap = new HashMap();
      protected final Logger log = Logger.getLogger(getClass());
      }


      =========================================================

        • 1. Re: Problem in CachedConnectionManager in JBOSS
          davidjencks

          Do you cache a connection handle over method invocations in your code? if not, the calls you have commented out should do nothing.

          Does your adapter allow the following sequence of calls on managed connections mc1 and mc2 and connection handle c?

          mc1.associateConnection(c);
          mc1.cleanup();
          mc2.associateConnection(c);

          The jca 1.0 spec is unclear about whether this sequence of calls is allowed.