KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Deployment > ComponentServerMain


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 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): Briclet Frederic
23 Contributor(s): ___________________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Deployment;
28
29 public class ComponentServerMain extends org.objectweb.openccm.corba.ApplicationServer
30 {
31     
32     // ==================================================================
33
//
34
// Internal state.
35
//
36
// ==================================================================
37

38     /**
39      ** To store the component server name.
40      **/

41     protected String JavaDoc name_ ="ComponentServer";
42
43     // ==================================================================
44
//
45
// Constructor.
46
//
47
// ==================================================================
48

49     /**
50      ** The constructor.
51      **/

52     public
53     ComponentServerMain()
54     {
55     }
56
57
58     // ==================================================================
59
//
60
// Public methods.
61
//
62
// ==================================================================
63

64     /**
65      ** The bootstrap main method.
66      **
67      ** @param args The command-line arguments.
68      **/

69     public static void
70     main(String JavaDoc args[])
71     {
72     ComponentServerMain server = new ComponentServerMain();
73     int status = server.start(args);
74     System.exit(status);
75     }
76
77     // ==================================================================
78
//
79
// Methods for the org.objectweb.openccm.corba.ApplicationServer.
80
//
81
// ==================================================================
82

83     /**
84      ** Before running the CORBA::ORB.
85      **
86      ** @param args The command line arguments.
87      **
88      ** @return The status.
89      **/

90     public int
91     before_run(String JavaDoc[] args)
92     {
93     // Init the OpenCCM Components runtime.
94
try{
95         org.objectweb.openccm.Components.Runtime.init();
96         //org.objectweb.openccm.corba.TheORB.initialize(args);
97
}
98     catch(Exception JavaDoc e){ System.out.println(e.getMessage());}
99     
100     try{
101         //setup componentinstallation for this JVM
102
org.omg.CosNaming.NameComponent JavaDoc[] ncomp
103         = new org.omg.CosNaming.NameComponent JavaDoc[1];
104         
105         ncomp[0]= new org.omg.CosNaming.NameComponent JavaDoc("ComponentInstallation"+args[1],"");
106         
107         org.omg.CORBA.Object JavaDoc obj = org.objectweb.openccm.corba.TheNameService
108         .getNamingContext()
109         .getNamingContext()
110         .resolve(ncomp);
111         
112         org.omg.Components.Deployment.ComponentInstallation server_inst=
113         org.omg.Components.Deployment.ComponentInstallationHelper.narrow(obj);
114         
115         TheComponentInstallation.setComponentInstallation(server_inst);
116         
117     }
118     catch(Exception JavaDoc e)
119         {
120         System.out.println("Cannot retrieves the componentInstallation "+
121                    "ComponentInstallation"+args[1]+e.getMessage());
122     
123         e.printStackTrace();
124         }
125     // Create the server servant.
126

127     org.objectweb.openccm.Components.ConfigValueImpl[] config=
128         new org.objectweb.openccm.Components.ConfigValueImpl[1];
129     org.omg.CORBA.Any JavaDoc any= org.objectweb.openccm.corba.TheORB.getORB().create_any();
130     
131     //store the component server name in config parameter
132
any.insert_string(args[0]+args[1]);
133     config[0]= new org.objectweb.openccm.Components.ConfigValueImpl("ServerName",any);
134     
135     ComponentServerImpl csi = new ComponentServerImpl(config);
136     
137     // Activate it.
138
org.omg.CORBA.Object JavaDoc ref =
139             csi._this_object(org.objectweb.openccm.corba.TheORB.getORB());
140     
141     org.omg.Components.Deployment.ComponentServer serverRef =
142         org.omg.Components.Deployment.ComponentServerHelper.narrow(ref);
143     
144     /* args [0] nom de la machine locale
145      * args[1] non du fichier a ecrire
146      */

147     // Obtain the Name Service.
148
org.objectweb.openccm.corba.NamingContext ns =
149         org.objectweb.openccm.corba.TheNameService.getNamingContext();
150     
151     // Bind the server object in the name service.
152
ns.rebind(args[0]+args[1], serverRef);
153     
154     
155     // Output the IOR of the ComponentServer
156
//org.objectweb.openccm.corba.TheORB.save_IOR(serverRef, args[0]+args[1]);
157

158         
159     System.out.println("The OpenCCM Component Server "+args[0]+" is ready.");
160     System.out.println(org.objectweb.openccm.corba.TheORB.getORB().object_to_string(ref));
161     return 0;
162     }
163     
164     /**
165      ** After running the CORBA::ORB.
166      **/

167     public void
168     after_run()
169     {
170     // Obtain the Name Service.
171
org.objectweb.openccm.corba.NamingContext ns =
172         org.objectweb.openccm.corba.TheNameService.getNamingContext();
173     
174     // Unbind the server object from the name service.
175
ns.unbind(name_);
176     }
177     
178 }
179
Popular Tags