KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > corba > latency > Server


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): Gael Harbonnier.
24
25 ====================================================================*/

26
27 package org.objectweb.benchmark.corba.latency;
28
29 // Package dependencies.
30
import java.io.InputStream JavaDoc;
31 import java.util.Properties JavaDoc;
32
33 import org.omg.CORBA.ORB JavaDoc;
34 import org.omg.PortableServer.POA JavaDoc;
35 import org.omg.PortableServer.POAHelper JavaDoc;
36
37 /**
38  * This is the Hello CORBA server.
39  *
40  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
41  *
42  * @version 0.1
43  */

44 public class Server
45 {
46     // ==================================================================
47
//
48
// Internal states.
49
//
50
// ==================================================================
51

52     // ==================================================================
53
//
54
// Constructors.
55
//
56
// ==================================================================
57

58     /**
59      * The default constructor.
60      */

61     public Server()
62     {
63         try{
64             Properties JavaDoc properties = new Properties JavaDoc();
65             InputStream JavaDoc propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties");
66             properties.load(propStream);
67         } catch (Exception JavaDoc e) {
68             e.printStackTrace();
69         }
70     }
71
72     // ==================================================================
73
//
74
// Internal methods.
75
//
76
// ==================================================================
77

78     /**
79      * Inits ORB properties.
80      */

81     private void init_orb()
82     {
83         try {
84             java.io.InputStream JavaDoc propStream = null;
85
86             propStream = getClass().getClassLoader().getResourceAsStream("ORB.properties");
87             System.getProperties().load(propStream);
88         } catch (Exception JavaDoc e) {
89             e.printStackTrace();
90         }
91     }
92     
93     // ==================================================================
94
//
95
// Public methods.
96
//
97
// ==================================================================
98

99     /**
100      * Runs the Server.
101      */

102     public void run()
103     {
104         try{
105             // Inits the ORB
106
init_orb();
107             ORB JavaDoc orb = ORB.init(new String JavaDoc[0], null);
108
109             // Gets Root POA
110
org.omg.CORBA.Object JavaDoc rootobj = orb.resolve_initial_references("RootPOA");
111             POA JavaDoc rootpoa = POAHelper.narrow(rootobj);
112             rootpoa.the_POAManager().activate();
113
114             // Instanciates new CORBA Object
115
PingImpl servant = new PingImpl(orb);
116             org.omg.CORBA.Object JavaDoc obj = rootpoa.servant_to_reference(servant);
117       
118             // Publishes CORBA Object IOR
119
String JavaDoc ior = orb.object_to_string(obj);
120             IORServer iorServer = new IORServer(ior);
121             iorServer.listen();
122
123             // Waits for requests
124
System.out.println( "The CORBA server is running ..." );
125             orb.run();
126         }catch(Exception JavaDoc ex){
127             ex.printStackTrace();
128         }
129     }
130
131     /**
132      * The bootstrap method.
133      *
134      * @param args - Application arguments
135      */

136     public static void main(String JavaDoc[] args)
137     {
138         Server serv = new Server();
139         serv.run();
140     }
141 }
142
Popular Tags