KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > OpenCCM_DCI > cif > ServerActivatorImpl


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
28
29 package org.objectweb.openccm.OpenCCM_DCI.cif;
30
31 import org.objectweb.openccm.OpenCCM_DCI.*;
32 import org.objectweb.openccm.corba.*;
33
34 /**
35  * This is the implementation of the ServerActivator facet
36  * provided by the node component.
37  *
38  * This class inherits from the skeleton
39  * generated by the OpenCCM's CIF to Java mapping generator.
40  *
41  * @author <a HREF="mailto:Frederic.Briclet@lifl.fr">Briclet Frederic</A>
42  */

43 public class ServerActivatorImpl
44        extends org.objectweb.openccm
45                 .OpenCCM_DCI.NodeManagerSessionComposition
46                 .ServerActivatorSeg
47 {
48    // ==================================================================
49
//
50
// Internal state.
51
//
52
// ==================================================================
53

54     /*Last attributed component server number */
55     private int last_cs_num;
56     
57     /*Table for storage of cs*/
58     private java.util.Hashtable JavaDoc c_servers;
59     
60     /*Table for storage of each component server*/
61     private java.util.Hashtable JavaDoc process;
62     
63      /* The parent NodeManager component which keep all connection*/
64     private org.objectweb.openccm.OpenCCM_DCI.NodeManagerCCM node;
65
66     // ==================================================================
67
//
68
// Internal methods.
69
//
70
// ==================================================================
71

72     private org.objectweb.openccm.OpenCCM_DCI.NodeManagerCCM
73     getNode()
74     {
75         if(node==null)
76              this.node=(org.objectweb.openccm
77                        .OpenCCM_DCI.NodeManagerCCM)get_context();
78         return node;
79     }
80     // ==================================================================
81
//
82
// Constructor.
83
//
84
// ==================================================================
85
/**
86      * Main constructor of ServerActivator
87      */

88     public ServerActivatorImpl(){
89         //super();
90
last_cs_num=0;
91         c_servers= new java.util.Hashtable JavaDoc();
92         process=new java.util.Hashtable JavaDoc();
93           
94      }
95     // ==================================================================
96
//
97
// Public methods.
98
//
99
// ==================================================================
100

101     /**
102      * Operation create_component_server :
103      * Three main steps build are lead in this method :
104      * - Build arguments for the command to execute
105      * - Build a new launcher (with this argument)
106      * whitch start the Component Server
107      * - Retrieve information ComponentServer reference and process
108      *
109      * @param config The configvalue to use to configure the component server
110      * @return The componentserver created
111      *
112      * TODO: Consider the config value
113      * WARNING : TODO change the connect operation with node manager using
114      * the context with
115      * node.get_context().get_CCM_object().connect(.....)
116      */

117     public
118     org.omg.Components.Deployment.ComponentServer
119     create_component_server(org.omg.Components.ConfigValue[] config)
120     throws org.omg.Components.CreateFailure,
121            org.omg.Components.Deployment.InvalidConfiguration
122     {
123         org.omg.Components.Deployment.ComponentServer server=null;
124         try{
125                       
126             //Build the name of new Component Server base on a number
127
String JavaDoc server_name="ComponentServer"+last_cs_num++;
128             
129             org.objectweb.openccm.Components.ConfigValueImpl[] config1=
130                 new org.objectweb.openccm.Components.ConfigValueImpl[1];
131             
132             org.omg.CORBA.Any JavaDoc any=
133                 org.objectweb.openccm.corba.TheORB.getORB().create_any();
134             
135             //store the component server name in config parameter
136
any.insert_string(server_name);
137             config1[0]= new org.objectweb.openccm.Components.ConfigValueImpl("ServerName",any);
138             //Retrieve the ComponentServerManagerHome
139
ComponentServerManagerHome cshome=
140                 getNode().get_connection_component_server_manager_home();
141             //create a ComponentServerManager
142
org.objectweb.openccm.OpenCCM_DCI.ComponentServerManager csm=
143                 cshome.create();
144             //configure the componentServer
145
csm.config(config1);
146             
147             //connect the registration interface
148
csm.connect_component_server_manager_registration
149                 (getNode().provide_component_server_manager_registration());
150             //connect the parent server activator interface
151
csm.connect_parent_server_activator
152                 (getNode().provide_server_activator());
153             //connect the ContainerManagerHome
154
csm.connect_container_manager_home
155                 (getNode().get_connection_container_manager_home());
156             //connect the ComponentInstallation to use
157
csm.connect_component_installation
158                 (getNode().provide_component_installation());
159             //configure complete the ComponentServerManager
160
csm.configuration_complete();
161             //return the componentserver interface
162
return csm.provide_component_server();
163             }
164        catch(Exception JavaDoc e)
165            {
166                e.printStackTrace();
167                throw new org.omg.Components.CreateFailure();
168            }
169     }
170
171     /**
172      * Operation remove_component_server, by stoping him and killing
173      * his process.
174      * The component server give in parameter must be created by
175      * this Server Activator
176      * else a RemoveFailure exception will be raise.
177      * Call the remove() function on the server pass to parameter.
178      *
179      * @param server The component server to remove
180      */

181     public void
182     remove_component_server(
183                             org.omg.Components
184                             .Deployment.ComponentServer server)
185         throws org.omg.Components.RemoveFailure
186     {
187             
188       /* //Retrive configuration informations
189         org.omg.Components.ConfigValue[] config =server.configuration();
190         // the first config value of component server must be component server name
191         if(!config[0].name.equals("ServerName"))
192             throw new org.omg.Components.RemoveFailure();
193         // test if this Component server was start by this Server Activator
194         if(!c_servers.containsKey(config[0].value.extract_string()))
195             throw new org.omg.Components.RemoveFailure();
196         
197         try{
198             //Start the removing processing for the component server
199             server.remove();
200             //remove the reference of the process
201             //Process p=(Process)process.remove(config[0].value.extract_string());
202             //Remove the reference of the component server
203             //c_servers.remove(config[0].value.extract_string());
204             //Kill the process
205             //p.destroy();
206            }
207         catch(Exception e){e.printStackTrace();
208                           System.out.println(e.getMessage());
209                           }*/

210
211         org.objectweb.openccm.OpenCCM_DCI.
212             NodeManagerPackage.component_server_managersConnection
213             connect[]=getNode().get_connections_component_server_managers();
214         
215         for(int i=0;i<connect.length;i++)
216             if(connect[i].objref.
217                provide_component_server().
218                _is_equivalent(server))
219                 {
220                     connect[i].objref.remove();
221                     return ;
222                 }
223         throw new org.omg.Components.RemoveFailure();
224     }
225     
226     
227     /**
228      * Operation get_component_servers: Return a set of all active
229      * components servers
230      * created by this Server Activator
231      *
232      *@return An array of the running componentServer.
233      */

234     public org.omg.Components.Deployment.ComponentServer[]
235     get_component_servers()
236     {
237         
238         /* c_servers.values().toArray(
239                    new org.omg.Components.Deployment.
240                    ComponentServer[c_servers.size()]);*/

241         
242         org.objectweb.openccm.OpenCCM_DCI.
243             NodeManagerPackage.component_server_managersConnection
244             connect[]=getNode().get_connections_component_server_managers();
245        
246         org.omg.Components.Deployment.ComponentServer[] cs=
247             new org.omg.Components.Deployment.ComponentServer[connect.length];
248         
249         for(int i=0;i<connect.length;i++)
250             cs[i]=connect[i].objref.provide_component_server();
251         
252         return cs;
253         // return null;
254
}
255
256     /**
257      * Remove the ServerActivator including all the started component servers
258      */

259      public void
260      remove()
261      throws org.omg.Components.RemoveFailure
262      {
263         org.objectweb.openccm.OpenCCM_DCI.
264             NodeManagerPackage.component_server_managersConnection
265             connect[]=getNode().get_connections_component_server_managers();
266         
267         for(int i=0;i<connect.length;i++)
268         {
269             connect[i].objref.remove();
270         }
271      }
272 }
273
Popular Tags