package com.jqmobile.core.server.rmi;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public final class RmiService {
private static RmiRemoteImpl impl;
static{
try {
impl = new RmiRemoteImpl();
} catch (RemoteException e) {
e.printStackTrace();
}
}
private RmiService(){
}
// public static void openRmi() throws RemoteException{
// openRmi(9700);
// }
// public static void openRmi(int port) throws RemoteException{
//// System.setProperty("java.rmi.server.hostname", Application.getApplication().getRmiProperties())
// Registry r = LocateRegistry.createRegistry(port);
// r.rebind(IRmiRemote.class.getName(), impl);
// }
public static void openRmi(String ip, int port) throws RemoteException{
Registry r;
if(null != ip && !ip.isEmpty()){
System.setProperty("java.rmi.server.hostname", ip);
LocateRegistry.createRegistry(port);
r=LocateRegistry.getRegistry(ip, port);
// r = LocateRegistry.createRegistry(ip, port);
}else{
r = LocateRegistry.createRegistry(port);//createRegistry(port);
}
r.rebind(IRmiRemote.class.getName(), new RmiRemoteImpl());
// String ip = InetAddress.getLocalHost().getHostAddress();
// Registry registry = LocateRegistry.getRegistry(ip, 8846);
// xgisXPubRMIConnectionServerSend obj2 = new xgisXPubRMIConnectionServerSend(ip, 8849);
// xgisXPubRMIConnectionServe stub2 = (xgisXPubRMIConnectionServe) UnicastRemoteObject.exportObject(obj2, 0);
// registry.bind("xgisClient2", stub2);
}
}