KickJava   Java API By Example, From Geeks To Geeks.

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


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: Installer.java 154 2006-03-27 15:30:10Z ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.component.lifecycle;
23
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URI JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32
33 import javax.jbi.JBIException;
34 import javax.jbi.component.Bootstrap;
35 import javax.jbi.component.Component;
36 import javax.jbi.component.InstallationContext;
37 import javax.jbi.management.LifeCycleMBean;
38 import javax.management.AttributeChangeNotification JavaDoc;
39 import javax.management.ListenerNotFoundException JavaDoc;
40 import javax.management.MBeanNotificationInfo JavaDoc;
41 import javax.management.Notification JavaDoc;
42 import javax.management.NotificationBroadcaster JavaDoc;
43 import javax.management.NotificationBroadcasterSupport JavaDoc;
44 import javax.management.NotificationFilter JavaDoc;
45 import javax.management.NotificationListener JavaDoc;
46 import javax.management.ObjectName JavaDoc;
47
48 import org.objectweb.petals.PetalsException;
49 import org.objectweb.petals.classloader.LoaderManager;
50 import org.objectweb.petals.classloader.PetalsClassLoader;
51 import org.objectweb.petals.jbi.component.context.ComponentContextImpl;
52 import org.objectweb.petals.jbi.component.context.InstallationContextImpl;
53 import org.objectweb.petals.jbi.component.event.StateChangeFailedEvent;
54 import org.objectweb.petals.jbi.component.event.StateChangedEvent;
55 import org.objectweb.petals.jbi.component.thread.BootstrapThread;
56 import org.objectweb.petals.jbi.component.thread.ComponentLifeCycleThread;
57 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService;
58 import org.objectweb.petals.jbi.management.service.MBeanNamesImpl;
59 import org.objectweb.petals.jbi.management.service.ManagementException;
60 import org.objectweb.petals.jbi.management.systemstate.SystemState;
61 import org.objectweb.petals.tools.jbicommon.descriptor.ComponentDescription;
62 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor;
63 import org.objectweb.petals.tools.jbicommon.descriptor.SharedLibraryList;
64 import org.objectweb.petals.util.ConvertSpecialCharactersUtil;
65 import org.objectweb.petals.util.LoggingUtil;
66 import org.objectweb.petals.util.SystemUtil;
67 import org.objectweb.util.monolog.api.Logger;
68
69 /**
70  *
71  * @author Olivier Fabre - EBM Websourcing
72  * @author wjoseph - eBMWebsourcing
73  *
74  */

75 public class Installer implements InstallerMBean, NotificationBroadcaster JavaDoc {
76
77     /**
78      * Bootstrap classloader id prefix
79      */

80     public static final String JavaDoc BS_PREFIX = "BS";
81
82     /**
83      * Component classloader id prefix
84      */

85     public static final String JavaDoc COMP_PREFIX = "COMP";
86
87     public static final String JavaDoc INSTALLED = "Installed";
88
89     public static final String JavaDoc INSTALLING = "Installing";
90
91     public static final String JavaDoc UNINSTALLED = "Uninstalled";
92
93     public static final String JavaDoc UNINSTALLING = "Uninstalling";
94
95     public static final String JavaDoc UNKNOWN = "Unknown";
96
97     private static final String JavaDoc BINDING_COMPONENT = "binding-component";
98
99     private static final String JavaDoc SERVICE_ENGINE = "service-engine";
100
101     // /////////////////
102
// Notifications support
103
// /////////////////
104
protected Object JavaDoc activitySynchronizer;
105
106     protected String JavaDoc state;
107
108     NotificationBroadcasterSupport JavaDoc notifSupport = new NotificationBroadcasterSupport JavaDoc();
109
110     protected ComponentContextImpl componentContext;
111
112     protected ComponentDescription componentDescription;
113
114     protected ObjectName JavaDoc componentJmxName;
115
116     protected URI JavaDoc installationRoot;
117
118     protected Bootstrap jbiBootstrap;
119
120     protected LifeCycleManagerService jmxAdmin;
121
122     protected LoaderManager loadSrv;
123
124     protected BootstrapThread bootstrapThread;
125
126     protected LoggingUtil log;
127
128     /**
129      * The ObjectName of this installer
130      */

131     protected ObjectName JavaDoc mBeanName;
132
133     protected SystemState recoverySrv;
134
135     /**
136      * A sequence number used by state change notification
137      */

138     protected long sequenceNumber;
139
140     /**
141      * Create the Installer that will manage installation / uninstallation of
142      * the Jbi component. The related bootstrap is created and initialize here.
143      *
144      * @param installationRoot
145      * @param loadSrv
146      * @param componentContext
147      * @param componentDescription
148      * @param jmxAdmin
149      * @param logger
150      * @throws JBIException
151      */

152     public Installer(URI JavaDoc installationRoot, LoaderManager loadSrv,
153         ComponentContextImpl componentContext,
154         ComponentDescription componentDescription,
155         LifeCycleManagerService jmxAdmin, SystemState recoverySrv,
156         ObjectName JavaDoc mbeanName, Logger logger) {
157         super();
158         log = new LoggingUtil(logger);
159
160         log.start();
161
162         this.jmxAdmin = jmxAdmin;
163
164         this.recoverySrv = recoverySrv;
165
166         this.componentDescription = componentDescription;
167
168         this.installationRoot = installationRoot;
169
170         this.componentContext = componentContext;
171
172         this.loadSrv = loadSrv;
173
174         this.mBeanName = mbeanName;
175
176         this.state = UNINSTALLED;
177
178         activitySynchronizer = new Object JavaDoc();
179
180         log.end();
181     }
182
183     /*
184      * (non-Javadoc)
185      *
186      * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener,
187      * javax.management.NotificationFilter, java.lang.Object)
188      */

189     public void addNotificationListener(NotificationListener JavaDoc arg0,
190         NotificationFilter JavaDoc arg1, Object JavaDoc arg2) throws IllegalArgumentException JavaDoc {
191         notifSupport.addNotificationListener(arg0, arg1, arg2);
192     }
193
194     /**
195      * Get the unique component name of this component, as assigned by the
196      * identification section of this component's installation descriptor.
197      *
198      * @return the component name; must be non-null and non-empty.
199      */

200     public String JavaDoc getComponentName() {
201         return componentContext.getComponentName();
202     }
203
204     // ////////////////////////////////////////////
205
// ElementListener implementation
206
// ////////////////////////////////////////////
207
/**
208      * @see javax.jbi.management.LifeCycleMBean#getCurrentState()
209      */

210     public String JavaDoc getCurrentState() {
211         if (!(LifeCycleMBean.SHUTDOWN.equals(state)
212             || LifeCycleMBean.STARTED.equals(state) || LifeCycleMBean.STOPPED
213             .equals(state))) {
214             return LifeCycleMBean.UNKNOWN;
215         }
216         return state;
217     }
218
219     /**
220      * (non-Javadoc)
221      *
222      * @see javax.jbi.management.InstallerMBean#getInstallerConfigurationMBean()
223      */

224     public ObjectName JavaDoc getInstallerConfigurationMBean() throws JBIException {
225         LifeCycleAbstract lifeCycle = jmxAdmin
226             .getComponentByName(componentContext.getComponentName());
227         if (!INSTALLED.equals(state)
228             || (lifeCycle != null && !lifeCycle.getCurrentState().equals(
229                 LifeCycleMBean.SHUTDOWN))) {
230             throw new JBIException("Component is not in the SHUTDOWN state");
231         }
232         
233         if (jbiBootstrap == null) {
234             throw new JBIException("Bootstrap should not be null");
235         }
236         
237         return bootstrapThread.getExtensionMBeanName();
238     }
239
240     /**
241      * (non-Javadoc)
242      *
243      * @see javax.jbi.management.InstallerMBean#getInstallRoot()
244      */

245     public String JavaDoc getInstallRoot() {
246         return componentContext.getInstallRoot();
247     }
248
249     /**
250      *
251      * @return the installer ObjectName
252      */

253     public ObjectName JavaDoc getMBeanName() {
254         return mBeanName;
255     }
256
257     /*
258      * (non-Javadoc)
259      *
260      * @see javax.management.NotificationBroadcaster#getNotificationInfo()
261      */

262     public MBeanNotificationInfo JavaDoc[] getNotificationInfo() {
263         String JavaDoc[] types = new String JavaDoc[] {AttributeChangeNotification.ATTRIBUTE_CHANGE};
264
265         String JavaDoc name = AttributeChangeNotification JavaDoc.class.getName();
266
267         String JavaDoc description = "Notification about a change of the lifeCycle state or a state change failure.";
268
269         MBeanNotificationInfo JavaDoc info = new MBeanNotificationInfo JavaDoc(types, name,
270             description);
271
272         return new MBeanNotificationInfo JavaDoc[] {info};
273     }
274
275     /**
276      * Install the jbi component. Call the Bootstrap onInstall() and cleanup()
277      * methods, register the jbiComponent object, and return its jmxName.
278      *
279      * @throws JBIException
280      * the component is already installed
281      */

282     public ObjectName JavaDoc install() throws JBIException {
283         log.start();
284         if (UNINSTALLED.equals(state)) {
285             synchronized (activitySynchronizer) {
286                 try {
287                     setState(INSTALLING);
288
289                     doInstall();
290
291                     setState(INSTALLED);
292                 } catch (Throwable JavaDoc re) {
293                     setState(UNKNOWN);
294
295                     String JavaDoc msg = "An exception occured during the installation.";
296
297                     JBIException e = new JBIException(msg, re);
298
299                     log.error(msg, e);
300
301                     stateChangeFailed(new StateChangeFailedEvent(this, e));
302
303                     throw e;
304                 }
305             }
306         } else {
307             String JavaDoc msg = "The Object can not be installed in this state.";
308
309             JBIException e = new JBIException(msg);
310
311             log.error(msg, e);
312
313             stateChangeFailed(new StateChangeFailedEvent(this, e));
314
315             throw e;
316         }
317         log.end();
318
319         return componentJmxName;
320     }
321
322     /**
323      * Test the installation flag
324      *
325      * @return true if the component is already installed
326      */

327     public boolean isInstalled() {
328         boolean result = false;
329         if (INSTALLED.equals(state)) {
330             result = true;
331         }
332         return result;
333     }
334
335     /*
336      * (non-Javadoc)
337      *
338      * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener)
339      */

340     public void removeNotificationListener(NotificationListener JavaDoc arg0)
341         throws ListenerNotFoundException JavaDoc {
342         notifSupport.removeNotificationListener(arg0);
343     }
344
345     /**
346      * Set the <code>State</code> reference of the current state. An
347      * <code>LifeCycleStateEventAbstract</code> is thrown.
348      *
349      * @param state
350      * @throws JBIException
351      */

352     public synchronized void setState(String JavaDoc state) throws JBIException {
353         stateChanged(new StateChangedEvent(this, this.state, state));
354
355         this.state = state;
356
357         try {
358             recoverySrv.updateComponentInstallationState(getComponentName(),
359                 state);
360         } catch (Exception JavaDoc e) {
361             String JavaDoc msg = "Component state can't be persisted for recovery";
362             log.error(msg, e);
363             throw new JBIException(msg, e);
364         }
365     }
366
367     /**
368      * <i>stateChanged</i> is called when the state of a lifecycle element
369      * changes. A JMX-notification is thrown.
370      *
371      * @see petals.management.element.ElementStateListener#stateChanged(java.util.EventObject)
372      */

373     public synchronized void stateChanged(StateChangedEvent event) {
374         log.call();
375         Notification JavaDoc n = new AttributeChangeNotification JavaDoc(mBeanName,
376             sequenceNumber++, System.currentTimeMillis(), "State of '"
377                 + mBeanName.toString() + "' changed : " + event.getOldState()
378                 + " -> " + event.getNewState(), "state", "String", event
379                 .getOldState(), event.getNewState());
380
381         notifSupport.sendNotification(n);
382     }
383
384     /**
385      * <i>stateChangeFailed</i>> is called when the change of state of a
386      * lifecycle element fails. A JMX-notification throws the relative
387      * JBIException, .
388      *
389      * @see petals.management.element.ElementStateListener#stateChanged(java.util.EventObject)
390      */

391     public synchronized void stateChangeFailed(StateChangeFailedEvent event) {
392         log.call();
393         Notification JavaDoc n = new AttributeChangeNotification JavaDoc(mBeanName,
394             sequenceNumber++, System.currentTimeMillis(), "State change of '"
395                 + mBeanName.toString() + "' failed : "
396                 + event.getException().getMessage(), "exception", "String",
397             null, event.getException().toString());
398
399         notifSupport.sendNotification(n);
400     }
401
402     /**
403      * Uninstall the jbi component. Call the Bootstrap onUninstall() and
404      * cleanup() methods, deregister the jbiComponent object,
405      *
406      * @throws JBIException
407      * the component is already uninstalled
408      */

409     public void uninstall() throws JBIException {
410         log.start();
411         if (INSTALLED.equals(state)) {
412             synchronized (activitySynchronizer) {
413                 try {
414
415                     ComponentLifeCycle componentLifeCycle = getComponentLifeCycle();
416                     String JavaDoc compState = componentLifeCycle.getCurrentState();
417
418                     if (ComponentLifeCycle.STARTED.equals(compState)) {
419                         componentLifeCycle.stop();
420                         componentLifeCycle.shutDown();
421                     } else if (ComponentLifeCycle.STOPPED.equals(compState)) {
422                         componentLifeCycle.shutDown();
423                     }
424                     
425                     compState = componentLifeCycle.getCurrentState();
426
427                     if (ComponentLifeCycle.SHUTDOWN.equals(compState)) {
428                         setState(UNINSTALLING);
429                         doUninstall();
430                         setState(UNINSTALLED);
431                     }
432                 } catch (Throwable JavaDoc re) {
433                     setState(UNKNOWN);
434
435                     String JavaDoc msg = "An exception occured during the uninstallation.";
436
437                     JBIException e = new JBIException(msg, re);
438
439                     log.error(msg, e);
440
441                     stateChangeFailed(new StateChangeFailedEvent(this, e));
442
443                     throw e;
444                 }
445             }
446         } else {
447             String JavaDoc msg = "The Object can not be uninstalled in this state.";
448
449             JBIException e = new JBIException(msg);
450
451             log.error(msg, e);
452
453             stateChangeFailed(new StateChangeFailedEvent(this, e));
454
455             throw e;
456         }
457         log.end();
458     }
459
460     /**
461      * Create the classLoader for Bootstrap
462      *
463      * @return classLoader for Bootstrap
464      */

465     protected PetalsClassLoader createBootstrapClassloader() {
466         log.call();
467
468         List JavaDoc<String JavaDoc> classpath = componentDescription.getBootstrapClassPath();
469
470         boolean parentFirst = JBIDescriptor.isParentFirst(componentDescription
471             .getBootstrapClassLoaderDelegation());
472
473         return createClassLoader(BS_PREFIX, classpath, parentFirst, null);
474     }
475
476     /**
477      * Create a classloader with the specified parameters.
478      *
479      * @param prefix
480      * bootstrap or component prefix
481      * @param classpath
482      * classpath of the bootstrap/component
483      * @param parentFirst
484      * delegation mode
485      * @param slNameList
486      * list of the name of the required sharedLibraries
487      * @return a classloader
488      */

489     protected PetalsClassLoader createClassLoader(String JavaDoc prefix,
490         List JavaDoc<String JavaDoc> classpath, boolean parentFirst, List JavaDoc<String JavaDoc> slNameList) {
491         log.call();
492
493         // prepare bootstrap and component classloader
494
List JavaDoc<URL JavaDoc> urls = new ArrayList JavaDoc<URL JavaDoc>();
495
496         try {
497             // TODO Find a better way of managing URI
498
String JavaDoc installRootPath;
499             if (installationRoot.toURL().getPath().startsWith("/")) {
500                 installRootPath = "file://"
501                     + installationRoot.toURL().getPath();
502             } else {
503                 installRootPath = "file:///"
504                     + installationRoot.toURL().getPath();
505             }
506
507             installRootPath = ConvertSpecialCharactersUtil
508                 .convertPath(installRootPath);
509
510             urls.add(new URL JavaDoc(installRootPath));
511         } catch (MalformedURLException JavaDoc e) {
512             // simple do nothing - JBI Package has responsibility in
513
// checking the archive contents against informations
514
// contained in JBI Descriptor first.
515
String JavaDoc msg = "Unexpected error. " + e.getMessage();
516             log.info(msg, e);
517         }
518         URL JavaDoc[] baseUrls = urls.toArray(new URL JavaDoc[] {});
519
520         PetalsClassLoader classLoader = null;
521
522         try {
523             classLoader = (PetalsClassLoader) loadSrv
524                 .createComponentClassLoader(prefix
525                     + componentDescription.getIdentification().getName(),
526                     baseUrls, classpath, parentFirst, slNameList);
527         } catch (PetalsException pe) {
528             // just log when some error occur
529
log.error("Error creating bootstrap class loader. "
530                 + pe.getMessage(), pe);
531
532             log.end();
533             return null;
534         }
535         return classLoader;
536     }
537
538     /**
539      * Create the classloader for the component Be careful, we use the classpath
540      * set in the InstallationContext. (during the installation phase, the
541      * Bootstrap can modify the component's classpath by setting it in the
542      * InstallationContext object.)
543      *
544      * @return classloader for the component
545      */

546     @SuppressWarnings JavaDoc("unchecked")
547     protected PetalsClassLoader createComponentClassloader() {
548         log.call();
549
550         InstallationContext installContext = new InstallationContextImpl(
551             componentDescription, componentContext, true);
552         
553         List JavaDoc<String JavaDoc> classpath = (List JavaDoc<String JavaDoc>) installContext
554             .getClassPathElements();
555
556         // delegation model
557
boolean parentFirst = JBIDescriptor.isParentFirst(componentDescription
558             .getComponentClassLoaderDelegation());
559
560         // sharedlibraries used by this component
561
List JavaDoc<SharedLibraryList> slList = componentDescription
562             .getSharedLibraryList();
563
564         List JavaDoc slNameList = new ArrayList JavaDoc();
565
566         if (slList != null) {
567             for (Iterator JavaDoc iter = slList.iterator(); iter.hasNext();) {
568                 SharedLibraryList element = (SharedLibraryList) iter.next();
569                 slNameList.add(element.getName());
570             }
571         }
572
573         return createClassLoader(COMP_PREFIX, classpath, parentFirst,
574             slNameList);
575     }
576
577     /**
578      * Do the bootstrap installation.
579      *
580      * @throws JBIException
581      */

582     protected void doInstall() throws JBIException {
583
584         // load the bootstrap
585
if (jbiBootstrap != null) {
586             throw new JBIException(
587                 "Bootstrap should be null, the installer has already been initialized");
588         }
589         
590         // 1. create the bootstrap classloader
591
PetalsClassLoader classloader = createComponentClassloader();
592         
593         // 2. create the bootstrap object
594
jbiBootstrap = loadBootstrap(classloader);
595         
596         // 3. create the bootstrap thread
597
bootstrapThread = createBootstrapThread(classloader);
598         
599         // 4. create installation context
600
InstallationContextImpl installContext = new InstallationContextImpl(
601             componentDescription, componentContext, true);
602
603         // 5. init and install
604
bootstrapThread.init(installContext);
605         bootstrapThread.onInstall();
606
607         // 6. create the component life cycle
608
componentJmxName = createComponentLifeCycleMBean();
609
610         bootstrapThread.cleanUp();
611     }
612     
613     /**
614      * Create the thread that will be used to process component installation steps.
615      * The thread-classloader is set with the given paremeter.
616      *
617      * @param classloader
618      * @return the BootstrapThread
619      */

620     protected BootstrapThread createBootstrapThread(PetalsClassLoader classloader) {
621         BootstrapThread it = new BootstrapThread(this, jbiBootstrap);
622         it.setContextClassLoader(classloader);
623         it.start();
624         return it;
625     }
626
627     /**
628      * Create the thread that will be used to process component life cycle steps.
629      * The thread-classloader is set with the given paremeter.
630      *
631      * @param classloader
632      * @return the BootstrapThread
633      */

634     protected ComponentLifeCycleThread createComponentLifeCycleThread(
635         Component component, PetalsClassLoader classloader) {
636         ComponentLifeCycleThread clt = new ComponentLifeCycleThread(component);
637         clt.setContextClassLoader(classloader);
638         clt.start();
639         return clt;
640     }
641
642     /**
643      * Register the installer engine/binding in the life cycle manager service
644      *
645      * @return
646      * @throws JBIException
647      */

648     protected ObjectName JavaDoc createComponentLifeCycleMBean() throws JBIException {
649         ObjectName JavaDoc objectName = null;
650
651         // 1. create component classloader
652
PetalsClassLoader cl = createComponentClassloader();
653         
654         // 2. create the component object
655
Component jbiComponent = loadComponent(cl);
656         
657         // 3. create the componentLifeCycle thread
658
ComponentLifeCycleThread lifeCycleThread = createComponentLifeCycleThread(
659             jbiComponent, cl);
660         
661         // 4. create the Mbean (as binding or engine)
662
MBeanNamesImpl mbeanNames = jmxAdmin.getMBeanNames();
663         if (BINDING_COMPONENT.equals(componentDescription.getType())) {
664             objectName = mbeanNames
665                 .createBindingComponentMBeanName(componentDescription
666                     .getIdentification().getName());
667         } else if (SERVICE_ENGINE.equals(componentDescription.getType())){
668             objectName = mbeanNames
669             .createEngineComponentMBeanName(componentDescription
670                 .getIdentification().getName());
671         }
672         
673         // 5. create life cycle
674
ComponentLifeCycle lifecycle = new ComponentLifeCycle(
675             componentDescription, jbiComponent, componentContext, recoverySrv,
676             objectName, lifeCycleThread, log);
677         
678         // 6. register engine or binding
679
if (BINDING_COMPONENT.equals(componentDescription.getType())) {
680             objectName = jmxAdmin.registerBindingComponent(lifecycle);
681         } else if (SERVICE_ENGINE.equals(componentDescription.getType())) {
682             objectName = jmxAdmin.registerEngineComponent(lifecycle);
683         }
684         
685         return objectName;
686     }
687
688     /**
689      * Unregister the installer engine/binding from the life cycle manager service
690
691      * @throws ManagementException
692      */

693     protected void unregisterComponentLifeCycleMBean() throws ManagementException {
694         if (BINDING_COMPONENT.equals(componentDescription.getType())) {
695             jmxAdmin.unregisterBindingComponent(componentJmxName);
696         } else if (SERVICE_ENGINE.equals(componentDescription.getType())) {
697             jmxAdmin.unregisterEngineComponent(componentJmxName);
698         }
699     }
700
701     /**
702      * Do the bootstrap uninstallation
703      *
704      * @throws JBIException
705      */

706     protected void doUninstall() throws JBIException {
707
708         if (jbiBootstrap == null) {
709             throw new JBIException("Bootstrap should not be null");
710         }
711
712         // call uninstall on bootstrap
713
// create an uninstallation context
714
InstallationContextImpl uninstallContext = new InstallationContextImpl(
715             componentDescription, componentContext, false);
716
717         bootstrapThread.init(uninstallContext);
718
719         bootstrapThread.onUninstall();
720
721         // unregister the installer mbean
722
unregisterComponentLifeCycleMBean();
723
724         // unregister the optionnal extensionmbean
725
if (componentContext.getComponent().getLifeCycle() != null) {
726             ObjectName JavaDoc extName = componentContext.getComponent().getLifeCycle()
727                 .getExtensionMBeanName();
728             try {
729                 jmxAdmin.getMBeanServer().unregisterMBean(extName);
730             } catch (Exception JavaDoc e) {
731                 // nothing
732
}
733         }
734
735         bootstrapThread.cleanUp();
736
737         // stop current bootstrap thread
738
// a new thread will be created on the next do install call
739
bootstrapThread.shutdownThread();
740
741         /*
742          * unload component and bootstrap class loaders
743          */

744         String JavaDoc componentName = componentDescription.getIdentification()
745             .getName();
746
747         loadSrv.deleteClassLoader(Installer.COMP_PREFIX + componentName);
748         loadSrv.deleteClassLoader(Installer.BS_PREFIX + componentName);
749         
750         // set parameters to null
751
jbiBootstrap = null;
752
753     }
754
755     /**
756      * Get the component life cycle
757      *
758      * @return the component life cycle
759      */

760     protected ComponentLifeCycle getComponentLifeCycle() {
761         String JavaDoc compName = componentDescription.getIdentification().getName();
762         return jmxAdmin.getComponentByName(compName);
763     }
764
765     /**
766      * load the bootstrap, with its own classloader
767      *
768      * @return
769      */

770     protected Bootstrap loadBootstrap(PetalsClassLoader classloader)
771         throws JBIException {
772         log.call();
773         Class JavaDoc bootstrapClass;
774         Bootstrap jbiBootstrapTmp = null;
775         try {
776             // 1. get the classloader
777
// PetalsClassLoader classloader = createBootstrapClassloader();
778

779             bootstrapClass = classloader.loadClass(componentDescription
780                 .getBootstrapClassName());
781
782             if (bootstrapClass == null) {
783                 throw new JBIException("Could not find bootstrap class: "
784                     + componentDescription.getBootstrapClassName());
785             }
786             jbiBootstrapTmp = (Bootstrap) bootstrapClass.newInstance();
787
788             // 2. set the logger factory
789
// LoggerFactory loggerFactory = new LoggerFactory();
790
// loggerFactory.getLogger("Petals");
791
// LogManager logManager = LogManager.getLogManager();
792
// this.componentContext.setRootLogger(loggerFactory.getLogger(descr));
793

794         } catch (ClassNotFoundException JavaDoc e) {
795             throw new JBIException("Class not found: "
796                 + componentDescription.getBootstrapClassName(), e);
797         } catch (InstantiationException JavaDoc e) {
798             throw new JBIException("Could not instantiate : "
799                 + componentDescription.getBootstrapClassName(), e);
800         } catch (IllegalAccessException JavaDoc e) {
801             throw new JBIException("Illegal access on: "
802                 + componentDescription.getBootstrapClassName(), e);
803         }
804         return jbiBootstrapTmp;
805     }
806
807     /**
808      * load the component, with its own classloader
809      *
810      * @return the component
811      */

812     protected javax.jbi.component.Component loadComponent(PetalsClassLoader classloader) throws JBIException {
813         log.call();
814
815         Class JavaDoc componentClass;
816         javax.jbi.component.Component jbiComponent = null;
817
818         try {
819             componentClass = classloader.loadClass(componentDescription
820                 .getComponentClassName());
821
822             if (componentClass == null) {
823                 throw new JBIException("Could not find component class: "
824                     + componentDescription.getComponentClassName());
825             }
826
827             jbiComponent = (javax.jbi.component.Component) componentClass
828                 .newInstance();
829
830             // 2. set component logger
831
Class JavaDoc clazz = classloader.loadClass("java.util.logging.Logger");
832             Method JavaDoc method = clazz.getMethod("getLogger", new Class JavaDoc[] {
833                 Class.forName("java.lang.String"),
834                 Class.forName("java.lang.String")});
835             java.util.logging.Logger JavaDoc logger = (java.util.logging.Logger JavaDoc) method
836                 .invoke(null, new Object JavaDoc[] {
837                     "root0.Petals" + ".components.container-"
838                         + SystemUtil.getContainerName() + "."
839                         + componentDescription.getIdentification().getName(),
840                     null});
841             componentContext.setRootLogger(logger);
842
843         } catch (ClassNotFoundException JavaDoc e) {
844             throw new JBIException("Class not found: "
845                 + componentDescription.getComponentClassName(), e);
846         } catch (InstantiationException JavaDoc e) {
847             throw new JBIException("Could not instantiate : "
848                 + componentDescription.getComponentClassName(), e);
849         } catch (IllegalAccessException JavaDoc e) {
850             throw new JBIException("Illegal access on: "
851                 + componentDescription.getComponentClassName(), e);
852         } catch (SecurityException JavaDoc e) {
853             throw new JBIException(
854                 "Security exception for java.util.logging.Logger", e);
855         } catch (NoSuchMethodException JavaDoc e) {
856             throw new JBIException(e);
857         } catch (IllegalArgumentException JavaDoc e) {
858             throw new JBIException(e);
859         } catch (InvocationTargetException JavaDoc e) {
860             throw new JBIException(e);
861         }
862         return jbiComponent;
863     }
864 }
865
Popular Tags