1.16.2. Single Method Call Command

Most of the time we only need to call a method on a given object, this can be done thanks to the org.exoplatform.services.rpc.SingleMethodCallCommand which is the implementation of a RemoteCommand proposed by default. This command will dynamically execute a method on a given object.

// Register the command first (to be done before that the RPCService has been started)

RemoteCommand commandGetName = rpcService.registerCommand(new SingleMethodCallCommand(myService, "getName"));
// Execute the command on the coordinator (can be done only after having started the RPCService)
String name = rpcService.executeCommandOnCoordinator(commandGetName, true);
// Print the name
System.out.println("Name : " + name);

This code:

  1. Register a SingleMethodCallCommand that will call getName() on the Object myService anytime the command is executed.

  2. Execute the command synchronously on the coordinator, assuming that the same command (with the same id) has already been registered on the coordinator.

  3. Print the name received from the coordinator.


  • As any RemoteCommand, the SingleMethodCallCommand has to be registered before being executed and before the RPCService is launched.

  • As any RemoteCommand, the SingleMethodCallCommand can be executed only once the RPCService is launched.

  • The SingleMethodCallCommand allows only public methods, if you try to register a non public method an RPCException will be thrown at creation level.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus