KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > ServiceController


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.system;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.ListIterator JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.concurrent.ConcurrentHashMap JavaDoc;
30 import java.util.concurrent.CopyOnWriteArrayList JavaDoc;
31
32 import javax.management.MBeanRegistration JavaDoc;
33 import javax.management.MBeanServer JavaDoc;
34 import javax.management.Notification JavaDoc;
35 import javax.management.ObjectName JavaDoc;
36
37 import org.jboss.dependency.spi.Controller;
38 import org.jboss.dependency.spi.ControllerContext;
39 import org.jboss.dependency.spi.ControllerMode;
40 import org.jboss.dependency.spi.ControllerState;
41 import org.jboss.dependency.spi.DependencyInfo;
42 import org.jboss.dependency.spi.DependencyItem;
43 import org.jboss.deployment.DeploymentException;
44 import org.jboss.deployment.DeploymentInfo;
45 import org.jboss.deployment.DeploymentState;
46 import org.jboss.kernel.Kernel;
47 import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
48 import org.jboss.kernel.spi.dependency.KernelController;
49 import org.jboss.logging.Logger;
50 import org.jboss.mx.server.ServerConstants;
51 import org.jboss.mx.util.JBossNotificationBroadcasterSupport;
52 import org.jboss.mx.util.ObjectNameFactory;
53 import org.jboss.system.metadata.ServiceMetaData;
54 import org.jboss.system.metadata.ServiceMetaDataParser;
55 import org.jboss.system.microcontainer.LifecycleDependencyItem;
56 import org.jboss.system.microcontainer.ServiceControllerContext;
57 import org.w3c.dom.Element JavaDoc;
58
59 /**
60  * This is the main Service Controller. A controller can deploy a service to a
61  * jboss.system It installs by delegating, it configures by delegating<p>
62  *
63  * This class has been rewritten to delegate to the microcontainer's
64  * generic controller. Like the original ServiceController, all state
65  * transitions must be handled manually, e.g. driven by the deployer
66  * invoking create, start, stop, etc.
67  * That is with one exception; we register ourselves an automatic context.
68  *
69  * @see org.jboss.system.Service
70  *
71  * @author <a HREF="mailto:marc.fleury@jboss.org">Marc Fleury</a>
72  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
73  * @author <a HREF="mailto:scott.stark@jboss.org">Scott Stark</a>
74  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
75  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
76  * @version $Revision: 57108 $
77  */

78 public class ServiceController extends JBossNotificationBroadcasterSupport
79    implements ServiceControllerMBean, MBeanRegistration JavaDoc
80 {
81    /** The ObjectName of the default loader repository */
82    public static final ObjectName JavaDoc DEFAULT_LOADER_REPOSITORY = ObjectNameFactory.create(ServerConstants.DEFAULT_LOADER_NAME);
83
84    /** The operation name for lifecycle */
85    public static final String JavaDoc JBOSS_INTERNAL_LIFECYCLE = "jbossInternalLifecycle";
86
87    /** The signature for lifecycle operations */
88    public static final String JavaDoc[] JBOSS_INTERNAL_LIFECYCLE_SIG = new String JavaDoc[] { String JavaDoc.class.getName() };
89
90    /** Class logger. */
91    private static final Logger log = Logger.getLogger(ServiceController.class);
92
93    /** The kernel */
94    protected Kernel kernel;
95
96    /** A callback to the JMX MBeanServer */
97    protected MBeanServer JavaDoc server;
98    
99    /** The service binding */
100    protected ServiceBinding serviceBinding;
101
102    /** The contexts */
103    protected Map JavaDoc<ObjectName JavaDoc, ServiceControllerContext> installed = new ConcurrentHashMap JavaDoc<ObjectName JavaDoc, ServiceControllerContext>();
104    
105    /** The contexts in installation order */
106    protected CopyOnWriteArrayList JavaDoc<ServiceControllerContext> installedOrder = new CopyOnWriteArrayList JavaDoc<ServiceControllerContext>();
107    
108    /**
109     * Get the MBeanServer
110     *
111     * @return the server
112     */

113    public MBeanServer JavaDoc getMBeanServer()
114    {
115       return server;
116    }
117
118    /**
119     * Set the server.
120     *
121     * @param server the server.
122     */

123    public void setMBeanServer(MBeanServer JavaDoc server)
124    {
125       this.server = server;
126    }
127
128    /**
129     * Get the kernel.
130     *
131     * @return the kernel.
132     */

133    public Kernel getKernel()
134    {
135       return kernel;
136    }
137
138    /**
139     * Set the kernel.
140     *
141     * @param kernel the kernel.
142     */

143    public void setKernel(Kernel kernel)
144    {
145       this.kernel = kernel;
146    }
147
148    /**
149     * Get the serviceBinding.
150     *
151     * @return the serviceBinding.
152     */

153    public ServiceBinding getServiceBinding()
154    {
155       return serviceBinding;
156    }
157
158    /**
159     * Plugin a ServiceBinding policy
160     *
161     * @param serviceBinding policy
162     */

163    public void setServiceBinding(ServiceBinding serviceBinding)
164    {
165       this.serviceBinding = serviceBinding;
166    }
167    
168    public List JavaDoc<ServiceContext> listDeployed()
169    {
170       // Retrieve the service context from all our installed contexts
171
ArrayList JavaDoc<ServiceContext> result = new ArrayList JavaDoc<ServiceContext>(installedOrder.size());
172       for (ServiceControllerContext context : installedOrder)
173          result.add(context.getServiceContext());
174       return result;
175    }
176
177    public List JavaDoc<ServiceContext> listIncompletelyDeployed()
178    {
179       // Retrieve the service contexts that are not deployed properly
180
ArrayList JavaDoc<ServiceContext> result = new ArrayList JavaDoc<ServiceContext>();
181       for (ServiceControllerContext context : installedOrder)
182       {
183          ServiceContext sc = context.getServiceContext();
184          if (sc.state != ServiceContext.CREATED &&
185              sc.state != ServiceContext.RUNNING &&
186              sc.state != ServiceContext.STOPPED &&
187              sc.state != ServiceContext.DESTROYED)
188          {
189             result.add(sc);
190          }
191       }
192       return result;
193    }
194
195    public List JavaDoc<ObjectName JavaDoc> listDeployedNames()
196    {
197       // Get all the object names from our installed contexts
198
ArrayList JavaDoc<ObjectName JavaDoc> result = new ArrayList JavaDoc<ObjectName JavaDoc>(installed.size());
199       for (ObjectName JavaDoc name : installed.keySet())
200          result.add(name);
201       return result;
202    }
203
204    public String JavaDoc listConfiguration(ObjectName JavaDoc[] objectNames) throws Exception JavaDoc
205    {
206       return ServiceConfigurator.getConfiguration(server, this, objectNames);
207    }
208
209    public void validateDeploymentState(DeploymentInfo di, DeploymentState state)
210    {
211       ArrayList JavaDoc<ObjectName JavaDoc> mbeans = new ArrayList JavaDoc<ObjectName JavaDoc>(di.mbeans);
212       if (di.deployedObject != null)
213          mbeans.add(di.deployedObject);
214       boolean mbeansStateIsValid = true;
215       for (int m = 0; m < mbeans.size(); ++m)
216       {
217          ObjectName JavaDoc serviceName = mbeans.get(m);
218          ServiceContext ctx = getServiceContext(serviceName);
219          if (ctx != null && state == DeploymentState.STARTED)
220             mbeansStateIsValid &= ctx.state == ServiceContext.RUNNING;
221       }
222       if (mbeansStateIsValid == true)
223          di.state = state;
224    }
225
226    public List JavaDoc<ObjectName JavaDoc> install(List JavaDoc<ServiceMetaData> metaDatas, ObjectName JavaDoc loaderName) throws DeploymentException
227    {
228       KernelController controller = kernel.getController();
229
230       // Track the registered mbeans both for returning the result
231
// and uninstalling in the event of an error
232
List JavaDoc<ObjectName JavaDoc> result = new ArrayList JavaDoc<ObjectName JavaDoc>(metaDatas.size());
233       List JavaDoc<ServiceControllerContext> contexts = new ArrayList JavaDoc<ServiceControllerContext>(metaDatas.size());
234
235       // Go through each mbean in the passed xml
236
for (ServiceMetaData metaData : metaDatas)
237       {
238          metaData.setClassLoaderName(loaderName);
239
240          // Install the context to the configured level
241
ServiceControllerContext context = new ServiceControllerContext(this, metaData);
242          try
243          {
244             doInstall(controller, context);
245             contexts.add(context);
246             doChange(controller, context, ControllerState.CONFIGURED, "configure");
247             result.add(context.getObjectName());
248          }
249          catch (Throwable JavaDoc t)
250          {
251             // Something went wrong
252
for (ServiceControllerContext ctx : contexts)
253                safelyRemoveAnyRegisteredContext(ctx);
254
255             DeploymentException.rethrowAsDeploymentException("Error during install", t);
256          }
257       }
258       return result;
259    }
260
261    public ObjectName JavaDoc install(ServiceMetaData metaData, ObjectName JavaDoc loaderName) throws DeploymentException
262    {
263       KernelController controller = kernel.getController();
264       metaData.setClassLoaderName(loaderName);
265       ObjectName JavaDoc name = metaData.getObjectName();
266       
267       // Install the context to the configured level
268
ServiceControllerContext context = new ServiceControllerContext(this, metaData);
269       try
270       {
271          doInstall(controller, context);
272          doChange(controller, context, ControllerState.CONFIGURED, "configure");
273          return context.getObjectName();
274       }
275       catch (Throwable JavaDoc t)
276       {
277          throw DeploymentException.rethrowAsDeploymentException("Error during install " + name, t);
278       }
279    }
280
281    public List JavaDoc<ObjectName JavaDoc> install(Element JavaDoc config, ObjectName JavaDoc loaderName) throws DeploymentException
282    {
283       // Parse the xml
284
ServiceMetaDataParser parser = new ServiceMetaDataParser(config);
285       List JavaDoc<ServiceMetaData> metaDatas = parser.parse();
286       return install(metaDatas, loaderName);
287    }
288    
289    /**
290     * Install an MBean without any meta data
291     *
292     * @param name the object name
293     * @param object the mbean object
294     * @throws DeploymentException for any error
295     */

296    public void install(ObjectName JavaDoc name, Object JavaDoc object) throws DeploymentException
297    {
298       if (name == null)
299          throw new IllegalArgumentException JavaDoc("Null name");
300       if (object == null)
301          throw new IllegalArgumentException JavaDoc("Null object");
302
303       KernelController controller = kernel.getController();
304
305       ServiceControllerContext context = new ServiceControllerContext(this, name, object);
306       try
307       {
308          doInstall(controller, context);
309          doChange(controller, context, ControllerState.CONFIGURED, "configure");
310       }
311       catch (Throwable JavaDoc t)
312       {
313          // Something went wrong
314
safelyRemoveAnyRegisteredContext(context);
315
316          DeploymentException.rethrowAsDeploymentException("Error during install", t);
317       }
318    }
319    
320    public void register(ObjectName JavaDoc serviceName) throws Exception JavaDoc
321    {
322       register(serviceName, null);
323    }
324
325    public void register(ObjectName JavaDoc serviceName, Collection JavaDoc<ObjectName JavaDoc> depends) throws Exception JavaDoc
326    {
327       if (serviceName == null)
328       {
329          log.warn("Ignoring request to register null service: ", new Exception JavaDoc("STACKTRACE"));
330          return;
331       }
332       
333       log.debug("Registering service " + serviceName);
334
335       // This is an already registered mbean
336
KernelController controller = kernel.getController();
337       ServiceControllerContext context = new ServiceControllerContext(this, serviceName);
338       if (depends != null)
339          addDependencies(context, depends);
340
341       // Install the context to the configured level
342
try
343       {
344          doInstall(controller, context);
345          doChange(controller, context, ControllerState.CONFIGURED, "configure");
346       }
347       catch (Throwable JavaDoc t)
348       {
349          // Something went wrong
350
safelyRemoveAnyRegisteredContext(context);
351          
352          DeploymentException.rethrowAsDeploymentException("Error during register: " + serviceName, t);
353       }
354    }
355    
356    public void create(ObjectName JavaDoc serviceName) throws Exception JavaDoc
357    {
358       create(serviceName, null);
359    }
360
361    public void create(ObjectName JavaDoc serviceName, Collection JavaDoc<ObjectName JavaDoc> depends) throws Exception JavaDoc
362    {
363       if (serviceName == null)
364       {
365          log.warn("Ignoring request to create null service: ", new Exception JavaDoc("STACKTRACE"));
366          return;
367       }
368       
369       log.debug("Creating service " + serviceName);
370       
371       // Register if not already done so
372
ServiceControllerContext context = installed.get(serviceName);
373       if (context == null)
374       {
375          register(serviceName, depends);
376          context = installed.get(serviceName);
377       }
378       ServiceContext ctx = context.getServiceContext();
379
380       // If we are already created (can happen in dependencies) or failed just return
381
if (ctx.state == ServiceContext.CREATED
382             || ctx.state == ServiceContext.RUNNING
383             || ctx.state == ServiceContext.FAILED)
384       {
385          log.debug("Ignoring create request for service: " + ctx.objectName + " at state " + ctx.getStateString());
386          return;
387       }
388
389       // Request the mbean go to the created state
390
KernelController controller = kernel.getController();
391       try
392       {
393          doChange(controller, context, ControllerState.CREATE, "create");
394       }
395       catch (Throwable JavaDoc t)
396       {
397          log.warn("Problem creating service " + serviceName, t);
398       }
399    }
400    
401    public void start(ObjectName JavaDoc serviceName) throws Exception JavaDoc
402    {
403       if (serviceName == null)
404       {
405          log.warn("Ignoring request to start null service: ", new Exception JavaDoc("STACKTRACE"));
406          return;
407       }
408
409       log.debug("starting service " + serviceName);
410       
411       // Register if not already done so
412
ServiceControllerContext context = installed.get(serviceName);
413       if (context == null)
414       {
415          register(serviceName, null);
416          context = installed.get(serviceName);
417       }
418       ServiceContext ctx = context.getServiceContext();
419
420       // If we are already started (can happen in dependencies) just return
421
if (ctx.state == ServiceContext.RUNNING || ctx.state == ServiceContext.FAILED)
422       {
423          log.debug("Ignoring start request for service: " + ctx.objectName + " at state " + ctx.getStateString());
424          return;
425       }
426
427       // Request the mbean go to the fully installed state
428
KernelController controller = kernel.getController();
429       try
430       {
431          doChange(controller, context, ControllerState.INSTALLED, "start");
432       }
433       catch (Throwable JavaDoc t)
434       {
435          log.warn("Problem starting service " + serviceName, t);
436       }
437    }
438
439    public void restart(ObjectName JavaDoc serviceName) throws Exception JavaDoc
440    {
441       if (serviceName == null)
442       {
443          log.warn("Ignoring request to restart null service: ", new Exception JavaDoc("STACKTRACE"));
444          return;
445       }
446
447       log.debug("restarting service " + serviceName);
448       stop(serviceName);
449       start(serviceName);
450    }
451
452    public void stop(ObjectName JavaDoc serviceName) throws Exception JavaDoc
453    {
454       if (serviceName == null)
455       {
456          log.warn("Ignoring request to stop null service: ", new Exception JavaDoc("STACKTRACE"));
457          return;
458       }
459
460       log.debug("stopping service: " + serviceName);
461
462       ServiceControllerContext context = installed.get(serviceName);
463       if (context == null)
464       {
465          log.warn("Ignoring request to stop nonexistent service: " + serviceName);
466          return;
467       }
468
469       // If we are already stopped (can happen in dependencies) just return
470
ServiceContext ctx = context.getServiceContext();
471       if (ctx.state != ServiceContext.RUNNING)
472       {
473          log.debug("Ignoring stop request for service: " + ctx.objectName + " at state " + ctx.getStateString());
474          return;
475       }
476
477       // Request the mbean go back to the created state
478
KernelController controller = kernel.getController();
479       try
480       {
481          doChange(controller, context, ControllerState.CREATE, null);
482       }
483       catch (Throwable JavaDoc t)
484       {
485          log.warn("Problem stopping service " + serviceName, t);
486       }
487    }
488
489    public void destroy(ObjectName JavaDoc serviceName) throws Exception JavaDoc
490    {
491       if (serviceName == null)
492       {
493          log.warn("Ignoring request to destroy null service: ", new Exception JavaDoc("STACKTRACE"));
494          return;
495       }
496
497       log.debug("destroying service: " + serviceName);
498
499       ServiceControllerContext context = installed.get(serviceName);
500       if (context == null)
501       {
502          log.warn("Ignoring request to destroy nonexistent service: " + serviceName);
503          return;
504       }
505
506       // If we are already destroyed (can happen in dependencies) just return
507
ServiceContext ctx = context.getServiceContext();
508       if (ctx.state == ServiceContext.DESTROYED || ctx.state == ServiceContext.NOTYETINSTALLED || ctx.state == ServiceContext.FAILED)
509       {
510          log.debug("Ignoring destroy request for service: " + ctx.objectName + " at state " + ctx.getStateString());
511          return;
512       }
513
514       // Request the mbean go the configured state
515
KernelController controller = kernel.getController();
516       try
517       {
518          doChange(controller, context, ControllerState.CONFIGURED, null);
519       }
520       catch (Throwable JavaDoc t)
521       {
522          log.warn("Problem stopping service " + serviceName, t);
523       }
524    }
525
526    public void remove(ObjectName JavaDoc objectName) throws Exception JavaDoc
527    {
528       if (objectName == null)
529       {
530          log.warn("Ignoring request to remove null service: ", new Exception JavaDoc("STACKTRACE"));
531          return;
532       }
533
534       // Removal can be attempted twice, this is because ServiceMBeanSupport does a "double check"
535
// to make sure the ServiceController is tidied up
536
// However, if the tidyup is done correctly, it invokes this method recursively:
537
// ServiceController::remove -> MBeanServer::unregisterMBean
538
// ServiceMBeanSupport::postDeregister -> ServiceController::remove
539
ServiceControllerContext context = installed.remove(objectName);
540       if (context == null)
541       {
542          log.trace("Ignoring request to remove nonexistent service: " + objectName);
543          return;
544       }
545       installedOrder.remove(context);
546       log.debug("removing service: " + objectName);
547
548       // Uninstall the context
549
safelyRemoveAnyRegisteredContext(context);
550    }
551
552    public ServiceContext getServiceContext(ObjectName JavaDoc serviceName)
553    {
554       ServiceControllerContext context = installed.get(serviceName);
555       if (context != null)
556          return context.getServiceContext();
557       return null;
558    }
559    
560    public void shutdown()
561    {
562       log.debug("Stopping " + installedOrder.size() + " services");
563
564       KernelController controller = kernel.getController();
565       
566       int serviceCounter = 0;
567
568       // Uninstall all the contexts we know about
569
ListIterator JavaDoc<ServiceControllerContext> iterator = installedOrder.listIterator(installedOrder.size());
570       while (iterator.hasPrevious())
571       {
572          ServiceControllerContext context = iterator.previous();
573          controller.uninstall(context.getName());
574          ++serviceCounter;
575       }
576       log.debug("Stopped " + serviceCounter + " services");
577    }
578
579    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name)
580          throws Exception JavaDoc
581    {
582       this.server = server;
583
584       if( kernel == null )
585       {
586          // Bootstrap the microcontainer.
587
BasicBootstrap bootstrap = new BasicBootstrap();
588          bootstrap.run();
589          kernel = bootstrap.getKernel();
590       }
591
592       log.debug("Controller MBean online");
593       return name == null ? OBJECT_NAME : name;
594    }
595
596    public void postRegister(Boolean JavaDoc registrationDone)
597    {
598       if (registrationDone.booleanValue() == false)
599          log.fatal("Registration of ServiceController failed");
600       else
601       {
602          // Register the ServiceController as a running service
603
KernelController controller = kernel.getController();
604          ServiceControllerContext context = new ServiceControllerContext(this, ServiceControllerMBean.OBJECT_NAME);
605          context.setMode(ControllerMode.AUTOMATIC);
606          try
607          {
608             controller.install(context);
609          }
610          catch (Throwable JavaDoc t)
611          {
612             log.fatal("Error registering service controller", t);
613          }
614       }
615    }
616
617    public void preDeregister()
618          throws Exception JavaDoc
619    {
620    }
621
622    public void postDeregister()
623    {
624       installed.clear();
625       installedOrder.clear();
626       server = null;
627    }
628    
629    /**
630     * Install a context
631     *
632     * @param controller the controller
633     * @param context the context
634     * @throws Throwable for any error
635     */

636    private void doInstall(KernelController controller, ServiceControllerContext context) throws Throwable JavaDoc
637    {
638       controller.install(context);
639       installed.put(context.getObjectName(), context);
640       installedOrder.add(context);
641    }
642    
643    /**
644     * Change a context
645     *
646     * @param controller the controller
647     * @param context the context
648     * @param requiredState the require state
649     * @param logWait log the waiting dependencies
650     * @throws Throwable for any error
651     */

652    private void doChange(KernelController controller, ServiceControllerContext context, ControllerState requiredState, String JavaDoc logWait) throws Throwable JavaDoc
653    {
654       if (ControllerMode.ON_DEMAND.equals(context.getMode()) == false)
655       {
656          controller.change(context, requiredState);
657          ControllerState state = context.getState();
658          if (logWait != null && requiredState.equals(state) == false && state != ControllerState.ERROR)
659             log.debug("Waiting in " + logWait + " of " + context.getObjectName() + " on " + getUnresolvedDependencies(context, requiredState));
660       }
661    }
662
663    /**
664     * Sends outs controller notifications about service lifecycle events
665     *
666     * @param type the notification type
667     * @param serviceName the service name
668     */

669    public void sendControllerNotification(String JavaDoc type, ObjectName JavaDoc serviceName)
670    {
671       Notification JavaDoc notification = new Notification JavaDoc(type, this, super.nextNotificationSequenceNumber());
672       notification.setUserData(serviceName);
673       sendNotification(notification);
674    }
675
676    /**
677     * Add the passed lifecycle dependencies to the context
678     *
679     * @param context the context
680     * @param depends the dependencies
681     */

682    private void addDependencies(ServiceControllerContext context, Collection JavaDoc<ObjectName JavaDoc> depends)
683    {
684       DependencyInfo info = context.getDependencyInfo();
685       for (ObjectName JavaDoc other : depends)
686       {
687          info.addIDependOn(new LifecycleDependencyItem(context.getName(), other.getCanonicalName(), ControllerState.CREATE));
688          info.addIDependOn(new LifecycleDependencyItem(context.getName(), other.getCanonicalName(), ControllerState.START));
689       }
690    }
691
692    /**
693     * Get the unresolved dependencies
694     *
695     * @param context the context
696     * @param state the state we want to move to
697     * @return the unresolved dependencies
698     */

699    private String JavaDoc getUnresolvedDependencies(ServiceControllerContext context, ControllerState state)
700    {
701       boolean first = true;
702       
703       StringBuilder JavaDoc builder = new StringBuilder JavaDoc();
704       for (DependencyItem item : context.getDependencyInfo().getUnresolvedDependencies())
705       {
706          if (item.isResolved() == false && item.getWhenRequired() == state)
707          {
708             if (first)
709                first = false;
710             else
711                builder.append(' ');
712             builder.append(item.getIDependOn());
713          }
714       }
715       return builder.toString();
716    }
717
718    /**
719     * Safely remove any potentially registered context (usually after an error)
720     *
721     * @param ctx the context
722     */

723    private void safelyRemoveAnyRegisteredContext(ServiceControllerContext ctx)
724    {
725       // First the context must have a controller
726
Controller controller = ctx.getController();
727       if (controller != null)
728       {
729          // The name must be registered and it must be our context
730
Object JavaDoc name = ctx.getName();
731          ControllerContext registered = controller.getContext(name, null);
732          if (registered == ctx)
733             controller.uninstall(name);
734       }
735    }
736 }
737
Popular Tags