KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > InOut > Impl > Main


1 /**
2  * Main.java is a part of the SOFA project.
3  * This file was created by pepan on 2.4.2003.
4  */

5 package SOFA.SOFAnode.InOut.Impl;
6
7 import java.net.InetAddress JavaDoc;
8 import java.net.UnknownHostException JavaDoc;
9 import java.rmi.RMISecurityManager JavaDoc;
10
11 import SOFA.Connector.ConnectorException;
12 import SOFA.Connector.Reference;
13 import SOFA.SOFAnode.InOut.Connector.InOut2ClientConnector;
14 import SOFA.SOFAnode.InOut.Connector.InOut2InOutConnector;
15 import SOFA.Util.VMProperties;
16
17 /**
18  * Runs the InOut part of a SOFA node. Allows two ways to run in - either if the <code>main</code>
19  * method is used, then an RMI connector to TR is created, or the <code>runInOut</code> method is used,
20  * then the local reference to TR can be provided.
21  * @author Petr Panuska
22  */

23 public class Main {
24
25   /**
26    * Runs InOut part of a SOFA node and connects it to its TR through an RMI connector.
27    * @param argv no command parameters are to be expected. However, system properties
28    * {@link VMProperties#RMI_HOST}, {@link VMProperties#RMI_PORT} and {@link VMProperties#TR_NAME}
29    * according to the running TR may be specified. If not, the default values ('localhost', '1099' and
30    * 'localTR') are used instead.
31    */

32   public static void main (String JavaDoc[] argv) {
33     if (System.getSecurityManager() == null) {
34       System.setSecurityManager(new RMISecurityManager JavaDoc());
35     }
36     String JavaDoc rmiHost = System.getProperty(VMProperties.RMI_HOST, "localhost");
37     String JavaDoc rmiPort = System.getProperty(VMProperties.RMI_PORT, "1099");
38     String JavaDoc trName = System.getProperty(VMProperties.TR_NAME, "localTR");
39     runInOut(null, "SOFA.Connector.ECG.SGenerator.Connectors.DeplDockConnector-RMI;//"
40       + rmiHost + ":" + rmiPort + "/SOFA/SOFAnode/TR/Connector/TR2InOutRMISkel/" + trName + "-");
41   }
42
43   /**
44    * Runs InOut server. Just one parameter is set, the second one must be <code>null</code>.
45    * @param trRef local reference to TR. If used, this InOut server is run in the same address space as
46    * this TR - the connector uses a local connection.
47    * @param referenceString a string form of a connector - remote reference to TR. If used,
48    * this InOut server is run in a different address space than this TR - the connector uses
49    * an RMI connection.
50    */

51   public static void runInOut (Reference trRef, String JavaDoc referenceString) {
52     try {
53       InOutImpl inOut = null;
54       if (trRef == null) {
55         String JavaDoc sofaNodeName = System.getProperty(VMProperties.NODE_NAME);
56
57         if (sofaNodeName == null) {
58           try {
59             sofaNodeName = InetAddress.getLocalHost().getHostName();
60           } catch (UnknownHostException JavaDoc e) {
61             System.err.println("Can't get the host name.\nSet the name to the property '" + VMProperties.NODE_NAME + "' when TR is being started.");
62             System.exit(1);
63           }
64         }
65
66         System.setProperty(VMProperties.NODE_NAME, sofaNodeName);
67
68         inOut = new InOutImpl(Reference.fromString(referenceString));
69       } else
70         inOut = new InOutImpl(trRef);
71
72       System.out.print("Registering InOut2Client....");
73       Reference refInOut = InOut2ClientConnector.createSrv(inOut).getSOFAReference();
74       System.out.println("OK");
75       System.out.println(refInOut);
76
77       System.out.print("Registering InOut2InOut....");
78       refInOut = InOut2InOutConnector.createSrv(inOut).getSOFAReference();
79       System.out.println("OK");
80       System.out.println(refInOut);
81
82     } catch (ConnectorException e) {
83       System.out.println("Exception " + e.getMessage());
84       e.printStackTrace();
85     }
86 /*
87 // todo following code is here for testing purposes only
88     try {
89
90       FileInputStream fis = new FileInputStream("c:\\ww\\t.tmp");
91       byte[] buffer = new byte[fis.available()];
92       fis.read(buffer);
93       fis.close();
94       ByteArrayInputStream bis = new ByteArrayInputStream(buffer);
95
96       Reference refTR = new Reference();
97       refTR._read(bis);
98       bis.close();
99
100       InOut2InOut inOut = new InOutImpl(refTR);
101 // inOut.distributeComponent("::CUNI::SOFA::demos::logdemo::Logger[0.0.2]", null);
102       ComponentInfo[] infos = {
103         new ComponentInfoImpl("::CUNI::SOFA::demos::cplayer::ReadingUnit", "0.0.1"),
104         new ComponentInfoImpl("::CUNI::SOFA::demos::logdemo::Tester", "0.0.1"),
105         new ComponentInfoImpl("::CUNI::SOFA::demos::protodemo::LoggingWorker", "0.0.1"),
106       };
107       Bundle bundle = inOut.pullBundle(infos);
108       inOut.pushBundle(bundle);
109
110     } catch (Exception e) {
111       e.printStackTrace();
112       System.exit(-1);
113     }
114 */

115   }
116 }
117
Popular Tags