View Javadoc

1   /*
2    * $Id: MuleContextStartPhase.java 11530 2008-04-08 12:49:14Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.agent.AgentSorter;
14  import org.mule.api.MuleContext;
15  import org.mule.api.agent.Agent;
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.service.Service;
22  import org.mule.api.transport.Connector;
23  import org.mule.context.notification.MuleContextNotification;
24  import org.mule.lifecycle.DefaultLifecyclePhase;
25  import org.mule.lifecycle.LifecycleObject;
26  import org.mule.lifecycle.NotificationLifecycleObject;
27  
28  import java.util.Collection;
29  import java.util.LinkedHashSet;
30  import java.util.List;
31  import java.util.Set;
32  
33  /**
34   * The Start phase for the Management context LifecycleManager. Calling
35   * {@link org.mule.api.UMOManagementContext#start()} with initiate this phase via the
36   * {@link org.mule.api.lifecycle.LifecycleManager}. This phase controls the order in
37   * which objects should be started.
38   * 
39   * @see org.mule.api.UMOManagementContext
40   * @see org.mule.api.lifecycle.LifecycleManager
41   * @see org.mule.api.lifecycle.Startable
42   */
43  public class MuleContextStartPhase extends DefaultLifecyclePhase
44  {
45      public MuleContextStartPhase()
46      {
47          this(new Class[]{Registry.class, MuleContext.class});
48      }
49  
50      public MuleContextStartPhase(Class[] ignorredObjects)
51      {
52          super(Startable.PHASE_NAME, Startable.class, Stoppable.PHASE_NAME);
53  
54          Set startOrderedObjects = new LinkedHashSet();
55          startOrderedObjects.add(new NotificationLifecycleObject(Connector.class));
56          startOrderedObjects.add(new NotificationLifecycleObject(Agent.class));
57          startOrderedObjects.add(new NotificationLifecycleObject(Model.class, MuleContextNotification.class,
58              MuleContextNotification.CONTEXT_STARTING_MODELS, MuleContextNotification.CONTEXT_STARTED_MODELS));
59          startOrderedObjects.add(new NotificationLifecycleObject(Service.class));
60          startOrderedObjects.add(new NotificationLifecycleObject(Startable.class));
61  
62          setIgnoredObjectTypes(ignorredObjects);
63          setOrderedLifecycleObjects(startOrderedObjects);
64          registerSupportedPhase(Stoppable.PHASE_NAME);
65          registerSupportedPhase(Initialisable.PHASE_NAME);
66      }
67  
68      /**
69       * Make sure that the agents are started up in proper order.
70       */
71      protected List sortLifecycleInstances(Collection objects, LifecycleObject lo)
72      {
73          if (!lo.getType().equals(Agent.class))
74          {
75              return super.sortLifecycleInstances(objects, lo);
76          }
77  
78          return AgentSorter.sortAgents(objects);
79      }
80  
81  }