KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Transport > RMI > RMITransportCenter


1 /*
2  * RMITransportCenter.java
3  *
4  * Created on 3. květen 2004, 16:41
5  */

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 JavaDoc;
14 import java.rmi.Naming JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16
17 /**
18  * Managing class of RMI implementation of transport subsystem of the SOFAnet.
19  *
20  * @author Ladislav Sobr
21  */

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 JavaDoc myNodeName;
32   
33   /** Creates a new instance of RMITransportCenter */
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   /** Starts RMI transport subsystem */
62   public void start() throws RMITransportException
63   {
64     started = true;
65     
66     //run RMI transport server
67

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 JavaDoc e)
84     {
85       throw new RMITransportException("RMI transport server failed to start", e);
86     }
87     catch (MalformedURLException JavaDoc 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