1 Reply Latest reply on Feb 13, 2012 12:02 PM by Paul Ferraro

    Inject new/existing Service<org.jboss.as.clustering.api.GroupMembershipListener>

    VITHUN VENGOPALAN Newbie

      For listening group membership changes, Paul Ferraro suggested the following approach

       

      Quoting to thread https://community.jboss.org/message/715940#715940  ,

      2. Create a custom subsystem that either creates a new, or injects an existing, Service<org.jboss.as.clustering.api.GroupMembershipListener & org.jboss.as.clustering.api.GroupRpcDispatcher>.  This object returned by this service is a slimmed down, slightly tidier version of HAPartition.

      How do we actually do that?

      I already went through https://docs.jboss.org/author/display/AS71/Extending+JBoss+AS+7 , I just wnated to know, hw do we inject something? and how do we do that in this case?

      ..... either creates a new, or injects an existing, Service<org.jboss.as.clustering.api.GroupMembershipListener & org.jboss.as.clustering.api.GroupRpcDispatcher>.......

        • 1. Re: Inject new/existing Service<org.jboss.as.clustering.api.GroupMembershipListener>
          Paul Ferraro Master

          Your custom service - the one that want to listen to cluster membership changes - should add a dependency on the relevant GroupMembershipNotifier service.

          e.g.

          {code}public class MyService implements Service<Foo>, GroupMembershipListener {

             private final Value<GroupMembershipNotifier> notifier;

             public MyService(Value<GroupMembershipNotifier> notifier) {

                this.notifier = notifier;

             }

             @Override

             public void start(StartContext context) {

               this.notifier.getValue().registerGroupMembershipListener(this);

             }

             @Override

             public void stop(StopContext context) {

           

               this.notifier.getValue().unregisterGroupMembershipListener(this);

            }

             @Override

             public void membershipChanged(...) {

                // ...

             }

          }{code}

           

          In your subsystem's add operation handler, where you'll want to install your custom service, you'll do something like:

           

          {code}InjectedValue<GroupMembershipNotifier> notifier = new InjectedValue<GroupMembershipNotifier>();

          ServiceName name = ...;

          MyService service = new MyService(notifier);

          context.getServiceTarget().addService(name, service).addDependency(ServiceName.JBOSS.append("cluster", "insert-cluster-name-here"), GroupMembershipNotifier.class, notifier).install();{code}

           

          The module providing this extension will need a dependency on the org.jboss.as.clustering.api module.