1 Reply Latest reply on Aug 2, 2005 2:47 PM by nirvanas1979

    Issue | Sequence Generator | 2 JBoss Instances Single Machin

    nirvanas1979

      Hi all,

      I am facing a strange issue. I have 2 instances of jboss on the same machine and we have a number of stateless session beans used in our application. Now, I have written a Stateless session bean for sequence generator. I am able to run it on one instance but it is failing on another instance (even if I am only this running this one instance).

      It gives the following error:
      com.proximities.common.utils.SequenceIdGeneratorUtil: Method: getSequence(): Message: TableKey : VENUE
      2005-08-02 11:19:58,406 DEBUG [com.proximities] Class: utils.SequenceIdGeneratorUtil: Method: getSequence(): Message: Fetching from sequence proxy factory: VENUE
      2005-08-02 11:19:58,406 DEBUG [com.proximities] Class: ejb.EJBLookupUtil: Method: getInitialContext: Message: Using JNDI initial context: org.jnp.interfaces.NamingContextFactory
      2005-08-02 11:19:58,406 DEBUG [com.proximities] Class: ejb.EJBLookupUtil: Method: getInitialContext: Message: Using JNDI URL: jnp://localhost:11099
      2005-08-02 11:19:58,406 DEBUG [com.proximities] Class: ejb.EJBLookupUtil: Method: getInitialContext: Message: Using JNDI initial context prefix: org.jboss.naming:org.jnp.interfaces
      2005-08-02 11:19:58,421 DEBUG [com.proximities] Class: ejb.EJBLookupUtil: Method: getSequenceFacade: Message: SequenceStoreFacadeHome - Sequence store facade home returned from ejbHomeFactory isnull
      2005-08-02 11:19:58,421 FATAL [com.proximities] Class: ejb.EJBLookupUtil: Method: getSequenceFacade: Message: Exception during the invoking the remote interface
      2005-08-02 11:19:58,421 INFO [STDOUT] java.lang.NullPointerException
      2005-08-02 11:19:58,421 INFO [STDOUT] ejb.EJBLookupUtil.getSequenceFacade(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] sequence.SequenceProxyFactory.getSequenceStore(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] sequence.SequenceProxyFactory.reserveBlock(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] sequence.SequenceProxyFactory.(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] sequence.SequenceProxyFactory.getSequence(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] at common.utils.SequenceIdGeneratorUtil.getSequence(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] at dataaccess.VenueDAO.add(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] at dataaccess.VenueDAO.update(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] at dataaccess.common.GenericDataAccessManager.executeModify(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] at business.mediator.ManageVenueMediator.insertIntoVenues(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] at business.sessionfacade.VenueManagementFacadeEJBean.insertIntoVenues(Unknown Source)
      2005-08-02 11:19:58,421 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2005-08-02 11:19:58,421 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2005-08-02 11:19:58,421 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2005-08-02 11:19:58,421 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:130)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:139)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.CleanShutdownInterceptor.invoke(CleanShutdownInterceptor.java:264)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.ejb.Container.invoke(Container.java:873)
      2005-08-02 11:19:58,421 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2005-08-02 11:19:58,421 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2005-08-02 11:19:58,421 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2005-08-02 11:19:58,421 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:155)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:104)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:179)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:165)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:97)
      2005-08-02 11:19:58,421 INFO [STDOUT] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:86)
      2005-08-02 11:19:58,421 INFO [STDOUT] at $Proxy92.insertIntoVenues(Unknown Source)

      Now within the server logs, I can see that it has loaded and cached the home interface of that bean, but dont know why its not picking it up.
      Here are the logs for the same:
      [org.jboss.ejb.EjbModule] startService, starting container: SequenceStoreFacade
      [org.jboss.system.ServiceController] starting service jboss.j2ee:jndiName=ejb.SequenceStoreFacadeHome,service=EJB
      [org.jboss.ejb.StatelessSessionContainer] Starting jboss.j2ee:jndiName=ejb.SequenceStoreFacadeHome,service=EJB
      [org.jboss.ejb.StatelessSessionContainer] Begin java:comp/env for EJB: SequenceStoreFacade
      [org.jboss.ejb.StatelessSessionContainer] TCL: org.jboss.util.loading.DelegatingClassLoader@188d92e
      [org.jboss.ejb.StatelessSessionContainer] Bound java:comp/ORB for EJB: SequenceStoreFacade
      [org.jboss.ejb.StatelessSessionContainer] Bound java:comp:/HandleDelegate for EJB: SequenceStoreFacade
      [org.jboss.ejb.StatelessSessionContainer] End java:comp/env for EJB: SequenceStoreFacade
      [org.jboss.ejb.plugins.local.BaseLocalProxyFactory] SequenceStoreFacade cannot be Bound, doesn't have local and local home interfaces
      [org.jboss.proxy.ejb.ProxyFactory] (re-)Binding Home ejb.SequenceStoreFacadeHome
      [org.jboss.proxy.ejb.ProxyFactory] Bound SequenceStoreFacade to ejb.SequenceStoreFacadeHome
      [org.jboss.system.ServiceController] starting service jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb.SequenceStoreFacadeHome
      [org.jboss.ejb.plugins.StatelessSessionInstancePool] Starting jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb.SequenceStoreFacadeHome
      [org.jboss.ejb.plugins.StatelessSessionInstancePool] Started jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb.SequenceStoreFacadeHome
      [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb.SequenceStoreFacadeHome dependent components: []
      [org.jboss.resource.connectionmanager.CachedConnectionInterceptor] start called in CachedConnectionInterceptor
      [org.jboss.ejb.StatelessSessionContainer] Started jboss.j2ee:jndiName=ejb.SequenceStoreFacadeHome,service=EJB
      [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:jndiName=ejb.SequenceStoreFacadeHome,service=EJB dependent components: []

      BTW, I am using JCS for caching and JBoss 4.0. Any pointers will be most appreciated?

      Thanks,
      Vikrant Verma

        • 1. Re: Issue | Sequence Generator | 2 JBoss Instances Single Ma
          nirvanas1979

          This problem is only occuring with the sequence bean and other beans are working fine. Here is the code for the same:
          public class SequenceStoreFacadeEJBean implements javax.ejb.SessionBean
          {
          /** The class name */
          private static final String CLASS_NAME = SequenceStoreFacadeEJBean.class.getName ();
          private javax.ejb.SessionContext mySessionCtx;
          /**
          * Default Constructor
          */
          public SequenceStoreFacadeEJBean ()
          {

          }
          /**
          * DOCUMENT ME!
          *
          * @param sequenceName DOCUMENT ME!
          * @param size DOCUMENT ME!
          *
          * @return DOCUMENT ME!
          *
          * @throws EJBException DOCUMENT ME!
          * @throws SequenceException DOCUMENT ME!
          */
          public SequenceRange reserveRange (String sequenceName,
          int size) throws EJBException,
          SequenceException
          {
          return reserveRange (sequenceName,
          size,
          false);

          }


          /**
          * DOCUMENT ME!
          *
          * @param sequenceName DOCUMENT ME!
          * @param size DOCUMENT ME!
          * @param secondTime DOCUMENT ME!
          *
          * @return DOCUMENT ME!
          *
          * @throws SequenceException DOCUMENT ME!
          * @throws SequenceIncrementException DOCUMENT ME!
          */
          protected SequenceRange reserveRange (String sequenceName,
          int size,
          boolean secondTime) throws SequenceException
          {
          /** The method name */
          final String METHOD_NAME = "reserveRange";


          LoggingWrapper.debug (CLASS_NAME,
          METHOD_NAME,
          "SequenceStoreBean::reserveRange - Reserving [" + size + "] on sequence [" +
          sequenceName + "].");
          PreparedStatement retrieveStmt = null;
          ResultSet retrieveRSet = null;
          PreparedStatement updateStmt = null;
          double start = 0.0D;
          SequenceRange range = null;

          Connection connection = null;

          try
          {
          connection = DataAccessUtil.getConnection ();

          retrieveStmt =
          connection.prepareStatement("SELECT seq.sequence_value AS sequence_value FROM fw_mis_sequence seq WHERE seq.sequence_name = ?");

          retrieveStmt.setString (1,
          sequenceName);
          retrieveRSet = retrieveStmt.executeQuery ();

          if (retrieveRSet.next ())
          {
          start = retrieveRSet.getDouble (1);

          LoggingWrapper.debug (CLASS_NAME,
          METHOD_NAME,
          "Sequence value returned from the table is: " + start);

          updateStmt = connection.prepareStatement ("UPDATE fw_mis_sequence SET sequence_value = (sequence_value + ?) WHERE sequence_name = ?");
          updateStmt.setInt (1,
          size);
          updateStmt.setString (2,
          sequenceName);
          int updates = updateStmt.executeUpdate ();


          if (updates != 1)
          {
          LoggingWrapper.debug (CLASS_NAME,
          METHOD_NAME,
          "No database rows to be updated");

          throw new SequenceIncrementException (sequenceName +
          "SequenceStoreBean::reserveRange - Database updated no rows");

          }

          }

          else
          {
          LoggingWrapper.debug (CLASS_NAME,
          METHOD_NAME,
          "Creating the new sequence for :" + sequenceName);

          createSequence (sequenceName);
          SequenceRange sequencerange = reserveRange (sequenceName,
          size,
          true);


          return sequencerange;

          }

          range = new SequenceRange (start,
          (start + (double) size) - 1.0D);

          }
          catch (SQLException exception)
          {
          throw new SequenceIncrementException (sequenceName,
          exception);

          }
          catch (Exception e)
          {
          e.printStackTrace();
          }
          finally
          {
          try
          {
          retrieveRSet.close ();
          retrieveStmt.close ();
          updateStmt.close ();
          }
          catch (Exception exception1)
          {

          }
          try
          {
          // release connection
          if (null != connection)
          {
          connection.close ();

          }
          }
          catch(Exception e)
          {

          }

          } // end try-catch-finally

          return range;

          } // end method reserveRange


          /**
          * DOCUMENT ME!
          *
          * @param sequenceName DOCUMENT ME!
          *
          * @throws EJBException DOCUMENT ME!
          * @throws SequenceCreationException DOCUMENT ME!
          */
          public void createSequence (String sequenceName) throws EJBException,
          SequenceCreationException
          {
          /** The method name */
          final String METHOD_NAME = "reserveRange";


          LoggingWrapper.debug (CLASS_NAME,
          METHOD_NAME,
          "SequenceStoreBean::createSequence - creating sequence [" + sequenceName + "].");
          PreparedStatement insertStmt = null;


          Connection connection = null;

          try
          {
          connection = DataAccessUtil.getConnection ();

          insertStmt = connection.prepareStatement ("INSERT INTO fw_mis_sequence (sequence_name, sequence_value) VALUES (?,?)");
          insertStmt.setString (1,
          sequenceName);
          insertStmt.setDouble (2,
          0.0D);
          int updateCount = insertStmt.executeUpdate ();

          LoggingWrapper.debug (CLASS_NAME,
          METHOD_NAME,
          "updateCount is :" + updateCount);

          if (updateCount != 1)
          {
          throw new SequenceCreationException ("SequenceStoreBean::createSequence - The update count on sequence [" +
          sequenceName + "] was not 1 [" + updateCount + "]");

          }

          }
          catch (Exception gse)
          {
          throw new SequenceCreationException (sequenceName,
          gse);

          }
          finally
          {
          try
          {
          insertStmt.close ();

          }
          catch (Exception exception1)
          {

          }
          try
          {
          // release connection
          if (null != connection)
          {
          connection.close ();

          }
          }
          catch (Exception exception2)
          {

          }
          } // end try-catch-finally

          } // end method createSequence

          static final String RETRIEVE_SQL = "framework.sequence.retrieve";
          static final String UPDATE_SQL = "framework.sequence.update";
          static final String CREATE_SQL = "framework.sequence.create";
          static final String AUTO_CREATE = "framework.sequence.autoCreate";
          static final double AUTO_CREATE_START_VALUE = 0D;
          static final boolean AUTO_CREATE_DEFAULT = false;

          /**
          * getSessionContext
          *
          * @return Returns mySessionCtx
          */
          public javax.ejb.SessionContext getSessionContext ()
          {
          return mySessionCtx;

          }


          /**
          * setSessionContext
          *
          * @param ctx javax.ejb.SessionContext the ctx set to.
          */
          public void setSessionContext (javax.ejb.SessionContext ctx)
          {
          mySessionCtx = ctx;

          }


          /**
          * ejbCreate
          *
          * @throws javax.ejb.CreateException Standard application-level exception
          * to report a failure to create an
          * entity EJB object
          */
          public void ejbCreate () throws javax.ejb.CreateException
          {
          // do nothing.

          }


          /**
          * ejbActivate
          */
          public void ejbActivate ()
          {
          // do nothing.

          }


          /**
          * ejbPassivate
          */
          public void ejbPassivate ()
          {
          // do nothing.

          }


          /**
          * ejbRemove
          */
          public void ejbRemove ()
          {
          // do nothing.

          }

          } // end class SequenceStoreFacadeEJBean