Author: cutting
Date: Tue May  3 09:36:01 2005
New Revision: 167929

URL: http://svn.apache.org/viewcvs?rev=167929&view=rev
Log:
Add support for multi-calls to RPC.

Modified:
    incubator/nutch/trunk/src/java/org/apache/nutch/ipc/RPC.java
    incubator/nutch/trunk/src/test/org/apache/nutch/ipc/TestRPC.java

Modified: incubator/nutch/trunk/src/java/org/apache/nutch/ipc/RPC.java
URL: 
http://svn.apache.org/viewcvs/incubator/nutch/trunk/src/java/org/apache/nutch/ipc/RPC.java?rev=167929&r1=167928&r2=167929&view=diff
==============================================================================
--- incubator/nutch/trunk/src/java/org/apache/nutch/ipc/RPC.java (original)
+++ incubator/nutch/trunk/src/java/org/apache/nutch/ipc/RPC.java Tue May  3 
09:36:01 2005
@@ -191,6 +191,25 @@
                                   new Class[] { protocol },
                                   new Invoker(addr));
   }
+
+  /** Make multiple, parallel calls to a set of servers. */
+  public static Object[] call(Method method, Object[][] params,
+                              InetSocketAddress[] addrs)
+    throws IOException {
+
+    Invocation[] invocations = new Invocation[params.length];
+    for (int i = 0; i < params.length; i++)
+      invocations[i] = new Invocation(method, params[i]);
+    
+    Writable[] wrappedValues = CLIENT.call(invocations, addrs);
+    
+    Object[] values =
+      (Object[])Array.newInstance(method.getReturnType(),wrappedValues.length);
+    for (int i = 0; i < values.length; i++)
+      values[i] = ((ObjectWritable)wrappedValues[i]).get();
+    
+    return values;
+  }
   
 
   /** Construct a server for the named instance listening on the named port. */

Modified: incubator/nutch/trunk/src/test/org/apache/nutch/ipc/TestRPC.java
URL: 
http://svn.apache.org/viewcvs/incubator/nutch/trunk/src/test/org/apache/nutch/ipc/TestRPC.java?rev=167929&r1=167928&r2=167929&view=diff
==============================================================================
--- incubator/nutch/trunk/src/test/org/apache/nutch/ipc/TestRPC.java (original)
+++ incubator/nutch/trunk/src/test/org/apache/nutch/ipc/TestRPC.java Tue May  3 
09:36:01 2005
@@ -22,6 +22,7 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.lang.reflect.Method;
 
 import junit.framework.TestCase;
 
@@ -86,9 +87,9 @@
     Server server = RPC.getServer(new TestImpl(), PORT);
     server.start();
 
+    InetSocketAddress addr = new InetSocketAddress(PORT);
     TestProtocol proxy =
-      (TestProtocol)RPC.getProxy(TestProtocol.class,
-                                 new InetSocketAddress(PORT));
+      (TestProtocol)RPC.getProxy(TestProtocol.class, addr);
     
     proxy.ping();
 
@@ -114,9 +115,16 @@
     }
     assertTrue(caught);
 
+    // try a multi-call
+    Method method =
+      TestProtocol.class.getMethod("echo", new Class[] { String.class });
+    String[] values = (String[])RPC.call(method, new String[][]{{"a"},{"b"}},
+                                         new InetSocketAddress[] {addr, addr});
+    assertTrue(Arrays.equals(values, new String[]{"a","b"}));
+
+
     server.stop();
   }
-
   public static void main(String[] args) throws Exception {
     // crank up the volume!
     LOG.setLevel(Level.FINE);




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r 
_______________________________________________
Nutch-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nutch-cvs

Reply via email to