-
1. Re: Inject new/existing Service<org.jboss.as.clustering.api.GroupMembershipListener>
pferraro Feb 13, 2012 12:02 PM (in response to vithun.v)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.