4 Replies Latest reply on Aug 25, 2001 11:51 PM by marc.fleury

    just one instance of a stateful session bean

    raheit00

      Hello,

      I am trying to configure the container (Jboss 2.2.2) to instantiate no more than one instance of a stateful session bean. Unfortunately the container is creating more than one instance. Which I do not want, because the bean is meant to open a serial connection to a cellular phone.
      Any suggestions???

      Thanks,
      Ralph Hesse
      below is the jboss.xml configuration which I used!!!!!!!


      <?xml version="1.0" encoding="Cp1252"?>

      <enterprise-beans>
      <message-driven>
      <ejb-name>ListenerSMSBean</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/SMSQueue</destination-jndi-name>
      </message-driven>

      <ejb-name>SMSMessageBean</ejb-name>
      <configuration-name>SMSMessage Stateful SessionBean</configuration-name>

      false
      </enterprise-beans>
      <container-configurations>

      <container-configuration>
      <container-name>SMSMessage Stateful SessionBean</container-name>
      <call-logging>false</call-logging>
      <container-invoker>org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker</container-invoker>
      <container-interceptors>
      org.jboss.ejb.plugins.LogInterceptor
      <!-- CMT
      -->
      org.jboss.ejb.plugins.TxInterceptorCMT
      org.jboss.ejb.plugins.MetricsInterceptor
      org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor
      <!-- BMT
      -->
      org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor
      org.jboss.ejb.plugins.TxInterceptorBMT
      org.jboss.ejb.plugins.MetricsInterceptor
      org.jboss.ejb.plugins.SecurityInterceptor
      </container-interceptors>
      <instance-cache>org.jboss.ejb.plugins.StatefulSessionInstanceCache</instance-cache>
      <persistence-manager>org.jboss.ejb.plugins.StatefulSessionFilePersistenceManager</persistence-manager>
      <transaction-manager>org.jboss.tm.TxManager</transaction-manager>
      <container-invoker-conf>
      4444
      True
      </container-invoker-conf>
      <container-cache-conf>
      <cache-policy>org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy</cache-policy>
      <cache-policy-conf>
      <min-capacity>1</min-capacity>
      <max-capacity>1</max-capacity>
      <overager-period>300</overager-period>
      <max-bean-age>600</max-bean-age>
      <resizer-period>400</resizer-period>
      <max-cache-miss-period>60</max-cache-miss-period>
      <min-cache-miss-period>1</min-cache-miss-period>
      <cache-load-factor>0.75</cache-load-factor>
      </cache-policy-conf>
      </container-cache-conf>
      <container-pool-conf>
      1
      </container-pool-conf>
      </container-configuration>
      </container-configurations>

        • 1. Re: just one instance of a stateful session bean
          nhebert


          Ralph,

          The creation of Singletons is a bit of a problem
          in the J2EE/EJB context. No matter what you do
          if you get it to work it will be app server dependent.

          Maybe you need to step out of the EJB container context
          and use JMX MBeans, Jini or stand-alone Java programs
          that register themselves with a JBoss JNDI namespace.

          I have no idea what you are trying to do, but sometimes
          it pays to think outside of "The Box"...

          Cheers,

          Noel.

          • 2. Re: just one instance of a stateful session bean
            raheit00

            Hi,

            I solved it meanwhile with a interprocess communcation throw a static variable in the session bean. I think I read something that static variables are not allowed in ejb´s, but I am not sure. However it works. I block the other beans as long as my resource is busy.
            Hopefully this works, it is just a temporary solution and so I think it is ok.

            Regards,
            Ralph

            • 3. Re: just one instance of a stateful session bean
              nhebert

              Ralph,

              Glad to see that you have found a solution
              that meets your immediate needs.

              However, you are quite correct in noting that
              the use of static variables are not allowed.
              There use is frought with peril.

              It may work, but just remember that it is not
              portable and will not scale into a clustered
              (multi-application server) environment.

              If your application is running in a single JBoss
              instance (or any app server) and it meets your
              performance needs, than go for it.

              But be warned...

              Cheers,

              Noel.

              • 4. Re: just one instance of a stateful session bean
                marc.fleury

                Let me get this straight... one instance of a stateful bean?... hmmmm sounds like an entity bean to me :)

                in any case it seems you are trying to map something to ejb that doesn't quite fit, the static idea is a good one and frankly the only thing that will throw it off is the passivation of the stateful bean, just make sure you use non-passivating caches or that the bean implements passivate and activate correctly.

                But the most enterprise ready way of doing this is the MBean way... try to dig that if you have time