1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.extras.spring.events; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.MuleRuntimeException; |
15 | |
import org.mule.config.MuleConfiguration; |
16 | |
import org.mule.config.ThreadingProfile; |
17 | |
import org.mule.config.builders.QuickConfigurationBuilder; |
18 | |
import org.mule.extras.spring.SpringContainerContext; |
19 | |
import org.mule.extras.spring.i18n.SpringMessages; |
20 | |
import org.mule.impl.MuleDescriptor; |
21 | |
import org.mule.impl.MuleEvent; |
22 | |
import org.mule.impl.MuleMessage; |
23 | |
import org.mule.impl.MuleSession; |
24 | |
import org.mule.impl.RequestContext; |
25 | |
import org.mule.impl.endpoint.MuleEndpoint; |
26 | |
import org.mule.impl.endpoint.MuleEndpointURI; |
27 | |
import org.mule.impl.model.ModelHelper; |
28 | |
import org.mule.impl.model.seda.SedaModel; |
29 | |
import org.mule.providers.AbstractConnector; |
30 | |
import org.mule.routing.filters.ObjectFilter; |
31 | |
import org.mule.routing.filters.WildcardFilter; |
32 | |
import org.mule.umo.UMOComponent; |
33 | |
import org.mule.umo.UMODescriptor; |
34 | |
import org.mule.umo.UMOEventContext; |
35 | |
import org.mule.umo.UMOException; |
36 | |
import org.mule.umo.UMOSession; |
37 | |
import org.mule.umo.endpoint.MalformedEndpointException; |
38 | |
import org.mule.umo.endpoint.UMOEndpoint; |
39 | |
import org.mule.umo.endpoint.UMOEndpointURI; |
40 | |
import org.mule.umo.lifecycle.InitialisationException; |
41 | |
import org.mule.umo.manager.UMOManager; |
42 | |
import org.mule.umo.model.UMOModel; |
43 | |
import org.mule.umo.provider.UMOConnector; |
44 | |
import org.mule.umo.routing.UMOInboundRouterCollection; |
45 | |
import org.mule.umo.transformer.TransformerException; |
46 | |
import org.mule.umo.transformer.UMOTransformer; |
47 | |
import org.mule.util.ClassUtils; |
48 | |
import org.mule.util.MapUtils; |
49 | |
|
50 | |
import java.beans.ExceptionListener; |
51 | |
import java.util.ArrayList; |
52 | |
import java.util.Iterator; |
53 | |
import java.util.List; |
54 | |
import java.util.Map; |
55 | |
import java.util.Set; |
56 | |
|
57 | |
import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArraySet; |
58 | |
import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService; |
59 | |
import org.apache.commons.logging.Log; |
60 | |
import org.apache.commons.logging.LogFactory; |
61 | |
import org.springframework.beans.BeansException; |
62 | |
import org.springframework.beans.factory.DisposableBean; |
63 | |
import org.springframework.context.ApplicationContext; |
64 | |
import org.springframework.context.ApplicationContextAware; |
65 | |
import org.springframework.context.ApplicationEvent; |
66 | |
import org.springframework.context.ApplicationListener; |
67 | |
import org.springframework.context.event.ApplicationEventMulticaster; |
68 | |
import org.springframework.context.event.ContextClosedEvent; |
69 | |
import org.springframework.context.event.ContextRefreshedEvent; |
70 | |
import org.springframework.context.support.AbstractApplicationContext; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | 58 | public class MuleEventMulticaster implements ApplicationEventMulticaster, ApplicationContextAware, DisposableBean |
121 | |
{ |
122 | |
public static final String EVENT_MULTICASTER_DESCRIPTOR_NAME = "muleEventMulticasterDescriptor"; |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | 16 | protected static final Log logger = LogFactory.getLog(MuleEventMulticaster.class); |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | 58 | protected final Set listeners = new CopyOnWriteArraySet(); |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | 58 | protected boolean asynchronous = false; |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | 58 | protected ExecutorService asyncPool = null; |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | 58 | protected Map endpointMappings = null; |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | 58 | protected String[] subscriptions = null; |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
protected ApplicationContext applicationContext; |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
protected UMODescriptor descriptor; |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
protected UMOComponent component; |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | 58 | protected Class subscriptionFilter = WildcardFilter.class; |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | 58 | protected ExceptionListener exceptionListener = new LoggingExceptionListener(); |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
public void addApplicationListener(ApplicationListener listener) |
197 | |
{ |
198 | 292 | Object listenerToAdd = listener; |
199 | |
|
200 | 292 | if (asynchronous) |
201 | |
{ |
202 | 94 | listenerToAdd = new AsynchronousEventListener(asyncPool, listener); |
203 | |
} |
204 | |
|
205 | 292 | listeners.add(listenerToAdd); |
206 | 292 | } |
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public void removeApplicationListener(ApplicationListener listener) |
214 | |
{ |
215 | 6 | for (Iterator iterator = listeners.iterator(); iterator.hasNext();) |
216 | |
{ |
217 | 6 | ApplicationListener applicationListener = (ApplicationListener)iterator.next(); |
218 | 6 | if (applicationListener instanceof AsynchronousEventListener) |
219 | |
{ |
220 | 2 | if (((AsynchronousEventListener)applicationListener).getListener().equals(listener)) |
221 | |
{ |
222 | 2 | listeners.remove(applicationListener); |
223 | 2 | return; |
224 | |
} |
225 | |
} |
226 | |
else |
227 | |
{ |
228 | 4 | if (applicationListener.equals(listener)) |
229 | |
{ |
230 | 4 | listeners.remove(applicationListener); |
231 | 4 | return; |
232 | |
} |
233 | |
} |
234 | 0 | } |
235 | 0 | listeners.remove(listener); |
236 | 0 | } |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
public void removeAllListeners() |
242 | |
{ |
243 | 6 | listeners.clear(); |
244 | 6 | } |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
public void multicastEvent(ApplicationEvent e) |
260 | |
{ |
261 | 466 | MuleApplicationEvent muleEvent = null; |
262 | |
|
263 | 466 | if (e instanceof ContextRefreshedEvent) |
264 | |
{ |
265 | |
|
266 | |
|
267 | 58 | if (MuleManager.isInstanciated() && !MuleManager.getInstance().isInitialised()) |
268 | |
{ |
269 | |
try |
270 | |
{ |
271 | 2 | registerMulticasterDescriptor(); |
272 | |
} |
273 | 0 | catch (UMOException ex) |
274 | |
{ |
275 | 0 | throw new MuleRuntimeException(SpringMessages.failedToReinitMule(), ex); |
276 | 2 | } |
277 | |
} |
278 | |
else |
279 | |
{ |
280 | 56 | initMule(); |
281 | |
} |
282 | |
} |
283 | 408 | else if (e instanceof ContextClosedEvent) |
284 | |
{ |
285 | 52 | MuleManager.getInstance().dispose(); |
286 | 52 | return; |
287 | |
} |
288 | 356 | else if (e instanceof MuleApplicationEvent) |
289 | |
{ |
290 | 346 | muleEvent = (MuleApplicationEvent)e; |
291 | |
|
292 | |
|
293 | 346 | if (muleEvent.getMuleEventContext() == null) |
294 | |
{ |
295 | |
try |
296 | |
{ |
297 | 126 | dispatchEvent(muleEvent); |
298 | |
} |
299 | 0 | catch (ApplicationEventException e1) |
300 | |
{ |
301 | 0 | exceptionListener.exceptionThrown(e1); |
302 | 126 | } |
303 | 126 | return; |
304 | |
} |
305 | |
} |
306 | |
|
307 | 288 | for (Iterator iterator = listeners.iterator(); iterator.hasNext();) |
308 | |
{ |
309 | 1394 | ApplicationListener listener = (ApplicationListener)iterator.next(); |
310 | 1394 | if (muleEvent != null) |
311 | |
{ |
312 | |
|
313 | |
|
314 | |
|
315 | 1064 | if (listener instanceof AsynchronousEventListener) |
316 | |
{ |
317 | 348 | AsynchronousEventListener asyncListener = (AsynchronousEventListener)listener; |
318 | 348 | if (asyncListener.getListener() instanceof MuleSubscriptionEventListener) |
319 | |
{ |
320 | 138 | if (isSubscriptionMatch(muleEvent.getEndpoint(), |
321 | |
((MuleSubscriptionEventListener)asyncListener.getListener()).getSubscriptions())) |
322 | |
{ |
323 | 68 | asyncListener.onApplicationEvent(muleEvent); |
324 | |
} |
325 | |
} |
326 | 210 | else if (asyncListener.getListener() instanceof MuleEventListener) |
327 | |
{ |
328 | 140 | asyncListener.onApplicationEvent(muleEvent); |
329 | |
} |
330 | 70 | else if (!(asyncListener.getListener() instanceof MuleEventListener)) |
331 | |
{ |
332 | 70 | asyncListener.onApplicationEvent(e); |
333 | |
} |
334 | |
|
335 | 348 | } |
336 | 716 | else if (listener instanceof MuleSubscriptionEventListener) |
337 | |
{ |
338 | 284 | if (isSubscriptionMatch(muleEvent.getEndpoint(), |
339 | |
((MuleSubscriptionEventListener)listener).getSubscriptions())) |
340 | |
{ |
341 | 140 | listener.onApplicationEvent(muleEvent); |
342 | |
} |
343 | |
} |
344 | 432 | else if (listener instanceof MuleEventListener) |
345 | |
{ |
346 | 288 | listener.onApplicationEvent(muleEvent); |
347 | |
} |
348 | |
} |
349 | 330 | else if (listener instanceof AsynchronousEventListener |
350 | |
&& !(((AsynchronousEventListener)listener).getListener() instanceof MuleEventListener)) |
351 | |
{ |
352 | 20 | listener.onApplicationEvent(e); |
353 | |
} |
354 | 310 | else if (!(listener instanceof MuleEventListener)) |
355 | |
{ |
356 | 46 | listener.onApplicationEvent(e); |
357 | |
} |
358 | |
else |
359 | |
{ |
360 | |
|
361 | |
|
362 | 608 | for (int i = 0; i < listener.getClass().getInterfaces().length; i++) |
363 | |
{ |
364 | 390 | if (listener.getClass().getInterfaces()[i].equals(ApplicationListener.class)) |
365 | |
{ |
366 | 46 | listener.onApplicationEvent(e); |
367 | 46 | break; |
368 | |
} |
369 | |
} |
370 | |
|
371 | |
} |
372 | 1394 | } |
373 | 288 | } |
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
private boolean isSubscriptionMatch(String endpoint, String[] subscriptions) |
383 | |
{ |
384 | 636 | for (int i = 0; i < subscriptions.length; i++) |
385 | |
{ |
386 | 422 | String subscription = MapUtils.getString(MuleManager.getInstance().getEndpointIdentifiers(), |
387 | |
subscriptions[i], subscriptions[i]); |
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | 422 | ObjectFilter filter = createFilter(subscription); |
407 | 422 | if (filter.accept(endpoint)) |
408 | |
{ |
409 | 208 | return true; |
410 | |
} |
411 | |
} |
412 | 214 | return false; |
413 | |
} |
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
public boolean isAsynchronous() |
421 | |
{ |
422 | 0 | return asynchronous; |
423 | |
} |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
public void setAsynchronous(boolean asynchronous) |
431 | |
{ |
432 | 18 | this.asynchronous = asynchronous; |
433 | 18 | if (asynchronous) |
434 | |
{ |
435 | 18 | if (asyncPool == null) |
436 | |
{ |
437 | 18 | asyncPool = MuleManager.getConfiguration().getDefaultThreadingProfile().createPool( |
438 | |
"spring-events"); |
439 | |
} |
440 | |
} |
441 | |
else |
442 | |
{ |
443 | 0 | if (asyncPool != null) |
444 | |
{ |
445 | 0 | asyncPool.shutdown(); |
446 | 0 | asyncPool = null; |
447 | |
} |
448 | |
} |
449 | 18 | } |
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
public void onMuleEvent(UMOEventContext context) throws TransformerException, MalformedEndpointException |
458 | |
{ |
459 | 220 | multicastEvent(new MuleApplicationEvent(context.getTransformedMessage(), context, applicationContext)); |
460 | 220 | context.setStopFurtherProcessing(true); |
461 | 220 | } |
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
protected void dispatchEvent(MuleApplicationEvent applicationEvent) throws ApplicationEventException |
471 | |
{ |
472 | 126 | UMOEndpoint endpoint = null; |
473 | |
try |
474 | |
{ |
475 | 126 | endpoint = MuleEndpoint.getOrCreateEndpointForUri(applicationEvent.getEndpoint(), |
476 | |
UMOEndpoint.ENDPOINT_TYPE_SENDER); |
477 | |
} |
478 | 0 | catch (UMOException e) |
479 | |
{ |
480 | 0 | throw new ApplicationEventException("Failed to get endpoint for endpointUri: " |
481 | |
+ applicationEvent.getEndpoint(), e); |
482 | 126 | } |
483 | 126 | if (endpoint != null) |
484 | |
{ |
485 | |
try |
486 | |
{ |
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | 126 | MuleMessage message = new MuleMessage(applicationEvent.getSource(), |
492 | |
applicationEvent.getProperties()); |
493 | |
|
494 | |
|
495 | 126 | if (applicationEvent.getMuleEventContext() != null) |
496 | |
{ |
497 | |
|
498 | 0 | applicationEvent.getMuleEventContext().setStopFurtherProcessing(true); |
499 | 0 | applicationEvent.getMuleEventContext().dispatchEvent(message, endpoint); |
500 | |
} |
501 | |
else |
502 | |
{ |
503 | 126 | UMOSession session = new MuleSession(message, |
504 | |
((AbstractConnector)endpoint.getConnector()).getSessionHandler(), component); |
505 | 126 | RequestContext.setEvent(new MuleEvent(message, endpoint, session, false)); |
506 | |
|
507 | 126 | if (endpoint.getTransformer() != null) |
508 | |
{ |
509 | 6 | message = new MuleMessage(endpoint.getTransformer().transform( |
510 | |
applicationEvent.getSource()), applicationEvent.getProperties()); |
511 | |
} |
512 | 126 | endpoint.dispatch(new MuleEvent(message, endpoint, session, false)); |
513 | |
} |
514 | |
} |
515 | 0 | catch (Exception e1) |
516 | |
{ |
517 | 0 | throw new ApplicationEventException("Failed to dispatch event: " + e1.getMessage(), e1); |
518 | 126 | } |
519 | |
} |
520 | |
else |
521 | |
{ |
522 | 0 | throw new ApplicationEventException("Failed endpoint using name: " |
523 | |
+ applicationEvent.getEndpoint()); |
524 | |
} |
525 | 126 | } |
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException |
534 | |
{ |
535 | 58 | this.applicationContext = applicationContext; |
536 | 58 | } |
537 | |
|
538 | |
protected void initMule() |
539 | |
{ |
540 | |
try |
541 | |
{ |
542 | |
|
543 | |
|
544 | 56 | if (applicationContext.containsBean(EVENT_MULTICASTER_DESCRIPTOR_NAME)) |
545 | |
{ |
546 | 0 | descriptor = (UMODescriptor)applicationContext.getBean(EVENT_MULTICASTER_DESCRIPTOR_NAME); |
547 | |
} |
548 | |
|
549 | |
|
550 | 56 | if (applicationContext.containsBean("muleManager")) |
551 | |
{ |
552 | |
|
553 | 20 | registerMulticasterDescriptor(); |
554 | 20 | return; |
555 | |
} |
556 | 36 | UMOManager manager = MuleManager.getInstance(); |
557 | 36 | Map map = applicationContext.getBeansOfType(MuleConfiguration.class); |
558 | 36 | if (map != null && map.size() > 0) |
559 | |
{ |
560 | 36 | MuleManager.setConfiguration((MuleConfiguration)map.values().iterator().next()); |
561 | |
} |
562 | 36 | if (!manager.isStarted()) |
563 | |
{ |
564 | 36 | MuleManager.getConfiguration().setSynchronous(!asynchronous); |
565 | |
|
566 | 36 | registerEndpointMappings(); |
567 | |
} |
568 | |
|
569 | 36 | SpringContainerContext containerContext = new SpringContainerContext(); |
570 | 36 | containerContext.setBeanFactory(applicationContext); |
571 | 36 | manager.setContainerContext(null); |
572 | 36 | manager.setContainerContext(containerContext); |
573 | |
|
574 | |
|
575 | 36 | registerConnectors(); |
576 | |
|
577 | |
|
578 | 36 | registerTransformers(); |
579 | |
|
580 | 36 | registerGlobalEndpoints(); |
581 | |
|
582 | |
|
583 | 36 | registerMulticasterDescriptor(); |
584 | |
|
585 | 36 | if (!manager.isStarted()) |
586 | |
{ |
587 | 36 | manager.start(); |
588 | |
} |
589 | |
} |
590 | 0 | catch (UMOException e) |
591 | |
{ |
592 | 0 | throw new MuleRuntimeException(SpringMessages.failedToReinitMule(), e); |
593 | 36 | } |
594 | 36 | } |
595 | |
|
596 | |
protected void registerMulticasterDescriptor() throws UMOException |
597 | |
{ |
598 | |
|
599 | 58 | if (descriptor == null) |
600 | |
{ |
601 | 58 | descriptor = getDefaultDescriptor(); |
602 | 58 | setSubscriptionsOnDescriptor((MuleDescriptor)descriptor); |
603 | 58 | component = MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL).registerComponent(descriptor); |
604 | |
} |
605 | 58 | } |
606 | |
|
607 | |
protected void setSubscriptionsOnDescriptor(MuleDescriptor descriptor) throws UMOException |
608 | |
{ |
609 | 58 | List endpoints = new ArrayList(); |
610 | 58 | for (Iterator iterator = listeners.iterator(); iterator.hasNext();) |
611 | |
{ |
612 | 280 | ApplicationListener listener = (ApplicationListener)iterator.next(); |
613 | 280 | if (listener instanceof AsynchronousEventListener) |
614 | |
{ |
615 | 90 | listener = ((AsynchronousEventListener)listener).getListener(); |
616 | |
} |
617 | 280 | if (listener instanceof MuleSubscriptionEventListener) |
618 | |
{ |
619 | 112 | String[] subscriptions = ((MuleSubscriptionEventListener)listener).getSubscriptions(); |
620 | 224 | for (int i = 0; i < subscriptions.length; i++) |
621 | |
{ |
622 | 112 | if (subscriptions[i].indexOf("*") == -1 && MuleEndpointURI.isMuleUri(subscriptions[i])) |
623 | |
{ |
624 | 56 | boolean isSoap = registerAsSoap(subscriptions[i], listener); |
625 | |
|
626 | 56 | if (!isSoap) |
627 | |
{ |
628 | 56 | endpoints.add(subscriptions[i]); |
629 | |
} |
630 | |
} |
631 | |
} |
632 | |
} |
633 | 280 | } |
634 | 58 | if (endpoints.size() > 0) |
635 | |
{ |
636 | 56 | for (Iterator iterator = endpoints.iterator(); iterator.hasNext();) |
637 | |
{ |
638 | 56 | String endpoint = (String)iterator.next(); |
639 | 56 | MuleEndpoint ep = new MuleEndpoint(endpoint, true); |
640 | |
|
641 | |
|
642 | 56 | if (descriptor.getInboundRouter().getEndpoint(ep.getName()) == null) |
643 | |
{ |
644 | 56 | descriptor.getInboundRouter().addEndpoint(ep); |
645 | |
} |
646 | 56 | } |
647 | |
} |
648 | 58 | } |
649 | |
|
650 | |
private boolean registerAsSoap(String endpoint, Object listener) throws UMOException |
651 | |
{ |
652 | 56 | if (endpoint.startsWith("glue") || endpoint.startsWith("soap") || endpoint.startsWith("axis")) |
653 | |
{ |
654 | 0 | UMOEndpointURI ep = new MuleEndpointURI(endpoint); |
655 | 0 | QuickConfigurationBuilder builder = new QuickConfigurationBuilder(); |
656 | |
|
657 | |
|
658 | 0 | String serviceName = null; |
659 | 0 | if (ep.getPath() != null) |
660 | |
{ |
661 | 0 | String path = ep.getPath(); |
662 | 0 | if (path.endsWith("/")) |
663 | |
{ |
664 | 0 | path = path.substring(0, path.length() - 1); |
665 | |
} |
666 | 0 | int i = path.lastIndexOf("/"); |
667 | 0 | if (i > -1) |
668 | |
{ |
669 | 0 | serviceName = path.substring(i + 1); |
670 | |
} |
671 | 0 | } |
672 | |
else |
673 | |
{ |
674 | 0 | serviceName = descriptor.getName(); |
675 | |
} |
676 | |
|
677 | 0 | String newEndpoint = endpoint; |
678 | 0 | int i = newEndpoint.indexOf(serviceName); |
679 | 0 | newEndpoint = newEndpoint.substring(0, i - 1); |
680 | 0 | builder.registerComponentInstance(listener, serviceName, new MuleEndpointURI(newEndpoint)); |
681 | 0 | return true; |
682 | |
} |
683 | |
else |
684 | |
{ |
685 | 56 | return false; |
686 | |
} |
687 | |
} |
688 | |
|
689 | |
protected void registerEndpointMappings() throws InitialisationException |
690 | |
{ |
691 | |
|
692 | 36 | if (endpointMappings != null) |
693 | |
{ |
694 | 36 | Map.Entry entry = null; |
695 | 36 | for (Iterator iterator = endpointMappings.entrySet().iterator(); iterator.hasNext();) |
696 | |
{ |
697 | 36 | entry = (Map.Entry)iterator.next(); |
698 | 36 | MuleManager.getInstance().registerEndpointIdentifier((String)entry.getKey(), |
699 | |
(String)entry.getValue()); |
700 | |
} |
701 | |
} |
702 | 36 | } |
703 | |
|
704 | |
protected void registerConnectors() throws UMOException |
705 | |
{ |
706 | 36 | if (!MuleManager.getInstance().isInitialised()) |
707 | |
{ |
708 | |
|
709 | 36 | Map connectors = applicationContext.getBeansOfType(UMOConnector.class, true, true); |
710 | 36 | if (connectors.size() > 0) |
711 | |
{ |
712 | |
Map.Entry entry; |
713 | |
UMOConnector c; |
714 | 0 | for (Iterator iterator = connectors.entrySet().iterator(); iterator.hasNext();) |
715 | |
{ |
716 | 0 | entry = (Map.Entry)iterator.next(); |
717 | 0 | c = (UMOConnector)entry.getValue(); |
718 | 0 | if (c.getName() == null) |
719 | |
{ |
720 | 0 | c.setName(entry.getKey().toString()); |
721 | |
} |
722 | 0 | MuleManager.getInstance().registerConnector(c); |
723 | |
} |
724 | |
} |
725 | |
} |
726 | 36 | } |
727 | |
|
728 | |
protected void registerGlobalEndpoints() throws UMOException |
729 | |
{ |
730 | 36 | if (!MuleManager.getInstance().isInitialised()) |
731 | |
{ |
732 | |
|
733 | 36 | Map endpoints = applicationContext.getBeansOfType(UMOEndpoint.class, true, true); |
734 | 36 | if (endpoints.size() > 0) |
735 | |
{ |
736 | |
Map.Entry entry; |
737 | |
UMOEndpoint endpoint; |
738 | 0 | for (Iterator iterator = endpoints.entrySet().iterator(); iterator.hasNext();) |
739 | |
{ |
740 | 0 | entry = (Map.Entry)iterator.next(); |
741 | 0 | endpoint = (UMOEndpoint)entry.getValue(); |
742 | 0 | if (endpoint.getName() == null) |
743 | |
{ |
744 | 0 | endpoint.setName(entry.getKey().toString()); |
745 | |
} |
746 | 0 | MuleManager.getInstance().registerEndpoint(endpoint); |
747 | |
} |
748 | |
} |
749 | |
} |
750 | 36 | } |
751 | |
|
752 | |
protected void registerTransformers() throws UMOException |
753 | |
{ |
754 | 36 | if (!MuleManager.getInstance().isInitialised()) |
755 | |
{ |
756 | |
|
757 | 36 | Map transformers = applicationContext.getBeansOfType(UMOTransformer.class, true, true); |
758 | 36 | if (transformers.size() > 0) |
759 | |
{ |
760 | |
Map.Entry entry; |
761 | |
UMOTransformer t; |
762 | 0 | for (Iterator iterator = transformers.entrySet().iterator(); iterator.hasNext();) |
763 | |
{ |
764 | 0 | entry = (Map.Entry)iterator.next(); |
765 | 0 | t = (UMOTransformer)entry.getValue(); |
766 | 0 | if (t.getName() == null) |
767 | |
{ |
768 | 0 | t.setName(entry.getKey().toString()); |
769 | |
} |
770 | 0 | MuleManager.getInstance().registerTransformer(t); |
771 | |
} |
772 | |
} |
773 | |
} |
774 | 36 | } |
775 | |
|
776 | |
protected UMODescriptor getDefaultDescriptor() throws UMOException |
777 | |
{ |
778 | |
|
779 | |
|
780 | 58 | UMOModel model = MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL); |
781 | 58 | if(model==null) |
782 | |
{ |
783 | 0 | model = new SedaModel(); |
784 | 0 | model.setName(ModelHelper.SYSTEM_MODEL); |
785 | 0 | MuleManager.getInstance().registerModel(model); |
786 | |
} |
787 | 58 | UMODescriptor descriptor = model.getDescriptor(EVENT_MULTICASTER_DESCRIPTOR_NAME); |
788 | 58 | if (descriptor != null) |
789 | |
{ |
790 | 0 | model.unregisterComponent(descriptor); |
791 | |
} |
792 | 58 | descriptor = new MuleDescriptor(EVENT_MULTICASTER_DESCRIPTOR_NAME); |
793 | 58 | if (subscriptions == null) |
794 | |
{ |
795 | 0 | logger.info("No receive endpoints have been set, using default '*'"); |
796 | 0 | descriptor.setInboundEndpoint(new MuleEndpoint("vm://*", true)); |
797 | |
} |
798 | |
else |
799 | |
{ |
800 | |
|
801 | 58 | UMOInboundRouterCollection messageRouter = descriptor.getInboundRouter(); |
802 | |
|
803 | 116 | for (int i = 0; i < subscriptions.length; i++) |
804 | |
{ |
805 | 58 | String subscription = subscriptions[i]; |
806 | 58 | UMOEndpointURI endpointUri = new MuleEndpointURI(subscription); |
807 | 58 | UMOEndpoint endpoint = MuleEndpoint.getOrCreateEndpointForUri(endpointUri, |
808 | |
UMOEndpoint.ENDPOINT_TYPE_RECEIVER); |
809 | 58 | if (!asynchronous) |
810 | |
{ |
811 | 40 | endpoint.setSynchronous(true); |
812 | |
} |
813 | 58 | messageRouter.addEndpoint(endpoint); |
814 | |
} |
815 | |
} |
816 | |
|
817 | 58 | descriptor.setImplementation(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME); |
818 | 58 | return descriptor; |
819 | |
} |
820 | |
|
821 | |
protected ObjectFilter createFilter(String pattern) |
822 | |
{ |
823 | |
try |
824 | |
{ |
825 | 422 | if (getSubscriptionFilter() == null) |
826 | |
{ |
827 | 0 | setSubscriptionFilter(WildcardFilter.class); |
828 | |
} |
829 | 422 | ObjectFilter filter = (ObjectFilter)ClassUtils.instanciateClass(getSubscriptionFilter(), |
830 | |
new Object[]{pattern}); |
831 | 422 | return filter; |
832 | |
} |
833 | 0 | catch (Exception e) |
834 | |
{ |
835 | 0 | exceptionListener.exceptionThrown(e); |
836 | 0 | return new WildcardFilter(pattern); |
837 | |
} |
838 | |
} |
839 | |
|
840 | |
|
841 | |
|
842 | |
|
843 | |
|
844 | |
|
845 | |
|
846 | |
public Class getSubscriptionFilter() |
847 | |
{ |
848 | 844 | return subscriptionFilter; |
849 | |
} |
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
|
856 | |
public void setSubscriptionFilter(Class subscriptionFilter) |
857 | |
{ |
858 | 0 | this.subscriptionFilter = subscriptionFilter; |
859 | 0 | } |
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
|
865 | |
|
866 | |
|
867 | |
|
868 | |
public Map getEndpointMappings() |
869 | |
{ |
870 | 0 | return endpointMappings; |
871 | |
} |
872 | |
|
873 | |
|
874 | |
|
875 | |
|
876 | |
|
877 | |
|
878 | |
|
879 | |
|
880 | |
public void setEndpointMappings(Map endpointMappings) |
881 | |
{ |
882 | 56 | this.endpointMappings = endpointMappings; |
883 | 56 | } |
884 | |
|
885 | |
|
886 | |
|
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
|
892 | |
|
893 | |
|
894 | |
public String[] getSubscriptions() |
895 | |
{ |
896 | 0 | return subscriptions; |
897 | |
} |
898 | |
|
899 | |
|
900 | |
|
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
|
907 | |
|
908 | |
public void setSubscriptions(String[] subscriptions) |
909 | |
{ |
910 | 58 | this.subscriptions = subscriptions; |
911 | 58 | } |
912 | |
|
913 | |
protected void setExceptionListener(ExceptionListener listener) |
914 | |
{ |
915 | 0 | if (listener != null) |
916 | |
{ |
917 | 0 | this.exceptionListener = listener; |
918 | |
} |
919 | |
else |
920 | |
{ |
921 | 0 | throw new IllegalArgumentException("exceptionListener may not be null"); |
922 | |
} |
923 | 0 | } |
924 | |
|
925 | 58 | private class LoggingExceptionListener implements ExceptionListener |
926 | |
{ |
927 | |
public void exceptionThrown(Exception e) |
928 | |
{ |
929 | 0 | logger.error(e.getMessage(), e); |
930 | 0 | } |
931 | |
} |
932 | |
|
933 | |
|
934 | |
public void destroy() throws Exception |
935 | |
{ |
936 | 58 | MuleManager.getInstance().dispose(); |
937 | 58 | } |
938 | |
} |