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