KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > NetNode


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

6
7 package SOFA.SOFAnet;
8
9 import SOFA.SOFAnet.Repository.Repository;
10 import SOFA.SOFAnet.Repository.NodeInfo;
11 import SOFA.SOFAnet.TR.TRInterface;
12 import SOFA.SOFAnet.TR.Local.TRWrapper;
13 import SOFA.SOFAnode.TR.TRException;
14 import SOFA.SOFAnet.Core.*;
15 import SOFA.SOFAnet.Transport.TransportInterface;
16 import SOFA.SOFAnet.Transport.RMI.RMITransportCenter;
17 import SOFA.SOFAnet.Transport.RMI.RMITransportException;
18 import SOFA.SOFAnet.Local.RMI.RMILocalCenter;
19 import SOFA.SOFAnet.Local.RMI.RMILocalException;
20 import SOFA.SOFAnet.Admin.RMI.RMIAdminCenter;
21 import SOFA.SOFAnet.Admin.RMI.RMIAdminException;
22 import SOFA.SOFAnet.Search.SearchInterface;
23 import SOFA.SOFAnet.Search.RMI.RMISearchCenter;
24 import SOFA.SOFAnet.Search.RMI.RMISearchException;
25 import SOFA.Util.VMProperties;
26 import java.rmi.RMISecurityManager JavaDoc;
27 import java.io.File JavaDoc;
28 import java.net.InetAddress JavaDoc;
29 import java.net.UnknownHostException JavaDoc;
30
31 /**
32  * Instance of SOFAnet node with:
33  * <ul>
34  * <li>local Template Repository (this JVM)
35  * <li>RMI transport layer
36  * <li>RMI search subsystem
37  * <li>RMI interface for SOFA runtime ("Local interface")
38  * <li>RMI admin interface for Node Browser ("Admin interface")
39  * </ul>
40  *
41  * @author Ladislav Sobr
42  */

43 public class NetNode
44 {
45   private Repository rep;
46   private TRInterface tr;
47   private TransportInterface transport;
48   private SearchInterface search;
49   private LocalOps localOps;
50   private NetOps netOps;
51   private ShareOps shareOps;
52   private SearchOps searchOps;
53   
54   private RMITransportCenter rmiTransportCenter;
55   private RMISearchCenter rmiSearchCenter;
56   private RMILocalCenter rmiLocalCenter;
57   private RMIAdminCenter rmiAdminCenter;
58   
59   /**
60    * Creates a new instance of SOFA net node.
61    *
62    * @param infoBaseDir SOFAnet repository: directory for general information (must exist)
63    * @param binBundlesDir SOFAnet repository: directory for binary bundles (must exist)
64    * @param shareClientCacheDir SOFAnet repository: directory for binary bundles in cache of share client (must exist)
65    */

66   public NetNode(File JavaDoc trDir, File JavaDoc infoBaseDir, File JavaDoc binBundlesDir, File JavaDoc shareClientCacheDir)
67   {
68     System.setSecurityManager(new RMISecurityManager JavaDoc());
69     
70     try
71     {
72       rep = new Repository(infoBaseDir, binBundlesDir, shareClientCacheDir);
73       tr = new TRWrapper(trDir.getPath());
74       
75       localOps = new LocalOps();
76       netOps = new NetOps();
77       shareOps = new ShareOps();
78       searchOps = new SearchOps();
79       
80       rmiTransportCenter = new RMITransportCenter();
81       rmiSearchCenter = new RMISearchCenter();
82       rmiLocalCenter = new RMILocalCenter();
83       rmiAdminCenter = new RMIAdminCenter();
84       
85       transport = rmiTransportCenter.getTransportInterface();
86       search = rmiSearchCenter.getSearchInterface();
87       
88       localOps.setRepository(rep);
89       localOps.setTRInterface(tr);
90       localOps.setNetOps(netOps);
91       localOps.setShareOps(shareOps);
92       localOps.setSearchOps(searchOps);
93       localOps.setTransportInterface(transport);
94       
95       netOps.setRepository(rep);
96       netOps.setLocalOps(localOps);
97       netOps.setShareOps(shareOps);
98       netOps.setTransportInterface(transport);
99       
100       shareOps.setRepository(rep);
101       shareOps.setLocalOps(localOps);
102       shareOps.setTransportInterface(transport);
103       
104       searchOps.setRepository(rep);
105       searchOps.setLocalOps(localOps);
106       searchOps.setSearchInterface(search);
107       
108       rmiTransportCenter.setNetOps(netOps);
109       rmiTransportCenter.setShareOps(shareOps);
110       
111       rmiSearchCenter.setRepository(rep);
112       rmiSearchCenter.setSearchOps(searchOps);
113       
114       rmiLocalCenter.setLocalOps(localOps);
115
116       rmiAdminCenter.setRepository(rep);
117       rmiAdminCenter.setTRInterface(tr);
118       rmiAdminCenter.setLocalOps(localOps);
119       rmiAdminCenter.setNetOps(netOps);
120       rmiAdminCenter.setShareOps(shareOps);
121       rmiAdminCenter.setSearchOps(searchOps);
122       rmiAdminCenter.setRMISearchCenter(rmiSearchCenter);
123     }
124     catch (TRException e)
125     {
126       Reporter.error(e);
127     }
128   }
129
130   public void start()
131   {
132     Reporter.startInfo("Starting SOFAnet node " + NodeInfo.getLocalNodeName());
133     boolean ok = false;
134     
135     try
136     {
137       rmiTransportCenter.start();
138       rmiSearchCenter.start();
139       rmiLocalCenter.start();
140       rmiAdminCenter.start();
141       ok = true;
142     }
143     catch (RMITransportException e)
144     {
145       Reporter.error(e);
146     }
147     catch (RMISearchException e)
148     {
149       Reporter.error(e);
150     }
151     catch (RMILocalException e)
152     {
153       Reporter.error(e);
154     }
155     catch (RMIAdminException e)
156     {
157       Reporter.error(e);
158     }
159     
160     if (ok) Reporter.stopInfo("SOFAnet node successfully started");
161   }
162   
163   /**
164    * Main for starting SOFAnet node.
165    *
166    * @param args the command line arguments
167    */

168   public static void main(String JavaDoc[] args)
169   {
170     String JavaDoc nodeName = System.getProperty(VMProperties.NODE_NAME, null);
171     String JavaDoc trDir = System.getProperty(VMProperties.TR_DIR, null);
172     String JavaDoc infoBaseDir = System.getProperty(VMProperties.NET_INFO_BASE_DIR, null);
173     String JavaDoc binBundlesDir = System.getProperty(VMProperties.NET_BIN_BUNDLES_DIR, null);
174     String JavaDoc shareClientCacheDir = System.getProperty(VMProperties.NET_SHARE_CLIENT_CACHE_DIR, null);
175     String JavaDoc showDetailedExceptionsString = System.getProperty(VMProperties.NET_SHOW_DETAILED_EXCEPTIONS, "false");
176
177     if (nodeName == null || nodeName.trim().length() == 0)
178     {
179       try
180       {
181         nodeName = InetAddress.getLocalHost().getHostName();
182       }
183       catch (UnknownHostException JavaDoc e)
184       {
185         System.err.println("Can't get the host name.\nSet the name to the property '" + VMProperties.NODE_NAME + "' when NetNode is being started.");
186         System.exit(1);
187       }
188       
189       String JavaDoc rmiPort = System.getProperty(VMProperties.RMI_PORT, null);
190       
191       if (rmiPort != null) nodeName += ":" + rmiPort;
192       
193       System.out.println("The property '" + VMProperties.NODE_NAME + "' has not been specified, using '" + nodeName + "'");
194       System.setProperty(VMProperties.NODE_NAME, nodeName);
195     }
196
197     if (trDir == null)
198     {
199       System.out.println("The property '" + VMProperties.TR_DIR + "' has not been specified.");
200       System.exit(1);
201     }
202
203     if (infoBaseDir == null)
204     {
205       System.out.println("The property '" + VMProperties.NET_INFO_BASE_DIR + "' has not been specified.");
206       System.exit(1);
207     }
208
209     if (binBundlesDir == null)
210     {
211       System.out.println("The property '" + VMProperties.NET_BIN_BUNDLES_DIR + "' has not been specified.");
212       System.exit(1);
213     }
214
215     if (shareClientCacheDir == null)
216     {
217       System.out.println("The property '" + VMProperties.NET_SHARE_CLIENT_CACHE_DIR + "' has not been specified.");
218       System.exit(1);
219     }
220
221     if (showDetailedExceptionsString.compareTo("1") == 0 || showDetailedExceptionsString.compareTo("true") == 0)
222     {
223       Reporter.setShowDetailedExceptions(true);
224     }
225     
226     NetNode netNode = new NetNode(new File JavaDoc(trDir), new File JavaDoc(infoBaseDir), new File JavaDoc(binBundlesDir), new File JavaDoc(shareClientCacheDir));
227     
228     netNode.start();
229   }
230 }
231
Popular Tags