1 6 7 package SOFA.SOFAnet.Local.RMI; 8 9 import SOFA.SOFAnet.Core.LocalOps; 10 import SOFA.SOFAnet.Repository.NodeInfo; 11 import java.rmi.RemoteException ; 12 import java.rmi.Naming ; 13 import java.net.MalformedURLException ; 14 15 21 public class RMILocalCenter 22 { 23 private LocalOps localOps; 24 25 private RMILocalServer server; 26 27 boolean started; 28 private String myNodeName; 29 30 31 public RMILocalCenter() 32 { 33 started = false; 34 server = null; 35 myNodeName = NodeInfo.getLocalNodeName(); 36 } 37 38 public void setLocalOps(LocalOps localOps) 39 { 40 this.localOps = localOps; 41 } 42 43 44 public void start() throws RMILocalException 45 { 46 started = true; 47 48 50 NodeInfo myNodeInfo = new NodeInfo(); 51 try 52 { 53 myNodeInfo.setNodeName(myNodeName); 54 } 55 catch (NodeInfo.InvalidNodeNameException e) 56 { 57 throw new RMILocalException("Invalid name of local SOFA node: " + myNodeName, e); 58 } 59 60 try 61 { 62 server = new RMILocalServer(localOps); 63 Naming.rebind("//" + myNodeInfo.getAddressAndPort() + "/SOFAnet/RMILocalServer", server); 64 } 65 catch (RemoteException e) 66 { 67 throw new RMILocalException("RMI local server failed to start", e); 68 } 69 catch (MalformedURLException e) 70 { 71 throw new RMILocalException("RMI local server failed to start", e); 72 } 73 } 74 75 boolean isStarted() 76 { 77 return started; 78 } 79 } 80 | Popular Tags |