4 Replies Latest reply: Aug 8, 2013 8:31 AM by Bela Ban RSS

Accessing JGroups Channels Within a JBoss 7 Application

Michael Nielson Newbie

I'm in the process of upgrading a JBoss 5.1 application to JBoss 7.1.1. We currently monitor cluster health by looking into JGroups JChannels and comparing the view that's expected from the current cluster state and the actual JGroup's view. I'd also like to create my own JGroups channel and use it for some cluster coordination. What I can't seem to find is any JBoss API for current open channels and the ChannelFactory? Is there any way to access the underlying JGroups subsytem?

 

Michael

  • 1. Re: Accessing JGroups Channels Within a JBoss 7 Application
    Piotr Nowicki Newbie

    I'll bump this question.

     

    Is it possible to access the JGroups from the application? I would like to reuse the protocol stack and use it to create the JChannel.

     

    All the best,

    Piotr

  • 2. Re: Accessing JGroups Channels Within a JBoss 7 Application
    Paul Ferraro Master

    From a service activator:

     

    public class MyService implements Service<Void> {
        private final Value<Channel> channel;
        public MyService(Value<Channel> channel) {
            this.channel = channel;
        }
        @Override
        public void start(StartContext context) {
            try {
                this.channel.getValue().connect("myCluster");
            } catch (Exception e) {
                throw new StartException(e);
            }
        }
        @Override
        public void stop(StopContext context) {
            try {
                this.channel.close();
            } catch (Exception e) {
                // Log exception
            }
        }
        @Override
        public Void getValue() {
            return null;
        }
    }
    
    
    public class MyServiceActivator implements ServiceActivator {
        @Override
        public void activate(ServiceActivationContext context) {
            String stack = "udp";
            String channelId = "mychannel";
            ServiceName channelName = ChannelService.getServiceName(channelId);
            InjectedValue<ChannelFactory> factory = new InjectedValue<ChannelFactory>();
            context.getServiceTarget().addService(factoryServiceName, new ChannelService(factory))
                    .addDependency(ChannelFactoryService.getServiceName(stack), ChannelFactory.class, factory)
                    .install()
            ;
            ServiceName name = // Some service name
            InjectedValue<Channel> channel = new InjectedValue<Channel>();
            context.getServiceTarget().addService(name, new MyService(channel))
                    .addDependency(channelName, Channel.class, channel)
                    .setInitialMode(ServiceController.Mode.ACTIVE)
                    .install()
            ;
        }
    }

     

     

    You'll then need to create a META-INF/services/org.jboss.msc.service.ServiceActivator file containing the fully qualified class name of your service activator class and add the following dependencies to your application's META-INF/MANIFEST.MF:

     

    Dependencies: org.jboss.msc, org.jboss.as.clustering.jgroups, org.jgroups

     

     

    That should do it.

  • 3. Re: Accessing JGroups Channels Within a JBoss 7 Application
    Piotr Nowicki Newbie

    Thanks a lot Paul for your post and talk!

     

    I've managed to get it working and summed this up in my post here: http://piotrnowicki.com/2013/02/using-jgroups-directly-from-jboss-as-7-component/

     

    Hope it'll help someone else.

     

    Cheers!

  • 4. Re: Accessing JGroups Channels Within a JBoss 7 Application
    Bela Ban Master

    https://issues.jboss.org/browse/JGRP-1613 will make is even simpler to reuse an existing channel, either from Infinispan or Wildfly. This will not only give you an independent channel (ForkChannel), on which you only see your *own* traffic, but you'll also be able to add protocols to an existing stack, e.g. COUNTER.

    This is being designed and implemented as I speak (Aug 2013)...