View Javadoc

1   /*
2    * $Id: MuleContextStopPhase.java 23030 2011-09-26 18:02:33Z mike.schilling $
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  import org.mule.util.queue.TransactionalQueueManager;
29  
30  import java.util.LinkedHashSet;
31  import java.util.Set;
32  
33  /**
34   * The Stop phase for the Management context LifecycleManager. Calling {@link MuleContext#stop()}
35   * with initiate this phase via the {@link org.mule.api.lifecycle.LifecycleManager}.
36   *
37   *
38   * The MuleContextDisposePhase defines the lifecycle behaviour when the Mule context is stopped.  The MuleContext is associated
39   * with one or more registries that inherit the lifecycle of the MuleContext.
40   *
41   * This phase is responsible for disposing objects. Any object that implements {@link org.mule.api.lifecycle.Stoppable} will
42   * have its {@link org.mule.api.lifecycle.Stoppable#stop()} ()} method called.  Objects are initialised in the order based on type:
43   * {@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
44   * by any other object that implements {@link org.mule.api.lifecycle.Stoppable}.
45   *
46   * @see org.mule.api.MuleContext
47   * @see org.mule.api.lifecycle.LifecycleManager
48   * @see org.mule.api.lifecycle.Stoppable
49   *
50   * @since 3.0
51   */
52  public class MuleContextStopPhase extends DefaultLifecyclePhase
53  {
54      public MuleContextStopPhase()
55      {
56          this(new Class[]{Registry.class, MuleContext.class, MessageSource.class, Component.class, OutboundRouterCollection.class, OutboundRouter.class});
57      }
58  
59      public MuleContextStopPhase(Class<?>[] ignorredObjects)
60      {
61          super(Stoppable.PHASE_NAME, Stoppable.class, Startable.PHASE_NAME);
62  
63          Set<LifecycleObject> stopOrderedObjects = new LinkedHashSet<LifecycleObject>();
64          // Stop in the opposite order to start
65          stopOrderedObjects.add(new NotificationLifecycleObject(FlowConstruct.class));
66          stopOrderedObjects.add(new NotificationLifecycleObject(Model.class, MuleContextNotification.class));
67          stopOrderedObjects.add(new NotificationLifecycleObject(Agent.class));
68          stopOrderedObjects.add(new NotificationLifecycleObject(Connector.class));
69          stopOrderedObjects.add(new NotificationLifecycleObject(TransactionalQueueManager.class));
70          stopOrderedObjects.add(new NotificationLifecycleObject(Stoppable.class));
71  
72          setIgnoredObjectTypes(ignorredObjects);
73          setOrderedLifecycleObjects(stopOrderedObjects);
74          //Yuo can initialise and stop
75          registerSupportedPhase(Initialisable.PHASE_NAME);
76          //Stop/Start/Stop
77          registerSupportedPhase(Startable.PHASE_NAME);
78      }
79  }