KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > deployment > deploy > CreateAndRegisterSULifeCycleTask


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: CreateAndRegisterSULifeCycleTask.java 154 6 oct. 06 ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.management.deployment.deploy;
23
24 import java.net.URI JavaDoc;
25 import java.util.HashMap JavaDoc;
26
27 import javax.jbi.JBIException;
28
29 import org.objectweb.petals.jbi.component.lifecycle.ServiceAssemblyLifeCycle;
30 import org.objectweb.petals.jbi.component.lifecycle.ServiceUnitLifeCycle;
31 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants;
32 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils;
33 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService;
34 import org.objectweb.petals.jbi.management.service.ManagementException;
35 import org.objectweb.petals.processor.Task;
36 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit;
37 import org.objectweb.petals.util.LoggingUtil;
38
39 /**
40  * this task creates service unit lifecycle and registers this service unit
41  * lifecycle into the sa lifecycle
42  *
43  * @author ofabre - EBM Websourcing
44  *
45  */

46 public class CreateAndRegisterSULifeCycleTask implements Task {
47
48     /**
49      * logger wrapper
50      */

51     protected LoggingUtil log;
52
53     /**
54      * JBI Container :: JMX Agent Admin
55      */

56     protected LifeCycleManagerService managerService;
57
58     public CreateAndRegisterSULifeCycleTask(LoggingUtil log,
59             LifeCycleManagerService managerService) {
60         super();
61         this.log = log;
62         this.managerService = managerService;
63     }
64
65     public void execute(HashMap JavaDoc context) throws Exception JavaDoc {
66         URI JavaDoc installationRoot = (URI JavaDoc) context
67                 .get(DeploymentContextConstants.SU_INSTALL_ROOT);
68
69         ServiceUnit serviceUnit = (ServiceUnit) context
70                 .get(DeploymentContextConstants.SU_DESCRIPTOR);
71
72         ServiceAssemblyLifeCycle saLifeCycle = (ServiceAssemblyLifeCycle) context
73                 .get(DeploymentContextConstants.SA_LIFECYCLE);
74
75         /*
76          * 2. Create service unit lifecycle
77          */

78         ServiceUnitLifeCycle suLifeCycle = createNewServiceUnitLifeCycle(
79                 installationRoot.getPath(), serviceUnit);
80
81         /*
82          * 3. Register this service unit lifecycle into the sa lifecycle
83          */

84         registerSULifeCycle(suLifeCycle, saLifeCycle, serviceUnit);
85
86     }
87
88     /**
89      * Creates a new {@link ServiceUnitLifeCycle}
90      *
91      * @param rootPath
92      * the SU installation root
93      * @param serviceUnit
94      * the service unit production element
95      * @return a new {@link ServiceUnitLifeCycle} instance
96      */

97     protected ServiceUnitLifeCycle createNewServiceUnitLifeCycle(
98             String JavaDoc rootPath, ServiceUnit serviceUnit) {
99         return new ServiceUnitLifeCycle(serviceUnit, managerService, rootPath,
100                 log);
101     }
102
103     /**
104      * Register the {@link ServiceUnitLifeCycle} to the
105      * {@link ServiceAssemblyLifeCycle}.
106      *
107      * @param suLifeCycle
108      * the {@link ServiceUnitLifeCycle} to register
109      * @param saLifeCycle
110      * the {@link ServiceAssemblyLifeCycle} where
111      * {@link ServiceUnitLifeCycle} will be registered
112      * @param serviceUnit
113      * the service unit production element
114      * @throws ManagementException
115      * if it fails to register {@link ServiceUnitLifeCycle} to
116      * {@link ServiceAssemblyLifeCycle}
117      */

118     protected void registerSULifeCycle(ServiceUnitLifeCycle suLifeCycle,
119             ServiceAssemblyLifeCycle saLifeCycle, ServiceUnit serviceUnit)
120         throws ManagementException {
121         try {
122             saLifeCycle.registerSUIntoSA(DeploymentUtils
123                     .getServiceUnitName(serviceUnit), suLifeCycle);
124         } catch (JBIException e) {
125             String JavaDoc msg = "Error while registering the service unit "
126                     + DeploymentUtils.getServiceUnitName(serviceUnit)
127                     + " life cycle into the service assembly life cycle"
128                     + saLifeCycle.getServiceAssembly().getIdentification()
129                             .getName() + ".";
130             log.error(msg, e);
131             throw new ManagementException(msg, e);
132         }
133     }
134
135     public void undo(HashMap JavaDoc context) {
136
137         ServiceUnit serviceUnit = (ServiceUnit) context
138                 .get(DeploymentContextConstants.SU_DESCRIPTOR);
139
140         ServiceAssemblyLifeCycle saLifeCycle = (ServiceAssemblyLifeCycle) context
141                 .get(DeploymentContextConstants.SA_LIFECYCLE);
142
143         try {
144             unregisterSULifeCycle(saLifeCycle, serviceUnit);
145         } catch (ManagementException e) {
146             String JavaDoc msg = "Failed to revert a CreateAndRegisterSULifeCycleTask";
147             log.error(msg, e);
148         }
149
150     }
151
152     /**
153      * Register the {@link ServiceUnitLifeCycle} to the
154      * {@link ServiceAssemblyLifeCycle}.
155      *
156      * @param saLifeCycle
157      * the {@link ServiceAssemblyLifeCycle} where
158      * {@link ServiceUnitLifeCycle} will be registered
159      * @param serviceUnit
160      * the service unit production element of the su to unregister
161      * @throws ManagementException
162      * if it fails to register {@link ServiceUnitLifeCycle} to
163      * {@link ServiceAssemblyLifeCycle}
164      */

165     protected void unregisterSULifeCycle(ServiceAssemblyLifeCycle saLifeCycle,
166             ServiceUnit serviceUnit) throws ManagementException {
167         saLifeCycle.unregisterSUFromSA(DeploymentUtils
168                 .getServiceUnitName(serviceUnit));
169
170     }
171
172 }
173
Popular Tags