KickJava   Java API By Example, From Geeks To Geeks.

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


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 Frédéric.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer;
27
28 import java.io.IOException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.util.Hashtable JavaDoc;
31
32 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.FatalDeploymentException;
33 import org.objectweb.openccm.descriptor.softpkg.ccm.CodeInstallationFailureException;
34 import org.objectweb.openccm.descriptor.softpkg.ccm.DependencyResolutionFailureException;
35 import org.omg.Components.CCMHome;
36 import org.omg.Components.ConfigValue;
37 import org.omg.Components.Deployment.ComponentInstallation;
38 import org.omg.Components.Deployment.ComponentInstallationHelper;
39 import org.omg.Components.Deployment.ComponentServer;
40 import org.omg.Components.Deployment.Container;
41 import org.omg.Components.Deployment.InstallationFailure;
42 import org.omg.Components.Deployment.InvalidLocation;
43 import org.omg.Components.Deployment.ServerActivator;
44 import org.omg.Components.Deployment.ServerActivatorHelper;
45
46 /**
47  * The ECMDestinationDeployer is the DestinationDeployer able to correctly install
48  * a home on ECM destination host.
49  *
50  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a>
51  *
52  * @version 0.1
53  */

54 public class ECMDestinationDeployer
55        extends DestinationDeployerBase
56     {
57
58     // ==================================================================
59
//
60
// Internal state.
61
//
62
// ==================================================================
63
private ServerActivator sa;
64     private ComponentInstallation ci;
65     private ComponentServer cs;
66     private Hashtable JavaDoc containerTable;
67     private java.util.List JavaDoc config_values;
68     private NodeDependencyVisitorDeployer depVisitor;
69     // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74
public ECMDestinationDeployer()
75     {
76         containerTable = new Hashtable JavaDoc();
77         config_values = new java.util.LinkedList JavaDoc();
78         depVisitor = new NodeDependencyVisitorDeployer();
79     }
80     // ==================================================================
81
//
82
// Internals methods.
83
//
84
// ==================================================================
85
/**
86      * Internal method to found the ServerActivtor denoted by the component
87      * assembly descriptor.
88      * @return the ServerActivator found
89      */

90     private ServerActivator
91     getSA()
92     {
93         if (sa == null)
94             try {
95                 sa =
96                     ServerActivatorHelper.narrow(
97                         getFindbyDeployer().resolveReference());
98             } catch (Exception JavaDoc e) {
99                 // TODO Auto-generated catch block
100
e.printStackTrace();
101             }
102         return sa;
103     }
104     /**
105      * Internal method to found the ComponentInstallation denoted by the component
106      * assembly descriptor.
107      * @return the ComponentInstallation found
108      */

109     private ComponentInstallation
110     getCI()
111     {
112         if (ci == null) {
113             String JavaDoc ci_name ="ExtCI"+
114                 getFindbyDeployer()
115                     .getFindby()
116                     .getNamingservice()
117                     .getName().substring(2);
118
119
120
121             try {
122                 ci = ComponentInstallationHelper.narrow(getRef(ci_name));
123             } catch (Exception JavaDoc e) {
124                 // TODO Auto-generated catch block
125
e.printStackTrace();
126             }
127         }
128         return ci;
129     }
130     /**
131      * Internal method to start a HTTP server to upload the full component archive.
132      *
133      * @param input The input stream on the file to upload
134      * @param name The string identifier of the ressource
135      * @return the string URL identifier used to identifies the ressource
136      * @throws java.io.IOException
137      */

138     private String JavaDoc
139     startHttpServer(InputStream JavaDoc input, String JavaDoc name)
140     throws java.io.IOException JavaDoc
141     {
142         (new Thread JavaDoc(new org
143
            .objectweb
144             .openccm
145             .deploytool
146             .MicroServerHttp(
147                 getRootDeployerContext().getServerSocket(),
148                 input,
149                 name)))
150             .start();
151         return "http://"
152             + java.net.InetAddress.getLocalHost().getHostAddress()
153             + ':'
154             + getRootDeployerContext().getServerSocket().getLocalPort()
155             + '/'
156             + name;
157     }
158     /**
159      * Internal method to install a home.
160      *
161      * @param csConfig
162      * @param contConfig
163      * @param homeConfig
164      * @param implID
165      * @param entryPoint
166      * @return
167      * @throws FatalDeploymentException
168      */

169     private CCMHome
170     installCCMHome(
171         ConfigValue[] csConfig,
172         ConfigValue[] contConfig,
173         ConfigValue[] homeConfig,
174         String JavaDoc implID,
175         String JavaDoc entryPoint)
176     throws FatalDeploymentException {
177         CCMHome home = null;
178         try {
179             if (cs == null)
180                 cs = getSA().create_component_server(csConfig);
181             Container cont = cs.create_container(contConfig);
182             home = cont.install_home(implID, entryPoint, homeConfig);
183             containerTable.put(home, cont);
184         } catch (Exception JavaDoc e) {
185             e.printStackTrace();
186             throw new FatalDeploymentException(e);
187         }
188         return home;
189     }
190
191     // ==================================================================
192
//
193
// Public methods.
194
//
195
// ==================================================================
196
/**
197      * Make the target destination deployer process all the dependencies
198      * of the implementation.
199      *
200      * @throws FatalDeploymentException if a problem occured
201      * during processing of dependencies
202      */

203     public void
204     resolveDependency()
205     throws FatalDeploymentException
206     {
207         try {
208             /*config_values.addAll(Arrays.asList(getSoftpkgDeployer()
209                                                 .processDependencies
210                                                     (getComponentInstallation())));*/

211             getSoftpkgDeployer().visitDependencyDeployers(depVisitor);
212             /* List l=Arrays.asList(getImplementationDeployer()
213                                    .install(getComponentInstallation()));
214                
215                config_values.addAll(l);*/

216             getImplementationDeployer().visitDependencyDeployers(depVisitor);
217             getImplementationDeployer().visitCodeDeployers(depVisitor);
218
219             try {
220                 String JavaDoc url =
221                     startHttpServer(
222                         getSoftpkgDeployer().getComponentArchiveStream(),
223                         getSoftpkgDeployer().getSoftpkg().getName() + ".car");
224                 getComponentInstallation().install(
225                     getImplementationDeployer().getImplementation().getId(),
226                     url);
227
228             } catch (IOException JavaDoc e) {
229                 // TODO Auto-generated catch block
230
e.printStackTrace();
231                 throw new FatalDeploymentException(
232                     e,
233                     "Cannot install implementation in target node");
234             } catch (InvalidLocation e) {
235                 // TODO Auto-generated catch block
236
e.printStackTrace();
237                 throw new FatalDeploymentException(
238                     e,
239                     "Cannot install implementation in target node");
240             } catch (InstallationFailure e) {
241                 // TODO Auto-generated catch block
242
e.printStackTrace();
243                 throw new FatalDeploymentException(
244                     e,
245                     "Cannot install implementation in target node");
246             }
247
248         } catch (DependencyResolutionFailureException e) {
249             getErrorManager().submitException(e);
250         } catch (CodeInstallationFailureException e) {
251             e.printStackTrace();
252             getErrorManager().submitException(e);
253         }
254     }
255
256     /**
257      * InstallHome install the home on the precised destination according
258      * to the host requirements, such as dependencies and event factory.
259      *
260      * @return The home installed
261      * @throws FatalDeploymentException
262      */

263     public CCMHome
264     installHome()
265     throws FatalDeploymentException
266     {
267
268         ConfigValue[] config_home =
269         /*(ConfigValue[])
270            config_values.toArray(new ConfigValue[config_values.size()]);*/

271         depVisitor.getConfigValue();
272
273         return installCCMHome(
274             new ConfigValue[0],
275             new ConfigValue[0],
276             config_home,
277             getImplementationDeployer().getImplementation().getId(),
278             depVisitor.getEntryPoint());
279     }
280
281     /**
282      * Return the component installation of the target host used
283      * to install the home.
284      *
285      * @return The component installation of the target host
286      * @throws FatalDeploymentException if a fatal problem occured during installation
287      */

288     public ComponentInstallation
289     getComponentInstallation()
290     throws FatalDeploymentException
291     {
292         return getCI();
293     }
294
295     /**
296      * Remove a previously installed CCMHome
297      *
298      * @param home the home to remove
299      * @throws FatalDeploymentException if a fatal problem occured during uninstallation
300      */

301     public void
302     removeHome(CCMHome home)
303     throws FatalDeploymentException
304     {
305         try {
306             Container cont = (Container) containerTable.remove(home);
307             if (cont == null)
308                 return;
309             if (cont.get_homes().length == 0)
310                 cont.remove();
311             cont.remove_home(home);
312
313         } catch (Exception JavaDoc e) {
314             e.printStackTrace();
315             throw new FatalDeploymentException(e);
316         }
317     }
318
319 }
320
Popular Tags