8

I've been using deploy-hasingleton folder in jboss as 6, this allowed me to create a singleton bean that is used to control business information requests from the cluster nodes. These methods are synchronized in order to control the concurrency between nodes (the same data cannot be in different nodes).

Now that I'm migrating to the Jboss 7, and since that deploy-hasingleton folder disappeared, I've been following the official examples:

The problem is that theses examples are too trivial, and I couldn't understand where I can place the business logic methods. So I tried to place that logic in the SingletonService, which implements: Service, MyInterface

And I've modified the getValue method to the following:

@Override
    public MyInterface getValue() throws IllegalStateException,
            IllegalArgumentException {

        return this;
    }

On the client side:

@Override
    public List<Long> myMeth(Long arg1, int arg2) {
        LOGGER.log("loadGroups() is called()");
        ServiceController<?> service = CurrentServiceContainer.getServiceContainer().getService(
                GroupDistributorService.SINGLETON_SERVICE_NAME);

        if (service != null) {
            return ((MyInterface ) service.getValue()).getMyMethod(arg1, arg2);
        } else {
            throw new IllegalStateException("Service '" + GroupDistributorService.SINGLETON_SERVICE_NAME + "' not found!");
        }
    }

I doubt that this is the correct approach. And second, this appears to work in the node that contains the master singleton service. However in other nodes, it locks when calling the singleton service, and I get a timeout.

Dr.Cuco
  • 23
  • 1
  • 7
DCarvalho
  • 81
  • 5

1 Answers1

1

Several months ago I've posted blog post about using HASingleton in Jboss 7: http://www.kubrynski.com/2013/07/using-ha-singleton-in-jboss-7.html Hope it will help. Be sure that you enabled clustering mode:

<subsystem xmlns="urn:jboss:domain:ee:1.0">
  <global-modules>
    <module name="org.jboss.msc" slot="main">
    <module name="org.jboss.as.clustering.singleton" slot="main">
  </global-modules>
</subsystem>

and that you stick to osgi system, by adding in your pom.xml (to jar/war plugin) such configuraiton:

<configuration>
  <archive>
    <manifestentries>
      <dependencies>
        org.jboss.msc,org.jboss.as.server,
        org.jboss.as.clustering.singleton
      </dependencies>
    </manifestentries>
  </archive>
</configuration>
Jakub Kubrynski
  • 13,724
  • 6
  • 60
  • 85
  • Note that [link-only answers are discouraged](http://meta.stackoverflow.com/tags/link-only-answers/info), SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Jan 04 '14 at 15:57
  • does this allow a single bean to be loaded ha-singleton as opposed to a whole module? – drone.ah Oct 02 '14 at 12:23