1
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
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
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 }