1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.context; |
12 | |
|
13 | |
import org.mule.DefaultMuleContext; |
14 | |
import org.mule.api.MuleContext; |
15 | |
import org.mule.api.config.MuleConfiguration; |
16 | |
import org.mule.api.config.ThreadingProfile; |
17 | |
import org.mule.api.context.MuleContextBuilder; |
18 | |
import org.mule.api.context.WorkManager; |
19 | |
import org.mule.api.context.notification.ConnectionNotificationListener; |
20 | |
import org.mule.api.context.notification.CustomNotificationListener; |
21 | |
import org.mule.api.context.notification.ExceptionNotificationListener; |
22 | |
import org.mule.api.context.notification.ManagementNotificationListener; |
23 | |
import org.mule.api.context.notification.ModelNotificationListener; |
24 | |
import org.mule.api.context.notification.MuleContextNotificationListener; |
25 | |
import org.mule.api.context.notification.RegistryNotificationListener; |
26 | |
import org.mule.api.context.notification.RoutingNotificationListener; |
27 | |
import org.mule.api.context.notification.SecurityNotificationListener; |
28 | |
import org.mule.api.context.notification.ServiceNotificationListener; |
29 | |
import org.mule.api.context.notification.TransactionNotificationListener; |
30 | |
import org.mule.api.lifecycle.LifecycleManager; |
31 | |
import org.mule.config.DefaultMuleConfiguration; |
32 | |
import org.mule.context.notification.ConnectionNotification; |
33 | |
import org.mule.context.notification.CustomNotification; |
34 | |
import org.mule.context.notification.ExceptionNotification; |
35 | |
import org.mule.context.notification.ManagementNotification; |
36 | |
import org.mule.context.notification.ModelNotification; |
37 | |
import org.mule.context.notification.MuleContextNotification; |
38 | |
import org.mule.context.notification.RegistryNotification; |
39 | |
import org.mule.context.notification.RoutingNotification; |
40 | |
import org.mule.context.notification.SecurityNotification; |
41 | |
import org.mule.context.notification.ServerNotificationManager; |
42 | |
import org.mule.context.notification.ServiceNotification; |
43 | |
import org.mule.context.notification.TransactionNotification; |
44 | |
import org.mule.lifecycle.GenericLifecycleManager; |
45 | |
import org.mule.lifecycle.phases.MuleContextDisposePhase; |
46 | |
import org.mule.lifecycle.phases.MuleContextInitialisePhase; |
47 | |
import org.mule.lifecycle.phases.MuleContextStartPhase; |
48 | |
import org.mule.lifecycle.phases.MuleContextStopPhase; |
49 | |
import org.mule.util.ClassUtils; |
50 | |
import org.mule.work.DefaultWorkListener; |
51 | |
import org.mule.work.MuleWorkManager; |
52 | |
|
53 | |
import javax.resource.spi.work.WorkListener; |
54 | |
|
55 | |
import org.apache.commons.logging.Log; |
56 | |
import org.apache.commons.logging.LogFactory; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 1164 | public class DefaultMuleContextBuilder implements MuleContextBuilder |
65 | |
{ |
66 | 2 | protected static final Log logger = LogFactory.getLog(DefaultMuleContextBuilder.class); |
67 | |
|
68 | |
protected MuleConfiguration config; |
69 | |
|
70 | |
protected LifecycleManager lifecycleManager; |
71 | |
|
72 | |
protected WorkManager workManager; |
73 | |
|
74 | |
protected WorkListener workListener; |
75 | |
|
76 | |
protected ServerNotificationManager notificationManager; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public MuleContext buildMuleContext() |
82 | |
{ |
83 | 1158 | logger.debug("Building new DefaultMuleContext instance with MuleContextBuilder: " + this); |
84 | 1158 | MuleContext muleContext = new DefaultMuleContext(getMuleConfiguration(), |
85 | |
getWorkManager(), |
86 | |
getWorkListener(), |
87 | |
getLifecycleManager(), |
88 | |
getNotificationManager()); |
89 | 1158 | return muleContext; |
90 | |
} |
91 | |
|
92 | |
public void setMuleConfiguration(MuleConfiguration config) |
93 | |
{ |
94 | 4 | this.config = config; |
95 | 4 | } |
96 | |
|
97 | |
public void setWorkManager(WorkManager workManager) |
98 | |
{ |
99 | 2 | this.workManager = workManager; |
100 | 2 | } |
101 | |
|
102 | |
public void setWorkListener(WorkListener workListener) |
103 | |
{ |
104 | 1142 | this.workListener = workListener; |
105 | 1142 | } |
106 | |
|
107 | |
public void setNotificationManager(ServerNotificationManager notificationManager) |
108 | |
{ |
109 | 2 | this.notificationManager = notificationManager; |
110 | 2 | } |
111 | |
|
112 | |
public void setLifecycleManager(LifecycleManager lifecycleManager) |
113 | |
{ |
114 | 2 | this.lifecycleManager = lifecycleManager; |
115 | 2 | } |
116 | |
|
117 | |
protected MuleConfiguration getMuleConfiguration() |
118 | |
{ |
119 | 1164 | if (config != null) |
120 | |
{ |
121 | 4 | return config; |
122 | |
} |
123 | |
else |
124 | |
{ |
125 | 1160 | return new DefaultMuleConfiguration(); |
126 | |
} |
127 | |
} |
128 | |
|
129 | |
protected LifecycleManager getLifecycleManager() |
130 | |
{ |
131 | 1164 | if (lifecycleManager != null) |
132 | |
{ |
133 | 2 | return lifecycleManager; |
134 | |
} |
135 | |
else |
136 | |
{ |
137 | 1162 | LifecycleManager lifecycleManager = new GenericLifecycleManager(); |
138 | 1162 | lifecycleManager.registerLifecycle(new MuleContextInitialisePhase()); |
139 | 1162 | lifecycleManager.registerLifecycle(new MuleContextStartPhase()); |
140 | 1162 | lifecycleManager.registerLifecycle(new MuleContextStopPhase()); |
141 | 1162 | lifecycleManager.registerLifecycle(new MuleContextDisposePhase()); |
142 | 1162 | return lifecycleManager; |
143 | |
} |
144 | |
} |
145 | |
|
146 | |
protected WorkManager getWorkManager() |
147 | |
{ |
148 | 1164 | if (workManager != null) |
149 | |
{ |
150 | 2 | return workManager; |
151 | |
} |
152 | |
else |
153 | |
{ |
154 | 1162 | return new MuleWorkManager(ThreadingProfile.DEFAULT_THREADING_PROFILE, "MuleServer"); |
155 | |
} |
156 | |
} |
157 | |
|
158 | |
protected WorkListener getWorkListener() |
159 | |
{ |
160 | 1164 | if (workListener != null) |
161 | |
{ |
162 | 1142 | return workListener; |
163 | |
} |
164 | |
else |
165 | |
{ |
166 | 22 | return new DefaultWorkListener(); |
167 | |
} |
168 | |
} |
169 | |
|
170 | |
protected ServerNotificationManager getNotificationManager() |
171 | |
{ |
172 | 1164 | if (notificationManager != null) |
173 | |
{ |
174 | 2 | return notificationManager; |
175 | |
} |
176 | |
else |
177 | |
{ |
178 | 1162 | ServerNotificationManager notificationManager = new ServerNotificationManager(); |
179 | 1162 | notificationManager.addInterfaceToType(MuleContextNotificationListener.class, |
180 | |
MuleContextNotification.class); |
181 | 1162 | notificationManager.addInterfaceToType(ModelNotificationListener.class, ModelNotification.class); |
182 | 1162 | notificationManager.addInterfaceToType(RoutingNotificationListener.class, RoutingNotification.class); |
183 | 1162 | notificationManager.addInterfaceToType(ServiceNotificationListener.class, |
184 | |
ServiceNotification.class); |
185 | 1162 | notificationManager.addInterfaceToType(SecurityNotificationListener.class, |
186 | |
SecurityNotification.class); |
187 | 1162 | notificationManager.addInterfaceToType(ManagementNotificationListener.class, |
188 | |
ManagementNotification.class); |
189 | 1162 | notificationManager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); |
190 | 1162 | notificationManager.addInterfaceToType(ConnectionNotificationListener.class, |
191 | |
ConnectionNotification.class); |
192 | 1162 | notificationManager.addInterfaceToType(RegistryNotificationListener.class, |
193 | |
RegistryNotification.class); |
194 | 1162 | notificationManager.addInterfaceToType(ExceptionNotificationListener.class, |
195 | |
ExceptionNotification.class); |
196 | 1162 | notificationManager.addInterfaceToType(TransactionNotificationListener.class, |
197 | |
TransactionNotification.class); |
198 | 1162 | return notificationManager; |
199 | |
} |
200 | |
} |
201 | |
|
202 | |
public String toString() |
203 | |
{ |
204 | 1158 | return ClassUtils.getClassName(getClass()) + |
205 | |
"{muleConfiguration=" + config + |
206 | |
", lifecycleManager=" + lifecycleManager + |
207 | |
", workManager=" + workManager + |
208 | |
", workListener=" + workListener + |
209 | |
", notificationManager=" + notificationManager + "}"; |
210 | |
} |
211 | |
} |