KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2005 EBM WebSourcing
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 any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): EBM WebSourcing
21  * --------------------------------------------------------------------------
22  * $Id: ComponentLifeCycle.java,v 1.2 2005/07/22 10:24:27 alouis Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.petals.jbi.component.lifecycle;
27
28 import javax.jbi.JBIException;
29 import javax.jbi.component.Component;
30 import javax.management.ObjectName JavaDoc;
31
32 import org.objectweb.petals.jbi.component.context.ComponentContextImpl;
33 import org.objectweb.petals.jbi.component.thread.ComponentLifeCycleThread;
34 import org.objectweb.petals.jbi.management.systemstate.SystemState;
35 import org.objectweb.petals.jbi.messaging.DeliveryChannelImpl;
36 import org.objectweb.petals.tools.jbicommon.descriptor.ComponentDescription;
37 import org.objectweb.petals.util.LoggingUtil;
38
39 /**
40  * Implementation of the <code>ComponentLifeCycle</code> mbean
41  *
42  * @author Adrien LOUIS - EBM WebSourcing
43  * @author wjoseph - eBM-WebSourcing
44  */

45 public class ComponentLifeCycle extends LifeCycleAbstract implements
46     ComponentLifeCycleMBean {
47
48     /**
49      * The component linked with the current component life cycle
50      */

51     protected Component component;
52
53     /**
54      * The component description
55      */

56     private ComponentDescription componentDescription;
57
58     /**
59      * The component context
60      */

61     private ComponentContextImpl context;
62
63     /**
64      *
65      */

66     private SystemState recoverySrv;
67     
68     /**
69      * The component life cycle thread. Each life cycle have a thread to process
70      * operation in the component ClassLoader
71      */

72     protected ComponentLifeCycleThread componentLifeCycleThread;
73
74     /**
75      *
76      * @param componentDescription
77      * @param component
78      * @param context
79      * @param recoverySrv
80      * @param mbeanName
81      * @param log
82      */

83     public ComponentLifeCycle(ComponentDescription componentDescription,
84         Component component, ComponentContextImpl context,
85         SystemState recoverySrv, ObjectName JavaDoc mbeanName,
86         ComponentLifeCycleThread componentLifeCycleThread, LoggingUtil log) {
87         super(mbeanName, log);
88
89         this.componentDescription = componentDescription;
90
91         this.component = component;
92
93         this.context = context;
94
95         this.recoverySrv = recoverySrv;
96         
97         // set the jbiComponent ref to the contextImpl
98
if (context != null) {
99             context.setComponent(component);
100         }
101
102         // life cycle thread
103
this.componentLifeCycleThread = componentLifeCycleThread;
104     }
105
106     @Override JavaDoc
107     public void doInit() throws JBIException {
108         log.start();
109         componentLifeCycleThread.doInit(context);
110         log.end();
111     }
112
113     @Override JavaDoc
114     public void doShutdown() throws JBIException {
115         log.start();
116         componentLifeCycleThread.doShutdown();
117
118         // close the Channel if required
119
DeliveryChannelImpl channel = context.getDeliveryChannelImpl();
120         if (channel != null && channel.isOpened())
121             channel.close();
122         
123         log.end();
124     }
125
126     @Override JavaDoc
127     public void doStart() throws JBIException {
128         log.start();
129         componentLifeCycleThread.doStart();
130         log.end();
131     }
132
133     @Override JavaDoc
134     public void doStop() throws JBIException {
135         log.start();
136         componentLifeCycleThread.doStop();
137         log.end();
138     }
139
140     /**
141      * @see javax.jbi.management.ComponentLifeCycleMBean#getExtensionMBeanName()
142      */

143     public ObjectName JavaDoc getExtensionMBeanName() throws JBIException {
144         log.start();
145         ObjectName JavaDoc on = componentLifeCycleThread.getExtensionMBeanName();
146         log.end();
147         return on;
148     }
149
150     /**
151      *
152      * @return
153      */

154     public String JavaDoc getName() {
155         return componentDescription.getIdentification().getName();
156     }
157
158     @Override JavaDoc
159     public synchronized void setState(String JavaDoc state) throws JBIException {
160         super.setState(state);
161         try {
162             recoverySrv.updateComponentLifeCycleState(getName(), state);
163         } catch (Exception JavaDoc e) {
164             String JavaDoc msg = "Component state can't be persisted for recovery";
165             log.error(msg, e);
166             throw new JBIException(msg, e);
167         }
168     }
169
170     /* getters */
171     
172     public Component getComponent() {
173         return component;
174     }
175
176     public ComponentContextImpl getComponentContext() {
177         return context;
178     }
179
180     public ComponentDescription getComponentDescription() {
181         return componentDescription;
182     }
183
184 }
185
Popular Tags