KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > component > thread > BootstrapThread


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$
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.petals.jbi.component.thread;
26
27 import javax.jbi.JBIException;
28 import javax.jbi.component.Bootstrap;
29 import javax.jbi.component.Component;
30 import javax.jbi.component.InstallationContext;
31 import javax.management.ObjectName JavaDoc;
32
33 import org.objectweb.petals.jbi.component.lifecycle.Installer;
34
35 /**
36  * The installer thread. This thread is used by the Installer component to have
37  * each component in a separate bootstrap environment.
38  *
39  * @author Christophe Hamerling - EBM Websourcing
40  *
41  */

42 public class BootstrapThread extends AbstractThread implements Bootstrap {
43
44     /**
45      * The installer that is linked to this thread
46      */

47     private Installer installer;
48
49     /**
50      * The JBI component
51      */

52     private Component jbiComponent;
53
54     /**
55      * Management object name
56      */

57     private ObjectName JavaDoc objectName;
58
59     /**
60      * The Bootstrap
61      */

62     private Bootstrap jbiBootStrap;
63
64     /**
65      * The installation context attribute is required by the init method. This
66      * attribute is set by the init method and used by the current thread.
67      */

68     private InstallationContext installContext;
69
70     /*
71      * STATICS : The different states that are used to process operations
72      */

73
74     public static final int INSTALL = 0;
75
76     public static final int UNINSTALL = 1;
77
78     public static final int INIT = 2;
79
80     public static final int CLEAN = 3;
81
82     public static final int EXTMBEAN = 4;
83
84     /**
85      * Creates a new instance of BootstrapThread
86      *
87      * @param installer
88      * @param jbiBootstrap
89      */

90     public BootstrapThread(Installer installer, Bootstrap jbiBootstrap) {
91         super();
92         this.installer = installer;
93         this.jbiBootStrap = jbiBootstrap;
94         this.setName(this.installer.getComponentName() + "-Installer Thread");
95     }
96
97     /**
98      * Process the requested task.
99      *
100      * @param action
101      * the task to execute
102      * @return
103      */

104     protected int doTask(int action) {
105         
106         int result = 0;
107         try {
108             switch (action) {
109                 case CLEAN:
110                     jbiBootStrap.cleanUp();
111                     break;
112
113                 case INSTALL:
114                     jbiBootStrap.onInstall();
115                     break;
116
117                 case UNINSTALL:
118                     jbiBootStrap.onUninstall();
119                     break;
120
121                 case INIT:
122                     jbiBootStrap.init(installContext);
123                     break;
124
125                 case EXTMBEAN:
126                     objectName = jbiBootStrap.getExtensionMBeanName();
127                     break;
128
129                 case SHUTDOWNTHREAD:
130                     result = -1;
131                     break;
132
133                 default:
134                     // NOTHING
135
break;
136             }
137
138         } catch (JBIException jbie) {
139             jbiException = jbie;
140         }
141         
142         return result;
143     }
144
145     /**
146      *
147      * @return the jbiComponent
148      */

149     protected Component getJbiComponent() {
150         return jbiComponent;
151     }
152
153     /*
154      * (non-Javadoc)
155      *
156      * @see javax.jbi.component.Bootstrap#cleanUp()
157      */

158     public void cleanUp() throws JBIException {
159         execute(CLEAN);
160
161         JBIException jbie = getJbiException();
162         if (jbie != null) {
163             throw jbie;
164         }
165     }
166
167     /*
168      * (non-Javadoc)
169      *
170      * @see javax.jbi.component.Bootstrap#getExtensionMBeanName()
171      */

172     public ObjectName JavaDoc getExtensionMBeanName() {
173         execute(EXTMBEAN);
174         return objectName;
175     }
176
177     /*
178      * (non-Javadoc)
179      *
180      * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
181      */

182     public void init(InstallationContext installContext) throws JBIException {
183         this.installContext = installContext;
184         execute(INIT);
185
186         JBIException jbie = getJbiException();
187         if (jbie != null) {
188             throw jbie;
189         }
190     }
191
192     /*
193      * (non-Javadoc)
194      *
195      * @see javax.jbi.component.Bootstrap#onInstall()
196      */

197     public void onInstall() throws JBIException {
198         execute(INSTALL);
199
200         JBIException jbie = getJbiException();
201         if (jbie != null) {
202             throw jbie;
203         }
204     }
205
206     /*
207      * (non-Javadoc)
208      *
209      * @see javax.jbi.component.Bootstrap#onUninstall()
210      */

211     public void onUninstall() throws JBIException {
212         execute(UNINSTALL);
213
214         JBIException jbie = getJbiException();
215         if (jbie != null) {
216             throw jbie;
217         }
218     }
219 }
Popular Tags