KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Local > RMI > RMILocalCenter


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

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 JavaDoc;
12 import java.rmi.Naming JavaDoc;
13 import java.net.MalformedURLException JavaDoc;
14
15 /**
16  * Managing class of RMI implementation of "local interface" of the SOFAnet.
17  * This interface is used by SOFA runtime.
18  *
19  * @author Ladislav Sobr
20  */

21 public class RMILocalCenter
22 {
23   private LocalOps localOps;
24
25   private RMILocalServer server;
26   
27   boolean started;
28   private String JavaDoc myNodeName;
29   
30   /** Creates a new instance of RMILocalCenter */
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   /** Starts RMI local subsystem */
44   public void start() throws RMILocalException
45   {
46     started = true;
47
48     //run RMI local server
49

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 JavaDoc e)
66     {
67       throw new RMILocalException("RMI local server failed to start", e);
68     }
69     catch (MalformedURLException JavaDoc 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