I think you have to use a JBoss MSC Service instead of a singleton EJB. You can find a good start point on the wildfly-quickstart examples(cluster-ha-singleton). This example implements a clustered singleton. Based on this I try myself a bit and implement three maven modules (look at the attachment).
wildfly-service-test: Contains the service
wildfly-service-test-app-1: Contains a webservice to interact with the service
wildfly-service-test-app-2: Contains a webservice to interact with the service (a copy of app-1, only the name was changed)
wildfly-test.zip 13.5 KB
Dirk, you're a genius! This is was I was hoping to do! Can I ask you for some explanation on the classes? I see MyServiceEnviroment is a simple POJO. Is there any reason to use it or was just for the sake of the example? And in MySingletonService you use ServiceName.JBOSS.append for creating the name. What does this parameters mean? The only thing left is that app wont work if I deploy it from inside Netbeans. It only works if I deploy it via Administration Console. But sure this is an NB plugin bug.
1 of 1 people found this helpful
This are two good questions and I had this questions too. I read the org.jboss.msc javadoc documentation (can be downloaded from maven.org).
In the Service Interface documentation you can read: "The value type specified by this service is used by default by consumers of this service, and should represent the public interface of this service, which may or may not be the same as the implementing type of this service"
A ServiceName is structured like a java package name. The root name is JBOSS and all names are based on this name. All registered Services can be listed with CurrentServiceContainer.getServiceContainer().getServiceNames()
Thats all what I currently know about this. I work on this now for less than 2 weeks.
I started downloaded the docs (via IDE) and dont know why didnt finish...
But now I understood why another test I made based on yours failed... As for the naming convention... its quite unclear still. Will try to dig deeper in order to see if I can really find out what Im doing!
But, despite this, you solved my problem, so Thanks again!
You should also be able to do it using @Singleton EJBs. What you'd need to do is make it implement an interface, and put that interface in a jar which SmsClient has access to. The problem with your initial attempt would be that SmsClient needs access to the SmsService class, and by doing that it effectively has it's own @Singleton EJB.