1 6 7 package SOFA.SOFAnet.Transport.RMI; 8 9 import SOFA.SOFAnet.Transport.*; 10 import SOFA.SOFAnet.Core.NetOps; 11 import SOFA.SOFAnet.Core.ShareOps; 12 import SOFA.SOFAnet.Repository.NodeInfo; 13 import java.rmi.RemoteException ; 14 import java.rmi.Naming ; 15 import java.net.MalformedURLException ; 16 17 22 public class RMITransportCenter 23 { 24 private NetOps netOps; 25 private ShareOps shareOps; 26 27 private RMITransportClient client; 28 private RMITransportServer server; 29 30 boolean started; 31 private String myNodeName; 32 33 34 public RMITransportCenter() 35 { 36 started = false; 37 38 client = new RMITransportClient(); 39 server = null; 40 41 myNodeName = NodeInfo.getLocalNodeName(); 42 } 43 44 public void setNetOps(NetOps netOps) 45 { 46 this.netOps = netOps; 47 client.setNetOps(netOps); 48 } 49 50 public void setShareOps(ShareOps shareOps) 51 { 52 this.shareOps = shareOps; 53 client.setShareOps(shareOps); 54 } 55 56 public TransportInterface getTransportInterface() 57 { 58 return client; 59 } 60 61 62 public void start() throws RMITransportException 63 { 64 started = true; 65 66 68 NodeInfo myNodeInfo = new NodeInfo(); 69 try 70 { 71 myNodeInfo.setNodeName(myNodeName); 72 } 73 catch (NodeInfo.InvalidNodeNameException e) 74 { 75 throw new RMITransportException("Invalid name of local SOFA node: " + myNodeName, e); 76 } 77 78 try 79 { 80 server = new RMITransportServer(netOps, shareOps); 81 Naming.rebind("//" + myNodeInfo.getAddressAndPort() + "/SOFAnet/RMITransportServer", server); 82 } 83 catch (RemoteException e) 84 { 85 throw new RMITransportException("RMI transport server failed to start", e); 86 } 87 catch (MalformedURLException e) 88 { 89 throw new RMITransportException("RMI transport server failed to start", e); 90 } 91 } 92 93 boolean isStarted() 94 { 95 return started; 96 } 97 } 98 | Popular Tags |