View Javadoc

1   /*
2    * $Id: MuleContextStartPhase.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  
11  package org.mule.lifecycle.phases;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.agent.Agent;
15  import org.mule.api.component.Component;
16  import org.mule.api.construct.FlowConstruct;
17  import org.mule.api.lifecycle.Initialisable;
18  import org.mule.api.lifecycle.Startable;
19  import org.mule.api.lifecycle.Stoppable;
20  import org.mule.api.model.Model;
21  import org.mule.api.registry.Registry;
22  import org.mule.api.routing.OutboundRouter;
23  import org.mule.api.routing.OutboundRouterCollection;
24  import org.mule.api.source.MessageSource;
25  import org.mule.api.transport.Connector;
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 Start phase for the MuleContext. Calling
34   * {@link MuleContext#start()} will initiate this phase via the
35   * {@link org.mule.api.lifecycle.LifecycleManager}.
36   *
37   * The MuleContextStartPhase defines the lifecycle behaviour when the Mule context is started.  The MuleContext is associated
38   * with one or more registries that inherit the lifecycle of the MuleContext.
39   *
40   * This phase is responsible for starting objects. Any object that implements {@link org.mule.api.lifecycle.Startable} will
41   * have its {@link org.mule.api.lifecycle.Startable#start()} method called.  Objects are initialised in the order based on type:
42   * {@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
43   * by any other object that implements {@link org.mule.api.lifecycle.Startable}.
44   *
45   * @see org.mule.api.MuleContext
46   * @see org.mule.api.lifecycle.LifecycleManager
47   * @see org.mule.api.lifecycle.Startable
48   *
49   * @since 3.0
50   */
51  public class MuleContextStartPhase extends DefaultLifecyclePhase
52  {
53      public MuleContextStartPhase()
54      {
55          this(new Class[]{Registry.class, MuleContext.class, MessageSource.class, Component.class, OutboundRouterCollection.class, OutboundRouter.class});
56      }
57  
58      public MuleContextStartPhase(Class<?>[] ignorredObjects)
59      {
60          super(Startable.PHASE_NAME, Startable.class, Stoppable.PHASE_NAME);
61  
62          Set<LifecycleObject> startOrderedObjects = new LinkedHashSet<LifecycleObject>();
63          startOrderedObjects.add(new NotificationLifecycleObject(Connector.class));
64          startOrderedObjects.add(new NotificationLifecycleObject(Agent.class));
65          startOrderedObjects.add(new NotificationLifecycleObject(Model.class));
66          startOrderedObjects.add(new NotificationLifecycleObject(FlowConstruct.class));
67          startOrderedObjects.add(new NotificationLifecycleObject(Startable.class));
68  
69          setIgnoredObjectTypes(ignorredObjects);
70          setOrderedLifecycleObjects(startOrderedObjects);
71          registerSupportedPhase(Initialisable.PHASE_NAME);
72          //Start/Stop/Start 
73          registerSupportedPhase(Stoppable.PHASE_NAME);
74      }
75  }