5 Replies Latest reply on Feb 7, 2013 6:36 AM by Radoslav Husar

    How to invoke a local EJB from SingletonService client?

    Michał Ćmil Newbie

      Hello,

       

      What I'm trying to achiebe is a cluster-wide singleton. I've successfuly created a Service implementing the Service<MyBusinessInterface> interface. When the Service is started, it lookups a @Singleton bean at stores the ejb locator in a field.  When I invoke a getValue() on it from my SLSB (lets name it AccesBean), I get EJB locator, and I can successfully call it. The problem is that the service works on Node1 (its currently elected on Node1) and the SLSB is on Node 2 (which has its own @Singleton bean). getValue() called from Node2 is invoked on Node1, but the ejbLocator passed to the Node2 points to the @Singleton on Node2 - I want it to point to the node, on which the lookup occured (Node1).

       

      Any ideas, how it should be done? Currently the lookup is a simple (Single is the @Singleton bean implementing the NodeNameServiceIf):

       

       

      public class NodeNameServiceBean implements Service<NodeNameServiceIf> {
      (...)
      private NodeNameServiceIf singleton;
      (...)
      @Override
      public void start(StartContext arg0) throws StartException {
      if (!started.compareAndSet(false, true)) {
       throw new StartException("The service is still started!");
       }
      try { 
      InitialContext ic = new InitialContext(p);
      singleton =  (NodeNameServiceIf) ic.lookup("ejb:sample-jboss-ear/sample-jboss-ejb-0.0.1-SNAPSHOT/Single!dNodeNameServiceIf");               
      } catch (NamingException e) {
      e.printStackTrace();
       }
      }
      
      @Override
      public NodeNameServiceIf getValue() {
      return singleton;
      }
      }