View Javadoc

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