2 Replies Latest reply: Oct 31, 2012 10:27 PM by 971828 RSS

    Weblogic Singleton Service - Stateless session bean

      I have created a singleton service on a weblogic cluster using a Stateless EJB

      +@Stateless(name = "BasicSingletonBean", mappedName = "BasicSingletonBean")+
      +public class BasicSingletonBean implements BasicSingletonBeanRemote, SingletonService {+

      private List<String> messages = null;

      +public void activate() {+
      System.out.println("EJB: activating singleton service");
      messages = new ArrayList<String>();

      +public void deactivate() {+
      System.out.println("EJB: deactivating singleton service");
      messages = null;

      +public void add(String s) {+
      System.out.println("Adding message : " s);+

      +public List<String> get() {+
      System.out.println("Returning message : " messages);+
      return messages;

      I see that proper logs in the server log that it got activated on only one of the nodes of the cluster.

      +<svr2> <ExecuteThread: '3' for queue: 'weblogic.kernel.System'> <<WLS Kernel>> <> <> <1297279799988> <BEA-000187> <The Singleton Service BasicSingletonBean is now registered on this server. This server may be chosen to host this service.>+
      +<svr2> <ExecuteThread: '4' for queue: 'weblogic.kernel.System'> <<WLS Kernel>> <> <> <1297279842387> <BEA-000189> <The Singleton Service BasicSingletonBean is now active on this server.>+
      But if I check the JNDI tree it is registered on all the servers.

      I went ahead and wrote a client which does a look up on the cluster url and makes some calls on the bean. I see that it is going to both the servers in the cluster and since one of the "List" is not initialized on one of the nodes, it fails on that node "svr1". But it works fine on the node where the singleton service was activated "svr2".

      So basically eventhough it looks like the singleton service is registered properly, it doenst actually work which brings me to question:
      1) Does singleton service work with stateless session beans
      2) Is there any extra configuration in the EJB annotations other than implementing the SingletonService interface for the EJB to be Singleton
      3) Is there any special way the client has to be written to lookup singleton EJB other than normal ctx lookup.

      Any help is very much appreciated.
        • 1. Re: Weblogic Singleton Service - Stateless session bean

          I'm not sure if singleton services works with stateless session beans. By other hand, I understand as follow:-

          1. After you have created a singleton service class using the SingletonService interface, you must define it as a singleton service within WebLogic Server, see http://download.oracle.com/docs/cd/E1284001/wls/docs103/ConsoleHelp/taskhelp/clusters/ConfigureSingletonService.html_

          2. A singleton service is a service (application) on a cluster that is available and active on only one server at any given time, you must deploy the service on only one member of the cluster.

          3. For high avalability, you must implement WebLogic Service Migration for your singleton service, see http://download.oracle.com/docs/cd/E1284001/wls/docs103/cluster/service_migration.html#wp1051458_

          4. The clients connecting to the service, you must implement a special mechanism. See http://download.oracle.com/docs/cd/E1322201/wls/docs81/jndi/jndi.html#475689_
          • 2. Re: Weblogic Singleton Service - Stateless session bean
            I cannot get this to work under any scenario. The examples I have found say you need to implement a Remote interface on an implementation of weblogic.cluster.singleton.SingletonService then bind that class under the Remote's name in JNDI during activate, then use JNDI look-up to get back to the singleton but when you look-up in JNDI on any of the servers that don't have the service activated then you get a copy of the service that is not activated and if you change any data it doesn't persist across calls let alone across other servers in the cluster. This whole feature is worthless. If you are going to advertise something as a cluster wide singleton then it should be accessible across the cluster as a single instance object in all cluster jvms and weblogic should handle any replication or whatever in order to keep all servers in the cluster up to date with changes to the singleton's data or whatever.