0 Replies Latest reply on Sep 14, 2015 6:21 PM by loporto

    Wildfly Ha singleton , invoke singleton bean with several methods



      I am trying to figure out how to use just one singleton bean that "lives" on a cluster. I have found an approximation of that using HA singleton (example from wildfly/quickstart · GitHubhttps://github.com/wildfly/quickstart).

      Basically that solution is to have a service running in only one machine of a cluster. This service has a method, getValue(), wich allows to call a singleton bean, guaranteeing that

      there is only one singleton bean instance inside the cluster.


      The problem with that approach, is that the getValue() method of the service invokes a singleton bean and allows to call to one method. Untill here, all good. But, what happen if the singleton bean I want to invoke has more than one method? The idea is not to implement several services per each method that I need to invoke.


      The basic idea (according the quickstart ha singleton example) is, from the client, call to a @Stateless bean (AccessBean) that calls the Service... I implemented something like that :

           //from my @stateless accessBean

          ServiceController<?> service = CurrentServiceContainer.getServiceContainer().getService(MyService.DEFAULT_SERVICE_NAME);



      where MyService implements org.jboss.msc.service.Service<SomeType>


      then, we can call :

            //from my @stateless accessBean



      this returns an object and it works fine.


      The getValue() implementation (as a part of the Service) is something like that:

      ** I omitted all the try/catch/throws exception, is just a  code to explain the problem **


          public Integer getValue() {
                  InitialContext ic = new InitialContext();
                  Integer gvalue = ((MyRemoteInterface) ic.lookup("global/....!....")).getValue(); //that calls a method from the singetonBean
                  return gvalue;

      I tried to create a new getValue method that have parameters inside my  MyService Class (for example the name of the method I want to invoke, using reflection) and when I try to use this method from my @Stateless bean (AccessBean) as in this line:

        ((MyService)service).getValue(some parameteres...)


      I have a java.lang.ClassCastException because service's class is org.jboss.msc.service.ServiceControllerImpl and is not possible to cast with my service.

      Please, any Idea ?