[exo-jcr-commits] exo-jcr SVN: r3746 - in kernel/trunk/exo.kernel.component.common/src: main/java/org/exoplatform/services/rpc/impl and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Dec 28 10:54:29 EST 2010


Author: tolusha
Date: 2010-12-28 10:54:28 -0500 (Tue, 28 Dec 2010)
New Revision: 3746

Modified:
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java
   kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
   kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
Log:
EXOJCR-1128: RPCService support execute command by identifier

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java	2010-12-28 13:19:39 UTC (rev 3745)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java	2010-12-28 15:54:28 UTC (rev 3746)
@@ -106,6 +106,76 @@
       SecurityException;
 
    /**
+    * Executes a command on all the cluster nodes. This method is equivalent to the other method of the
+    * same type but with the default timeout. The command must be registered first otherwise an 
+    * {@link RPCException} will be thrown.
+    *
+    * @param commandId The commandId to execute on each cluster node
+    * @param synchronous if true, sets group request mode to {@link org.jgroups.blocks.GroupRequest#GET_ALL},
+    *  and if false sets it to {@link org.jgroups.blocks.GroupRequest#GET_NONE}.
+    * @param args an array of {@link Serializable} objects corresponding to parameters of the command 
+    * to execute remotely
+    * @return a list of responses from all the members of the cluster. If we met an exception on a given node, 
+    * the RPCException will be the corresponding response of this particular node
+    * @throws RPCException in the event of problems.
+    * @throws SecurityException if the {@link SecurityManager} is installed and the call method
+    * doesn't have the {@link RuntimePermission} <code>ACCESS_RPC_SERVICE_PERMISSION</code>
+    */
+   List<Object> executeCommandOnAllNodes(String commandId, boolean synchronous, Serializable... args)
+      throws RPCException, SecurityException;
+
+   /**
+    * Executes a command synchronously on all the cluster nodes. The command must be registered first otherwise an 
+    * {@link RPCException} will be thrown.
+    *
+    * @param commandId The commandId to execute on each cluster node
+    * @param timeout a timeout after which to throw a replication exception.
+    * @param args an array of {@link Serializable} objects corresponding to parameters of the command 
+    * to execute remotely
+    * @return a list of responses from all the members of the cluster. If we met an exception on a given node, 
+    * the RPCException will be the corresponding response of this particular node
+    * @throws RPCException in the event of problems.
+    * @throws SecurityException if the {@link SecurityManager} is installed and the call method
+    * doesn't have the {@link RuntimePermission} <code>ACCESS_RPC_SERVICE_PERMISSION</code>
+    */
+   List<Object> executeCommandOnAllNodes(String commandId, long timeout, Serializable... args) throws RPCException,
+      SecurityException;
+
+   /**
+    * Executes a command on the coordinator only. This method is equivalent to the other method of the
+    * same type but with the default timeout. The command must be registered first otherwise an 
+    * {@link RPCException} will be thrown.
+    *
+    * @param commandId The commandId to execute on the coordinator node
+    * @param synchronous if true, sets group request mode to {@link org.jgroups.blocks.GroupRequest#GET_ALL}, 
+    * and if false sets it to {@link org.jgroups.blocks.GroupRequest#GET_NONE}.
+    * @param args an array of {@link Serializable} objects corresponding to parameters of the command 
+    * to execute remotely
+    * @return the response of the coordinator.
+    * @throws RPCException in the event of problems.
+    * @throws SecurityException if the {@link SecurityManager} is installed and the call method
+    * doesn't have the {@link RuntimePermission} <code>ACCESS_RPC_SERVICE_PERMISSION</code>
+    */
+   Object executeCommandOnCoordinator(String commandId, boolean synchronous, Serializable... args) throws RPCException,
+      SecurityException;
+
+   /**
+    * Executes a command synchronously on the coordinator only. The command must be registered first otherwise an 
+    * {@link RPCException} will be thrown.
+    *
+    * @param commandId The commandId to execute on the coordinator node
+    * @param timeout a timeout after which to throw a replication exception.
+    * @param args an array of {@link Serializable} objects corresponding to parameters of the command 
+    * to execute remotely
+    * @return the response of the coordinator.
+    * @throws RPCException in the event of problems.
+    * @throws SecurityException if the {@link SecurityManager} is installed and the call method
+    * doesn't have the {@link RuntimePermission} <code>ACCESS_RPC_SERVICE_PERMISSION</code>
+    */
+   Object executeCommandOnCoordinator(String commandId, long timeout, Serializable... args) throws RPCException,
+      SecurityException;
+
+   /**
     * Register a new {@link RemoteCommand} instance, it will be mapped to its id. If a command with the
     * same Id has already been registered, a warning will be printed into the log file and the new
     * command will replace the old one.

Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java	2010-12-28 13:19:39 UTC (rev 3745)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java	2010-12-28 15:54:28 UTC (rev 3746)
@@ -478,6 +478,66 @@
    /**
     * {@inheritDoc}
     */
+   public List<Object> executeCommandOnAllNodes(String commandId, boolean synchronous, Serializable... args)
+      throws RPCException, SecurityException
+   {
+      RemoteCommand command = commands.get(commandId);
+      if (command == null)
+      {
+         throw new RPCException("Command " + commandId + " unkown, please register your command first");
+      }
+
+      return executeCommandOnAllNodes(command, synchronous, args);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public List<Object> executeCommandOnAllNodes(String commandId, long timeout, Serializable... args)
+      throws RPCException, SecurityException
+   {
+      RemoteCommand command = commands.get(commandId);
+      if (command == null)
+      {
+         throw new RPCException("Command " + commandId + " unkown, please register your command first");
+      }
+
+      return executeCommandOnAllNodes(command, timeout, args);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object executeCommandOnCoordinator(String commandId, boolean synchronous, Serializable... args)
+      throws RPCException, SecurityException
+   {
+      RemoteCommand command = commands.get(commandId);
+      if (command == null)
+      {
+         throw new RPCException("Command " + commandId + " unkown, please register your command first");
+      }
+
+      return executeCommandOnCoordinator(command, synchronous, args);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public Object executeCommandOnCoordinator(String commandId, long timeout, Serializable... args) throws RPCException,
+      SecurityException
+   {
+      RemoteCommand command = commands.get(commandId);
+      if (command == null)
+      {
+         throw new RPCException("Command " + commandId + " unkown, please register your command first");
+      }
+
+      return executeCommandOnCoordinator(command, timeout, args);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
    public Object handle(Message msg)
    {
       String commandId = null;
@@ -974,4 +1034,5 @@
          super(message);
       }
    }
+
 }

Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java	2010-12-28 13:19:39 UTC (rev 3745)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java	2010-12-28 15:54:28 UTC (rev 3746)
@@ -50,6 +50,7 @@
    private PortalContainer container;
    private ConfigurationManager configManager;
    
+   @Override
    public void setUp() throws Exception
    {
       container = PortalContainer.getInstance();
@@ -1063,6 +1064,58 @@
       }         
    }
    
+   public void testCallCommandsById() throws Exception
+   {
+      InitParams params = new InitParams();
+      ValueParam paramConf = new ValueParam();
+      paramConf.setName(RPCServiceImpl.PARAM_JGROUPS_CONFIG);
+      paramConf.setValue("jar:/conf/portal/udp.xml");      
+      params.addParameter(paramConf);
+      RPCServiceImpl service = null;
+      try
+      {
+         service = new RPCServiceImpl(container.getContext(), params, configManager);
+         RemoteCommand dummy = new RemoteCommand()
+         {
+            
+            public String getId()
+            {
+               return "dummy";
+            }
+            
+            public String execute(Serializable[] args) throws Throwable
+            {
+               return "OK";
+            }
+         };
+         service.registerCommand(dummy);
+         service.start();
+
+         Object o = service.executeCommandOnCoordinator("dummy", true);
+         assertEquals("OK", o);
+
+         List<Object> result = service.executeCommandOnAllNodes("dummy", true);
+         assertNotNull(result);
+         assertTrue(result.size() == 1);
+         assertEquals(result.get(0), "OK");
+
+         o = service.executeCommandOnCoordinator("dummy", RPCServiceImpl.DEFAULT_TIMEOUT);
+         assertEquals("OK", o);
+
+         result = service.executeCommandOnAllNodes("dummy", RPCServiceImpl.DEFAULT_TIMEOUT);
+         assertNotNull(result);
+         assertTrue(result.size() == 1);
+         assertEquals(result.get(0), "OK");
+      }
+      finally
+      {
+         if (service != null)
+         {
+            service.stop();            
+         }
+      }        
+   }
+
    public static class MyService
    {
       private int value = 0;



More information about the exo-jcr-commits mailing list