public static Remote exportObject(Remote obj,
int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf,
Class[] interfaces,
int numSockets) throws RemoteException {
Remote[] stubs = new Remote[numSockets];
Method[] methods = obj.getClass().getMethods();
HashMap invokerMap = new HashMap();
for (int i = 0; i < methods.length; i++) {
Long methodkey = new Long(MethodHash.calculateHash(methods[i]));
invokerMap.put(methodkey, methods[i]);
}
RMIMultiSocketHandler[] handlers = new RMIMultiSocketHandler[numSockets];
for (int i = 0; i < numSockets; i++)
{
int theport = (port == 0) ? 0 : port + i;
handlers[i] = new RMIMultiSocketHandler(obj, invokerMap);
stubs[i] = UnicastRemoteObject.exportObject(handlers[i], theport, csf, ssf);
}
Remote remote = (Remote)Proxy.newProxyInstance(
obj.getClass().getClassLoader(),
interfaces,
new RMIMultiSocketClient(stubs));
stubmap.put(remote, stubs);
handlermap.put(remote, handlers);
return remote;
}
|