-
1. Re: Accessing JGroups Channels Within a JBoss 7 Application
pedrokowalski Feb 20, 2013 8:53 AM (in response to safetytrick)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
pferraro Feb 20, 2013 11:13 AM (in response to pedrokowalski)From a service activator:
{code}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()
;
}
}{code}
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:
{code}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
pedrokowalski Feb 25, 2013 2:45 AM (in response to pferraro)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
belaban Aug 8, 2013 8:31 AM (in response to pedrokowalski)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)...