5 Replies Latest reply on Feb 20, 2008 10:31 AM by adrian.brock

    issues with JCA minimum connections

    tvbinh

      Hi,

      I am developing an in-house resource adapter for both inbound and outbound communications. I have specified <min-pool-size>2</min-pool-size> in the -ds.xml but it seems do not work properly. The fillToMin method of InternalManagedConnectionPool class in JBoss does attempt to create 2 connections but it does not pass the connection request information in so the 2 connections created are not much useful since it is connected to nowhere. I am not sure whether this is a bug, could someone please help ?

      Best regards,

      Binh

      - defaultCri is null at the time fillToMin is executed.
      public void fillToMin()
      {
      while (true)
      {
      // Get a permit - avoids a race when the pool is nearly full
      // Also avoids unnessary fill checking when all connections are checked out
      try
      {
      if (permits.attempt(poolParams.blockingTimeout))
      {
      try
      {
      if (shutdown.get())
      return;

      // We already have enough connections
      if (getMinSize() - connectionCounter.getGuaranteedCount() <= 0)
      return;

      // Create a connection to fill the pool
      try
      {
      ConnectionListener cl = createConnectionEventListener(defaultSubject, defaultCri);
      synchronized (cls)
      {
      if (trace)
      log.trace("Filling pool cl=" + cl);
      cls.add(cl);
      }
      }
      catch (ResourceException re)
      {
      log.warn("Unable to fill pool ", re);
      return;
      }
      }
      finally
      {
      permits.release();
      }
      }
      }
      catch (InterruptedException ignored)
      {
      log.trace("Interrupted while requesting permit in fillToMin");
      }
      }
      }

        • 1. Re: issues with JCA minimum connections
          vickyk

          Couple of things we need to check

          1) How are you getting the Connection Handle from the ConnectionFactory ? Are you passing the CRI details to the Connection Handle through the application code?
          eg

          DemoConnectionFactory cf = (DemoConnectionFactory)ctx.lookup("<JNDINAME>");
          DemoConnectionHandle connection = cf.getConnection(parameter1, parameter2,......) ;
          
          where getConnection(parameter1,parameter2,.....) contains the parameter which are used by ConnectionHandle implementation to generate the CRI object which is later passed to the ConnecitonManager Pool.

          2) Verify if the <connectionfactory-impl-class> implementation are passsing the ConnectionRequestInfo appropriately when asked to .
          Look at the jdbc resource adapter implemetaion of the connectionfactory-impl-class here
          http://anonsvn.jboss.org/repos/jbossas/trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java
          See how the WrappedConnectionRequestInfo is created in it and passed to ConnectionManager in it
          public Connection getConnection(String user, String password) throws SQLException
           {
           ConnectionRequestInfo cri = new WrappedConnectionRequestInfo(user, password);
           try
           {
           WrappedConnection wc = (WrappedConnection) cm.allocateConnection(mcf, cri);
           wc.setDataSource(this);
           return wc;
           }
           catch (ResourceException re)
           {
           throw new NestedSQLException(re);
           }
           }



          • 2. Re: issues with JCA minimum connections
            tvbinh

            Hi Vicky,

            Thank you very much for your help,

            1) How are you getting the Connection Handle from the ConnectionFactory ? Are you passing the CRI details to the Connection Handle through the application code?


            No, I declare all the properties in -ds.xml file e.g. and JBoss will read those. I prefer this way to hard coding properties into the codes. Below is the content of my -ds.xml

            sampleds.xml

            <connection-factories>
             <no-tx-connection-factory>
             <jndi-name>SimplewireDS</jndi-name>
             <rar-name>65-mitto-ra-smpp.rar</rar-name>
             <connection-definition>
             com.smsc.mitto.ra.smpp.SMPPConnectionFactory
             </connection-definition>
             <config-property name="Name" type="java.lang.String">Mitto-1</config-property>
             <config-property name="Server" type="java.lang.String">192.168.2.115</config-property>
             <config-property name="Port" type="java.lang.Integer">9999</config-property>
             <config-property name="Username" type="java.lang.String">binh</config-property>
             <config-property name="Password" type="java.lang.String">binh</config-property>
             <min-pool-size>0</min-pool-size>
             <max-pool-size>4</max-pool-size>
             <idle-timeout-minutes>525600</idle-timeout-minutes> <!-- if idle for a year reconnect... -->
             <blocking-timeout-millis>100</blocking-timeout-millis>
             <prefill>true</prefill>
             </no-tx-connection-factory>
            </connection-factories>


            The properties are loaded in my <managed-connection-factory> class

            public Object createConnectionFactory(ConnectionManager connectionManager)
             throws ResourceException {
             logger
             .info("Creating connection factory (with specified connectionmanager) in TelnetManagedConnectionfactory with id="
             + id);
            
             // At this stage the values from the configuration file should have been
             // set
             if (server != null && port != 0 && username != null && password != null
             && name != null) {
             SMPPRequestInfo smppInfo;
            
             smppInfo = new SMPPRequestInfo(username, password, server, port,
             name);
             return new SMPPConnectionFactoryImpl(connectionManager, this,
             smppInfo);
             } else
             throw new ResourceException();
             }
            
             public void setUsername(String username) {
             this.username = username;
             }
            
             public void setPassword(String password) {
             this.password = password;
             }
            
             public void setServer(String server) {
             this.server = server;
             }
            
             public void setPort(Integer port) {
             this.port = port;
             }
            
             public void setName(String name) {
             this.name = name;
             }
            

            2/ Verify if the <connectionfactory-impl-class> implementation are passsing the ConnectionRequestInfo appropriately when asked to .
            Look at the jdbc resource adapter implemetaion of the connectionfactory-impl-class here

            Since I declare all the properties in -ds.xml, I would probably not need to pass the ConnectionRequestInfo in my <connection-factory-impl> class. Here is the codes:
             public SMPPConnection getConnection() throws NamingException {
             logger
             .info("Request an SMPPConnection from the SMPPConnectionFactoryImpl with id="
             + id);
             SMPPConnectionImpl tc = null;
             try {
             tc = (SMPPConnectionImpl) manager.allocateConnection(factory,
             smppInfo);
             return tc;
             } catch (ResourceException ex) {
             // doing something
             }
             }
            


            • 3. Re: issues with JCA minimum connections
              vickyk

               

              try {
               tc = (SMPPConnectionImpl) manager.allocateConnection(factory,
               smppInfo);
               return tc;
               } catch (ResourceException ex) {
               // doing something

              Put the log statement and see if the smppInfo does contain the values which you are passing from the the -ds.xml file .
              If the log shows the values then it looks ok and you need to put some debugging in the org.jboss.resource to see where the CRI info is lost .


              • 4. Re: issues with JCA minimum connections
                tvbinh

                Hi Vicky,

                I don't have any problem with my <connection-factory-impl> class. It works nicely, I got all the properties that I want.

                The problem is with JBoss loading the number of minimum connections as declared in -ds.xml file

                <connection-factories>
                 <no-tx-connection-factory>
                 <jndi-name>SimplewireDS</jndi-name>
                 <rar-name>65-mitto-ra-smpp.rar</rar-name>
                 <connection-definition>
                 com.smsc.mitto.ra.smpp.SMPPConnectionFactory
                 </connection-definition>
                 <config-property name="Name" type="java.lang.String">Mitto-1</config-property>
                 <config-property name="Server" type="java.lang.String">192.168.2.115</config-property>
                 <config-property name="Port" type="java.lang.Integer">9999</config-property>
                 <config-property name="Username" type="java.lang.String">binh</config-property>
                 <config-property name="Password" type="java.lang.String">binh</config-property>
                 <min-pool-size>2</min-pool-size>
                 <max-pool-size>4</max-pool-size>
                 <idle-timeout-minutes>525600</idle-timeout-minutes> <!-- if idle for a year reconnect... -->
                 <blocking-timeout-millis>100</blocking-timeout-millis>
                 <prefill>true</prefill>
                 </no-tx-connection-factory>
                </connection-factories>


                With the above xml, I expect JBoss to automatically create 2 fully functional connections to 192.168.2.115 for me using other connection request infor provided. Though, when I try to use these 2 connections, I always got null pointer exception.

                I debuged through JBoss codes and found that JBoss does not make use of the connection request information also declared in the -ds.xml like server, port, username, password etc, when it tries to create connections to satisfy this minumum connection properties (it does load the property in) .... The problem lies in the fillToMin method of InternalManagedConnectionPool class of JBoss, where it uses null for ConnectionRequestInfo when trying to make the connections. Could you please check that for me ?

                Thank you very much for your help,

                Best regards,

                Binh

                ----------
                defaultCRI is null in the below codes
                public void fillToMin() {
                 while (true) {
                 // Get a permit - avoids a race when the pool is nearly full
                 // Also avoids unnessary fill checking when all connections are
                 // checked out
                 try {
                 if (permits.attempt(poolParams.blockingTimeout)) {
                 try {
                 if (shutdown.get())
                 return;
                
                 // We already have enough connections
                 if (getMinSize()
                 - connectionCounter.getGuaranteedCount() <= 0)
                 return;
                
                 // Create a connection to fill the pool
                 try {
                 ConnectionListener cl = createConnectionEventListener(
                 defaultSubject, defaultCri);
                 synchronized (cls) {
                 if (trace)
                 log.trace("Filling pool cl=" + cl);
                 cls.add(cl);
                 }
                 } catch (ResourceException re) {
                 log.warn("Unable to fill pool ", re);
                 return;
                 }
                 } finally {
                 permits.release();
                 }
                 }
                 } catch (InterruptedException ignored) {
                 log.trace("Interrupted while requesting permit in fillToMin");
                 }
                 }
                 }


                • 5. Re: issues with JCA minimum connections

                  As it says on the WIKI, prefill only works if you use the single pool option
                  which are using but should not.

                  If your MCF has a required CRI then JBoss doesn't know what that should be
                  (the contents are opaque to the connection manager - see the spec).

                  And as the FAQ says you should be using the "incorrectly named"

                  <application-managed-security/>

                  if you have request parameters - a ConnectionRequestInfo (CRI).

                  The "workaround" is to tell it what the CRI is by programmatically
                  asking for a connection with the correct request parameters,
                  see the original feature request (also linked on the WIKI page describing the prefill option)
                  http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossJCAPooling