@@ -0,0 +1,2216 @@
+package com.ouc.cs;%0A%0Aimport java.io.IOException;%0Aimport java.io.ObjectInputStream;%0Aimport java.io.ObjectOutputStream;%0Aimport java.lang.reflect.Method;%0Aimport java.net.InetSocketAddress;%0Aimport java.net.ServerSocket;%0Aimport java.net.Socket;%0Aimport java.util.concurrent.Executor;%0Aimport java.util.concurrent.Executors;%0A%0A// RPC %E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%9C%8D%E5%8A%A1%E5%8F%91%E5%B8%83%E8%80%85%0Apublic class RpcExporter %7B%0A    static Executor executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());%0A    public static void exporter(String hostName, int port) throws Exception %7B%0A    %09ServerSocket server = new ServerSocket();%0A    %09server.bind(new InetSocketAddress(hostName, port));%0A    %09try %7B%0A    %09%09while (true) %7B%0A    %09%09%09executor.execute(new ExporterTask(server.accept()));%0A    %09%09%7D%0A    %09%7D finally %7B%0A    %09%09server.close();%0A    %09%7D%0A    %7D%0A    %0A    private static class ExporterTask implements Runnable %7B%0A    %09Socket client = null;%0A    %09public ExporterTask(Socket client) %7B%0A    %09%09this.client = client;%0A    %09%7D%0A    %09%0A    %09@Override%0A    %09public void run() %7B%0A    %09%09ObjectInputStream input = null;%0A    %09%09ObjectOutputStream output = null;%0A    %09%09try %7B%0A    %09%09%09input = new ObjectInputStream(client.getInputStream());%0A    %09%09%09String interfaceName = input.readUTF();%0A    %09%09%09Class%3C?%3E service = Class.forName(interfaceName);%0A    %09%09%09String methodName = input.readUTF();%0A    %09%09%09Class%3C?%3E%5B%5D parameterTypes = (Class%3C?%3E%5B%5D)input.readObject();%0A    %09%09%09Object%5B%5D arguments = (Object%5B%5D)input.readObject();%0A    %09%09%09Method method = service.getMethod(methodName, parameterTypes);%0A    %09%09%09Object result = method.invoke(service.newInstance(), arguments);%0A    %09%09%09output = new ObjectOutputStream(client.getOutputStream());%0A    %09%09%09output.writeObject(result);%0A    %09%09%7D catch (Exception e) %7B%0A    %09%09%09e.printStackTrace();%0A    %09%09%7D finally %7B%0A    %09%09%09if (output != null) %0A    %09%09%09%09try %7B%0A    %09%09%09%09%09output.close();%0A    %09%09%09%09%7D catch (IOException ioe) %7B%0A    %09%09%09%09%09ioe.printStackTrace();%0A    %09%09%09%09%7D%0A    %09%09%09if (input != null) %0A    %09%09%09%09try %7B%0A    %09%09%09%09%09input.close();%0A    %09%09%09%09%7D catch (IOException ioe) %7B%0A    %09%09%09%09%09ioe.printStackTrace();%0A    %09%09%09%09%7D%0A    %09%09%09if (client != null) %0A    %09%09%09%09try %7B%0A    %09%09%09%09%09client.close();%0A    %09%09%09%09%7D catch (IOException ioe) %7B%0A    %09%09%09%09%09ioe.printStackTrace();%0A    %09%09%09%09%7D%0A    %09%09%7D%0A    %09%7D%0A    %7D%0A%7D %0A

Create RpcExporter.java