1 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 ; 27 import java.io.File ; 28 import java.net.InetAddress ; 29 import java.net.UnknownHostException ; 30 31 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 66 public NetNode(File trDir, File infoBaseDir, File binBundlesDir, File shareClientCacheDir) 67 { 68 System.setSecurityManager(new RMISecurityManager ()); 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 168 public static void main(String [] args) 169 { 170 String nodeName = System.getProperty(VMProperties.NODE_NAME, null); 171 String trDir = System.getProperty(VMProperties.TR_DIR, null); 172 String infoBaseDir = System.getProperty(VMProperties.NET_INFO_BASE_DIR, null); 173 String binBundlesDir = System.getProperty(VMProperties.NET_BIN_BUNDLES_DIR, null); 174 String shareClientCacheDir = System.getProperty(VMProperties.NET_SHARE_CLIENT_CACHE_DIR, null); 175 String 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 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 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 (trDir), new File (infoBaseDir), new File (binBundlesDir), new File (shareClientCacheDir)); 227 228 netNode.start(); 229 } 230 } 231 | Popular Tags |