Search code examples
javacluster-computingrpcjgroups

JGroups RpcDispatcher calling method from another class


How can I get an RpcDispatcher to remotely invoke the methods of a different class? The examples I've seen online all seem to demonstrate how it works when they're all instances of the same class. E.g. this one from the JGroups manual works fine for me because you just start multiple instances of RpcDispatcherTest and they all contain the print(int) method.

So how excatly could I get said RpcDispatcherTest to invoke from another, separate JGroups class, e.g. something like the SimpleChat example (also from the JGroups manual).

I've tried asking RpcDispatcherTest to connect to the same channel as SimpleChat: channel.connect("ChatCluster");. They seem to register eachother, and you can see the updated view with the multiple classes running, but I've failed to get the RpcDispatcherTest to actually invoke a method from SimpleChat, even if I copy the exact same print(int) method into it.


Solution

  • When you create an RpcDispatcher, you pass in a channel and a server object as arguments. The latter is the instance on which the RPCs will get invoked. In the examples, it is this, but you can pass in any object that implements the methods you want to invoke.