1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.lifecycle.phases; |
11 | |
|
12 | |
import org.mule.api.agent.Agent; |
13 | |
import org.mule.api.component.Component; |
14 | |
import org.mule.api.construct.FlowConstruct; |
15 | |
import org.mule.api.lifecycle.Disposable; |
16 | |
import org.mule.api.lifecycle.Initialisable; |
17 | |
import org.mule.api.lifecycle.LifecycleException; |
18 | |
import org.mule.api.model.Model; |
19 | |
import org.mule.api.routing.OutboundRouter; |
20 | |
import org.mule.api.routing.OutboundRouterCollection; |
21 | |
import org.mule.api.source.MessageSource; |
22 | |
import org.mule.api.transport.Connector; |
23 | |
import org.mule.config.i18n.CoreMessages; |
24 | |
import org.mule.lifecycle.LifecycleObject; |
25 | |
import org.mule.lifecycle.NotificationLifecycleObject; |
26 | |
import org.mule.util.annotation.AnnotationMetaData; |
27 | |
import org.mule.util.annotation.AnnotationUtils; |
28 | |
|
29 | |
import java.lang.reflect.Method; |
30 | |
import java.util.LinkedHashSet; |
31 | |
import java.util.List; |
32 | |
import java.util.Set; |
33 | |
|
34 | |
import javax.annotation.PostConstruct; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public class MuleContextInitialisePhase extends DefaultLifecyclePhase |
51 | |
{ |
52 | |
public MuleContextInitialisePhase() |
53 | |
{ |
54 | 0 | super(Initialisable.PHASE_NAME, Initialisable.class, Disposable.PHASE_NAME); |
55 | 0 | registerSupportedPhase(NotInLifecyclePhase.PHASE_NAME); |
56 | |
|
57 | 0 | Set<LifecycleObject> startOrderedObjects = new LinkedHashSet<LifecycleObject>(); |
58 | 0 | startOrderedObjects.add(new NotificationLifecycleObject(Connector.class)); |
59 | 0 | startOrderedObjects.add(new NotificationLifecycleObject(Agent.class)); |
60 | 0 | startOrderedObjects.add(new NotificationLifecycleObject(Model.class)); |
61 | 0 | startOrderedObjects.add(new NotificationLifecycleObject(FlowConstruct.class)); |
62 | 0 | startOrderedObjects.add(new NotificationLifecycleObject(Initialisable.class)); |
63 | 0 | setOrderedLifecycleObjects(startOrderedObjects); |
64 | 0 | setIgnoredObjectTypes(new Class[]{Component.class, MessageSource.class, OutboundRouterCollection.class, OutboundRouter.class}); |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
@Override |
69 | |
public void applyLifecycle(Object o) throws LifecycleException |
70 | |
{ |
71 | |
|
72 | 0 | super.applyLifecycle(o); |
73 | 0 | if (o == null) |
74 | |
{ |
75 | 0 | return; |
76 | |
} |
77 | 0 | if (ignoreType(o.getClass())) |
78 | |
{ |
79 | 0 | return; |
80 | |
} |
81 | |
|
82 | |
|
83 | 0 | List<AnnotationMetaData> annos = AnnotationUtils.getMethodAnnotations(o.getClass(), PostConstruct.class); |
84 | |
|
85 | |
|
86 | |
|
87 | 0 | if (annos.size() == 1) |
88 | |
{ |
89 | 0 | AnnotationMetaData anno = annos.get(0); |
90 | |
|
91 | |
try |
92 | |
{ |
93 | 0 | ((Method) anno.getMember()).invoke(o); |
94 | |
} |
95 | 0 | catch (Exception e) |
96 | |
{ |
97 | 0 | throw new LifecycleException(CoreMessages.failedToInvokeLifecycle(anno.getMember().getName(), o), e, this); |
98 | 0 | } |
99 | |
} |
100 | |
|
101 | 0 | } |
102 | |
} |