View Javadoc

1   /*
2    * $Id: MuleContextStopPhase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.lifecycle.phases;
11  
12  import org.mule.api.MuleContext;
13  import org.mule.api.agent.Agent;
14  import org.mule.api.component.Component;
15  import org.mule.api.construct.FlowConstruct;
16  import org.mule.api.lifecycle.Initialisable;
17  import org.mule.api.lifecycle.Startable;
18  import org.mule.api.lifecycle.Stoppable;
19  import org.mule.api.model.Model;
20  import org.mule.api.registry.Registry;
21  import org.mule.api.routing.OutboundRouter;
22  import org.mule.api.routing.OutboundRouterCollection;
23  import org.mule.api.source.MessageSource;
24  import org.mule.api.transport.Connector;
25  import org.mule.context.notification.MuleContextNotification;
26  import org.mule.lifecycle.LifecycleObject;
27  import org.mule.lifecycle.NotificationLifecycleObject;
28  
29  import java.util.LinkedHashSet;
30  import java.util.Set;
31  
32  /**
33   * The Stop phase for the Management context LifecycleManager. Calling {@link MuleContext#stop()}
34   * with initiate this phase via the {@link org.mule.api.lifecycle.LifecycleManager}.
35   *
36   *
37   * The MuleContextDisposePhase defines the lifecycle behaviour when the Mule context is stopped.  The MuleContext is associated
38   * with one or more registries that inherit the lifecycle of the MuleContext.
39   *
40   * This phase is responsible for disposing objects. Any object that implements {@link org.mule.api.lifecycle.Stoppable} will
41   * have its {@link org.mule.api.lifecycle.Stoppable#stop()} ()} method called.  Objects are initialised in the order based on type:
42   * {@link org.mule.api.service.Service}, {@link org.mule.api.model.Model}, {@link org.mule.api.agent.Agent}, {@link org.mule.api.transport.Connector}, followed
43   * by any other object that implements {@link org.mule.api.lifecycle.Stoppable}.
44   *
45   * @see org.mule.api.MuleContext
46   * @see org.mule.api.lifecycle.LifecycleManager
47   * @see org.mule.api.lifecycle.Stoppable
48   *
49   * @since 3.0
50   */
51  public class MuleContextStopPhase extends DefaultLifecyclePhase
52  {
53      public MuleContextStopPhase()
54      {
55          this(new Class[]{Registry.class, MuleContext.class, MessageSource.class, Component.class, OutboundRouterCollection.class, OutboundRouter.class});
56      }
57  
58      public MuleContextStopPhase(Class<?>[] ignorredObjects)
59      {
60          super(Stoppable.PHASE_NAME, Stoppable.class, Startable.PHASE_NAME);
61  
62          Set<LifecycleObject> stopOrderedObjects = new LinkedHashSet<LifecycleObject>();
63          // Stop in the opposite order to start
64          stopOrderedObjects.add(new NotificationLifecycleObject(FlowConstruct.class));
65          stopOrderedObjects.add(new NotificationLifecycleObject(Model.class, MuleContextNotification.class));
66          stopOrderedObjects.add(new NotificationLifecycleObject(Agent.class));
67          stopOrderedObjects.add(new NotificationLifecycleObject(Connector.class));
68          stopOrderedObjects.add(new NotificationLifecycleObject(Stoppable.class));
69  
70          setIgnoredObjectTypes(ignorredObjects);
71          setOrderedLifecycleObjects(stopOrderedObjects);
72          //Yuo can initialise and stop
73          registerSupportedPhase(Initialisable.PHASE_NAME);
74          //Stop/Start/Stop
75          registerSupportedPhase(Startable.PHASE_NAME);
76      }
77  }