KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > component > lifecycle > ServiceUnitLifeCycle


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 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: InstallationService.java 154 2006-03-27 15:30:10Z ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.component.lifecycle;
23
24 import javax.jbi.JBIException;
25 import javax.jbi.component.ServiceUnitManager;
26
27 import org.objectweb.petals.jbi.component.event.StateChangeFailedEvent;
28 import org.objectweb.petals.jbi.component.event.StateChangedEvent;
29 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService;
30 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit;
31 import org.objectweb.petals.util.LoggingUtil;
32
33 /**
34  * This class manage the life cycle of deployed service units
35  *
36  * @author Olivier Fabre - EBM Websourcing
37  *
38  */

39 public class ServiceUnitLifeCycle extends LifeCycleAbstract {
40
41     private LifeCycleManagerService managerService;
42
43     private ServiceUnit serviceUnit;
44
45     private String JavaDoc suName;
46
47     private String JavaDoc serviceUnitRootPath;
48
49     public ServiceUnitLifeCycle(ServiceUnit serviceUnit,
50             LifeCycleManagerService managerService, String JavaDoc serviceUnitRootPath,
51             LoggingUtil log) {
52         super(null, log);
53         this.managerService = managerService;
54         this.serviceUnit = serviceUnit;
55         this.serviceUnitRootPath = serviceUnitRootPath;
56         this.suName = serviceUnit.getIdentification().getName();
57     }
58
59     /**
60      * Returns the ServiceUnitManager associated with the service unit's
61      * targeted component
62      *
63      * @return null if there's no Service Unit Manager
64      */

65     public ServiceUnitManager getServiceUnitManager() {
66         ServiceUnitManager result = null;
67         ComponentLifeCycle clc = managerService.getComponentByName(serviceUnit
68                 .getTargetComponentName());
69         if (clc != null) {
70             result = clc.getComponent().getServiceUnitManager();
71         }
72         return result;
73     }
74
75     public String JavaDoc getServiceUnitRootPath() {
76         return serviceUnitRootPath;
77     }
78
79     public String JavaDoc getSuName() {
80         return suName;
81     }
82
83     /**
84      * Do nothing because there's no Service Unit MBean registered in JMX !
85      */

86     @Override JavaDoc
87     public synchronized void stateChanged(StateChangedEvent event) {
88
89     }
90
91     /**
92      * Do nothing because there's no Service Unit MBean registered in JMX !
93      */

94     @Override JavaDoc
95     public synchronized void stateChangeFailed(StateChangeFailedEvent event) {
96
97     }
98
99     @Override JavaDoc
100     public void doInit() throws JBIException {
101         getServiceUnitManager().init(suName, serviceUnitRootPath);
102     }
103
104     @Override JavaDoc
105     public void doStart() throws JBIException {
106         getServiceUnitManager().start(suName);
107     }
108
109     @Override JavaDoc
110     public void doStop() throws JBIException {
111         getServiceUnitManager().stop(suName);
112     }
113
114     @Override JavaDoc
115     public void doShutdown() throws JBIException {
116         getServiceUnitManager().shutDown(suName);
117     }
118
119 }
120
Popular Tags