-
1. Re: Invoking a session bean method on each cluster node
pferraro Dec 1, 2014 12:10 PM (in response to simplex-software)As of WildFly 8, you can use the clustering API for this purpose, specifically the CommandDispatcher. This facility allows you to execute commands on any or all nodes in the cluster. The requisite modules are already exported to the classloader of a deployment, so long as the JGroups and Infinispan subsystems are installed.
The complete API is here:
There is a test in the clustering testsuite that demonstrates a simple use case:
In your case, you would use your @Local @Stateless EJB as the command context.
-
2. Re: Invoking a session bean method on each cluster node
simplex-software Dec 2, 2014 8:46 AM (in response to pferraro)Hi Paul,
Many thanks for your reply. I need something that would work for EAP 6.2 and that is documented, such that I could see how to use it. As far as I have seen, the GIT repository to which you've sent links to me only contains the source code. I have googled around but didn't find any comprehensible documentation. Do you have anything which could help ? By the way, I'd be using @Stateless.
Many thanks in advance,
Nicolas
-
3. Re: Re: Invoking a session bean method on each cluster node
pferraro Dec 3, 2014 8:34 AM (in response to simplex-software)I see. The code to which I directed you was first introduced in WildFly 8, and thus doesn't exist in EAP 6.2. This is a WildFly forum, hence my assumptions...
You can do something similar in EAP 6, but it would require private modules (i.e. org.jboss.as.clustering.api and org.jboss.as.server) and would leverage the more primitive GroupRpcDispatcher. Because these modules are private, they are undocumented/unsupported apart from the source/javadoc itself. You should be able to do something like:
e.g.
ServiceRegistry registry = org.jboss.as.server.CurrentServiceContainer.getServiceContainer(); // Easiest way to access the MSC service registry org.jboss.as.clustering.GroupRpcDispatcher dispatcher = (org.jboss.as.clustering.GroupRpcDispatcher) registry.getService(ServiceName.JBOSS.append("cluster", "ejb")).getValue(); // Gets the group rpc dispatcher that uses the JGroups channel for EJBs. dispatcher.registerRPCHandler("foo", mySLSB); // Registers your @Stateless EJB as handler for remote rpcs
You can then dispatch RPCs to your @Stateless EJBs on each node via:
Object[] args = ...; Class[] types = ...; boolean excludeSelf = ...; dispatcher.callMethodOnCluster("foo", "methodName", args, types, excludeSelf);
The dispatcher will send the method signature and its arguments to each node, where that method on your SLSB (local to each node) will be invoked via reflection.
-
4. Re: Re: Invoking a session bean method on each cluster node
simplex-software Dec 3, 2014 6:12 AM (in response to pferraro)Hi Paul,
Many thanks again for your reply. Sorry about the confusion. Yes, I know it's a Wildfly site but I thought that EAP and Wildfly have a common code base and we get more pro-active and faster results from this site then from the RedHat customer support, who rejects most of tickets as "unsupported".
This is a very interesting and elegant solution. I'll definetly giez it a try. Just for the records, the statement
org.jboss.as.clustering.GroupRpcDispatcher dispatcher = (org.jboss.as.clustering.GroupRpcDispatcher) registry.getService(ServiceName.JBOSS.append("cluster", "ejb").getValue(); // Gets the group rpc dispatcher that uses the JGroups channel for EJBs.
should be:
org.jboss.as.clustering.GroupRpcDispatcher dispatcher = (org.jboss.as.clustering.GroupRpcDispatcher) registry.getService(ServiceName.JBOSS.append("cluster", "ejb")).getValue(); // Gets the group rpc dispatcher that uses the JGroups channel for EJBs.
right ?
Many thanks for your help.
Nicolas
-
5. Re: Re: Invoking a session bean method on each cluster node
pferraro Dec 3, 2014 8:35 AM (in response to simplex-software)Correct. I just edited that post.
-
6. Re: Invoking a session bean method on each cluster node
chrigri Jun 7, 2016 3:22 AM (in response to pferraro)Hi Paul,
Do you have any examples of how to do:
"In your case, you would use your @Local @Stateless EJB as the command context."
I'm having problem calling my SessionBeans from within the execute() method of an Command class.
I get Not Allowed execptions.
--
Christer