KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > installer > HomeplacementDeployer


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): Briclet Frederic
23 Contributor(s): Philippe Merle
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer;
28
29 //import the needed packages
30
import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.*;
31 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.registrar.*;
32 import org.objectweb.openccm.descriptor.componentassembly.*;
33 import org.omg.Components.CCMHome;
34
35
36 /**
37  * HomeplacementDeployer installs a home and configure it. Il also browse
38  * all the componentinstantiation to build.
39  *
40  * @author <a HREF="mailto:frederic.briclet@lifl.fr">Briclet Frederic</a>
41  *
42  * @version 0.1
43  */

44 public class HomeplacementDeployer extends HomeplacementDeployerContext{
45     
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51
/*Internal exception for deployment managing*/
52     private class CannotSetupHomeException extends Exception JavaDoc{};
53     /*The installed home*/
54     private org.omg.Components.CCMHome homePlaced;
55     /*Descriptor containing the path to ccd file*/
56     private org.objectweb.openccm.descriptor.softpkg.Descriptor descriptor;
57
58     // ==================================================================
59
//
60
// Constructor.
61
//
62
// ==================================================================
63
// ==================================================================
64
//
65
// private methods.
66
//
67
// ==================================================================
68

69     
70     /**
71      * Setup the dependencies defined in softpkg tags
72      *
73      * @throws FatalDeploymentException if a fatal problem occured
74      */

75     private void
76     setupSoftpkgDependency()
77     throws FatalDeploymentException
78     {
79         getDestinationDeployer().resolveDependency();
80     
81     }
82
83     /**
84      * Internal method in charge to setup the container and to create the home.
85      *
86      * @throws FatalDeploymentException if a fatal error occured
87      * @throws CannotSetupHomeexception if the home cannot be placed
88      */

89     private org.omg.Components.CCMHome
90     setupHome()
91     throws FatalDeploymentException,
92            CannotSetupHomeException
93     
94     {
95         try {
96                
97             return getDestinationDeployer().installHome();
98                
99             }catch(Error JavaDoc err){System.out.println(err.getMessage());}
100         
101         throw new CannotSetupHomeException();
102     }
103     /**
104      * Internal method to make home registration
105      *
106      * @throws FatalDeploymentException if a fatal problem occured
107      */

108     private void
109     proceedHomeRegistration()
110     throws FatalDeploymentException
111     {
112          traverse(this,getRegisterwithnamingDeployers());
113          traverse(this,getRegisterwithhomefinderDeployers());
114          traverse(this,getRegisterwithtraderDeployers());
115      }
116      
117     // ==================================================================
118
//
119
// Public methods.
120
//
121
// ==================================================================
122

123     // ==================================================================
124
//
125
// Public visitors used in homeplacement inactive state.
126
//
127
// ==================================================================
128
/**
129      * the componentinstantiationDeployer visitor method used to instantiate component
130      *
131      * @param comp The componentinstantiationDeployer to deploy
132      * @param status the homeplacementDeployer current status
133      * @throws FatalDeploymentException if a fatal problem occured
134      */

135     public void
136     visit(ComponentinstantiationDeployer comp, DeployerInactiveState status)
137     throws FatalDeploymentException
138     {
139         try{
140             comp.deploy(homePlaced);
141         }
142         catch(ComponentInstantiationFailureException e){
143             getErrorManager().submitException(e);
144         }
145     }
146     /**
147      * The RegisterwithhomefinderDeployer visitor method used to register home in
148      * home finder service.
149      *
150      * @param deployer The registerwithhomefinderDeployer to execute
151      * @param status The homeplacement current status
152      */

153     public void
154     visit(RegisterwithhomefinderDeployer deployer, DeployerInactiveState status)
155     {
156         try{
157             deployer.register_home(descriptor,homePlaced);
158         }
159         catch(Exception JavaDoc e){
160             e.printStackTrace();
161         }
162     }
163     /**
164      * The RegisterwithnamingDeployer visitor method used to register home in
165      * name service.
166      *
167      * @param deployer The registerwithnamingfinderDeployer to execute
168      * @param status The homeplacement current status
169      */

170     public void visit(RegisterwithnamingDeployer deployer,
171                       DeployerInactiveState status)
172     throws FatalDeploymentException{
173         try{
174             deployer.rebind(homePlaced);
175         }
176         catch(NameserviceRegistrationFailureException e){
177             getErrorManager().submitException(e);
178         }
179     }
180     /**
181      * The RegisterwithhometraderDeployer visitor method used to register home in
182      * trader service.
183      *
184      * @param deployer The registerwithtraderDeployer to execute
185      * @param status The homeplacement current status
186      */

187     public void visit(RegisterwithtraderDeployer deployer, DeployerInactiveState status){
188          try{
189              deployer.deploy(homePlaced);
190          }
191          catch(Exception JavaDoc e){
192              e.printStackTrace();
193          }
194      }
195
196
197     
198     /**
199      * The deploy metod install the home on the target host and make instantiation
200      * of all the required components.
201      *
202      * @throws FatalDeploymentException if fatal problem occured.
203      */

204     public void
205     deploy()
206     throws FatalDeploymentException
207     {
208         setupSoftpkgDependency();
209         try {
210             //setup the container and install homes with container configuration.
211

212             homePlaced =setupHome() ;
213             //storing the reference in the DeployInfo extension of the descriptor
214
getHomeplacementInfo().setCorbaReference(homePlaced);
215             getLogger().log("Home "+getHomeplacement().getId()+"is deployed");
216         }
217         catch(Exception JavaDoc e){
218             System.err.println("Problem occurred during the deployment of "+getHomeplacement().getId());
219             e.printStackTrace();
220
221         }
222         //setup the componentinstantiation
223
traverse(this,getComponentInstantiationDeployers());
224         proceedHomeRegistration();
225         getLifeCycleManager().stepEndedSuccessFully();
226     }
227     
228     /**
229      * Public accessor to retrieve the installed home.
230      * @return
231      */

232     public CCMHome getHome(){
233         return homePlaced;
234     }
235     
236
237     /**
238      *Tear down the homeplacement but dont remove the file archive
239      *@throws FatalDeploymentException if a fatal problem occured
240      */

241     public void
242     tearDown()
243     throws FatalDeploymentException
244     {
245         Homeplacement hi=getHomeplacement();
246         traverse(this,getComponentInstantiationDeployers());
247         traverse(this,getRegisterwithnamingDeployers());
248         traverse(this,getRegisterwithtraderDeployers());
249         traverse(this,getRegisterwithhomefinderDeployers());
250         // Remove the component server
251
getDestinationDeployer().removeHome(homePlaced);
252         getLifeCycleManager().stepEndedSuccessFully();
253     }
254     
255     // ==================================================================
256
//
257
// Public visitors used in homeplacement inactive state methods.
258
//
259
// ==================================================================
260
/**
261      * the componentinstantiationDeployer visitor method used to remove component
262      *
263      * @param comp The componentinstantiationDeployer to deploy
264      * @param status the homeplacementDeployer current status
265      * @throws FatalDeploymentException if a fatal problem occured
266      */

267     public void
268     visit(ComponentinstantiationDeployer comp, DeployerActiveState status)
269     {
270       try{
271         comp.tearDown();
272         }
273       catch(Exception JavaDoc e)
274         {
275          System.out.println("Cannot remove the instance");
276          e.printStackTrace();
277         }
278     }
279     /**
280      * The RegisterwithhomefinderDeployer visitor method used to unregister home in
281      * home finder service.
282      *
283      * @param deployer The registerwithhomefinderDeployer to execute
284      * @param status The homeplacement current status
285      */

286     public void
287     visit(RegisterwithhomefinderDeployer deployer, DeployerActiveState status)
288     {
289         try{
290             deployer.unregister_home();
291         }
292         catch(Exception JavaDoc e){
293             e.printStackTrace();
294         }
295     }
296     /**
297      * The RegisterwithnamingDeployer visitor method used to unregister home in
298      * name service.
299      *
300      * @param deployer The registerwithnamingfinderDeployer to execute
301      * @param status The homeplacement current status
302      */

303     public void
304     visit(
305         RegisterwithnamingDeployer deployer,
306         DeployerActiveState status)
307     {
308         try {
309             deployer.unbind();
310         } catch (Exception JavaDoc e) {
311             e.printStackTrace();
312         }
313     }
314     /**
315      * The RegisterwithhometraderDeployer visitor method used to register home in
316      * trader service.
317      *
318      * @param deployer The registerwithtraderDeployer to execute
319      * @param status The homeplacement current status
320      */

321     public void
322     visit(
323         RegisterwithtraderDeployer deployer,
324         DeployerActiveState status)
325     {
326         try {
327             deployer.tearDown();
328         } catch (Exception JavaDoc e) {
329             e.printStackTrace();
330         }
331     }
332 }
333
Popular Tags