Multiple node elected as Singleton service provider
bsudhananthan Feb 6, 2014 4:23 AMI'm using jboss-eap-6.1.0. standalone-full-ha configuration.
Singleton service start method has been triggered in multiple nodes i.e both master and slave nodes has been elected as service provider for "MySingletonService.SINGLETON_SERVICE_NAME".
My singleton service initiator ClusterServiceInitiater.java looks like :
@Singleton
@Startup
public class ClusterServiceInitiater
{
/**
* create the service during startup
*/
@PostConstruct
protected void clusterSingletonStartup()
{
MySingletonService mySingletonService = new MySingletonService();
SingletonService<String> singletonService = new SingletonService<String>(mySingletonService, MySingletonService.SINGLETON_SERVICE_NAME);
CurrentServiceContainer.getServiceContainer().dumpServices();
ServiceController<String> controller = singletonService.build(CurrentServiceContainer.getServiceContainer())
.addDependency(ServiceName.JBOSS.append("cluster", "singleton"),
GroupMembershipNotifier.class, mySingletonService.getEnvInjector()).install();
//controller.setMode(ServiceController.Mode.ACTIVE);
}
/**
* Remove the service during undeploy or shutdown
*/
@PreDestroy
protected void destroy() {
ServiceController<?> controller = CurrentServiceContainer.getServiceContainer().getRequiredService(MySingletonService.SINGLETON_SERVICE_NAME);
controller.setMode(ServiceController.Mode.REMOVE);
}
}
And the singleton class MYSingletonService.java looks like:
public class MySingletonService implements Service<String>, GroupMembershipListener
{
private static Log logger = LogFactory.getLog(MySingletonService.class);
public static final ServiceName SINGLETON_SERVICE_NAME = ServiceName.JBOSS.append("MY_Singleton_Service");
private final InjectedValue<GroupMembershipNotifier> notifier = new InjectedValue<GroupMembershipNotifier>();
@Override
public String getValue() throws IllegalStateException,
IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
@Override
public void start(StartContext arg0) throws StartException {
logger.info("::::Inside Start Of Singleton:::");
}
@Override
public void stop(StopContext arg0) {
logger.info("::::Inside Start Of Singleton:::");
}
@Override
public void membershipChanged(List<ClusterNode> arg0,
List<ClusterNode> arg1, List<ClusterNode> arg2) {
// TODO Auto-generated method stub
}
@Override
public void membershipChangedDuringMerge(List<ClusterNode> arg0,
List<ClusterNode> arg1, List<ClusterNode> arg2,
List<List<ClusterNode>> arg3) {
// TODO Auto-generated method stub
}
public Injector<GroupMembershipNotifier> getEnvInjector() {
return this.notifier;
}
}
What happens is when i start two nodes at same time, Singleton service's start() method has been triggered in multiple nodes i.e both master and slave nodes has been elected as service provider of "MySingletonService.SINGLETON_SERVICE_NAME". Can any on explain me why this is happening.
Thanks in Advance,
Sudhananthan B.