2 Replies Latest reply on Jan 9, 2015 2:07 PM by Yu Feng

    JGroups delay

    Yu Feng Newbie


      I am following article at http://www.mastertheboss.com/jboss-server/jboss-cluster/dispatching-commands-on-wildfly-cluster to dispatch commands to the cluster using JGroups. It works, but, with a problem that has bothered me.


      We use Apache proxy to connect to two servers (name A and B) in the cluster. We have a web service to invoke the sample code in the article to dispatch the command. The first time we hit the web service, Apache directs to server A and only A executes the command although JGroups sees two nodes and we called executeOnCluster() command. If we keeping trying the web serve, Apache will eventually direct call to server B and whenever that happens, all following web service call works -- both A and B executes the command. That is the delay ...


      Is there a configuration for this?



        • 1. Re: JGroups delay
          Paul Ferraro Master

          While that article does a good job explaining the purpose of the CommandDispatcher abstraction, it does a poor job demonstrating how to use it.

          The key issue the author fails to note is that Commands can only be sent, but more importantly, *only be received*, for the lifetime of the CommandDispatcher.

          Consequently, this code:


          public void execute() {
              try (CommandDispatcher<String> dispatcher = this.factory.createCommandDispatcher("id1", "Garbage collection in progress....")) {
                  dispatcher.executeOnCluster(new GarbageCollectorCommand()); 


          will rarely execute on a remote node, since that node will only execute the command if its corresponding CommandDispatcher (i.e. with the same cluster and identifier) is active.


          In summary, the CommandDispatcher is not a temporary object, but must remain active for as long as you wish it to execute commands.

          To facilitate this, a CommandDispatcher is typically created and used from a @Startup @Singleton, e.g.


          @Startup @Singleton
          public class MySingleton {
              private CommandDispatcherFactory factory;
              private CommandDispatcher<MyCommandContext> dispatcher;
              private MyCommandContext context = ...;
              public void init() {
                  this.dispatcher = this.factory.createCommandDispatcher("foo", this.context);
              public void destroy() {
              // ...


          There's a better example of CommandDispatcher usage in the clustering testsuite:

          wildfly/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/dispatcher/bean at master · …

          • 2. Re: JGroups delay
            Yu Feng Newbie

            Thanks Paul! It is of great help and I will look into your example.