Dear all,
I've been playing around with the HA singleton service of JBoss AS7. I
took the example in
https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Appli...
as a basis and use a EJB Singleton to start and stop the HA singleton
service.
Starting the service works fine, I also tested the fail-over behaviour
between different nodes. However, I encountered some strange behaviour
when it is up to stop the service:
- When I shutdown the server, the service is properly stopped and the
corresponding method stop() method is executed
- When I undeploy the app the PreDestroy method of the EJB singleton is
executed and I try to stop the HA singleton service as in the example.
However, it seems that the service is already in the REMOVED state and
unfortunately, the stop method of the singleton service is never
executed. So I have no possibility to clean up the resources that are
claimed by the service (TCP socket connection). This is not the
behaviour I'd expect
The code of the EJB singleton for service starting/stopping is as
follows:
@Singleton
@Startup
public class ServiceInstaller {
private static final Logger LOGGER =
LoggerFactory.getLogger(ServiceInstaller.class);
@PostConstruct
public void init() {
LOGGER.info("Starting singleton");
SimpleService service = new SimpleService();
SingletonService<String> singleton = new
SingletonService<String>(service, SimpleService.SINGLETON_SERVICE_NAME);
ServiceController<String> controller =
singleton.build(CurrentServiceContainer.getServiceContainer())
.addDependency(ServerEnvironmentService.SERVICE_NAME,
ServerEnvironment.class, service.getEnvInjector())
.install();
ServiceListener<String> listener = new
NotifyingServiceListener<String>();
controller.addListener(listener);
controller.setMode(ServiceController.Mode.ACTIVE);
LOGGER.info("Singleton started");
}
@PreDestroy
public void destroy() {
LOGGER.info("Destroying singleton");
ServiceController<?> controller =
CurrentServiceContainer.getServiceContainer().getRequiredService(SimpleService.SINGLETON_SERVICE_NAME);
controller.setMode(ServiceController.Mode.REMOVE);
LOGGER.info("Singleton destroyed");
}
private static class NotifyingServiceListener<T> extends
AbstractServiceListener<T> {
@Override
public void transition(ServiceController<? extends T>
controller, Transition transition) {
LOGGER.info("Change state from " +
transition.getBefore().toString() + " to " +
transition.getAfter().toString());
}
}
}
I've tested this using JBoss 7.1.1 and the standalone-ha.xml
configuration.
Another weird issue is that, if I redeploy the app after I've deployed
it, the deployment fails. The log shows me that the service with the
same name is already registered. However, I have not found a possibility
to unregister such a service.
Any suggestions? Is this a bug in JBoss?
Thanks,
Ingo