Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BridgeComponent |
|
| 3.5;3.5 |
1 | /* | |
2 | * $Id: BridgeComponent.java 10529 2008-01-25 05:58:36Z dfeist $ | |
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.component.simple; | |
12 | ||
13 | import org.mule.api.MuleEventContext; | |
14 | import org.mule.api.config.ConfigurationException; | |
15 | import org.mule.api.lifecycle.Callable; | |
16 | import org.mule.api.routing.InboundRouter; | |
17 | import org.mule.api.service.Service; | |
18 | import org.mule.api.service.ServiceAware; | |
19 | import org.mule.routing.inbound.DefaultInboundRouterCollection; | |
20 | import org.mule.routing.inbound.ForwardingConsumer; | |
21 | import org.mule.routing.inbound.InboundPassThroughRouter; | |
22 | ||
23 | import java.util.Iterator; | |
24 | ||
25 | /** | |
26 | * The BridgeComponent is a standard Mule service that enables a bridge between an inbound and outbound endpoints. | |
27 | * Transformers can be used on the endpoints to convert the data being received in order to 'bridge' from one | |
28 | * endpoint transport to another. When the BridgeComponent is used, it configures itself so that it will | |
29 | * not actually be invoked, instead it tells Mule to bypass invocation of the service, which has a slight performance | |
30 | * improvement. Note that because the service is never actually invoked any interceptors configured on the service | |
31 | * will not be invoked either. | |
32 | * | |
33 | * @deprecated along with bridge-service - use an empty service and, if you want an efficient transfer of messages, | |
34 | * add a forwarding-consumer. | |
35 | */ | |
36 | 0 | public class BridgeComponent implements ServiceAware, Callable |
37 | { | |
38 | ||
39 | public Object onCall(MuleEventContext context) throws Exception | |
40 | { | |
41 | 0 | throw new UnsupportedOperationException( |
42 | "A bridge should not ever receive an event, instead the event should be directly dispatched from the inbound endpoint to the outbound router. Service is: " | |
43 | + context.getService().getName()); | |
44 | } | |
45 | ||
46 | public void setService(Service service) throws ConfigurationException | |
47 | { | |
48 | // Add a ForwardingConsumer, which punts message to oubound router, unless already present | |
49 | 0 | boolean registered = false; |
50 | 0 | if(service.getInboundRouter()==null) |
51 | { | |
52 | 0 | service.setInboundRouter(new DefaultInboundRouterCollection()); |
53 | } | |
54 | 0 | for (Iterator routers = service.getInboundRouter().getRouters().iterator(); routers.hasNext();) |
55 | { | |
56 | 0 | InboundRouter router = (InboundRouter) routers.next(); |
57 | //Remove if present | |
58 | 0 | if(router instanceof InboundPassThroughRouter) |
59 | { | |
60 | 0 | service.getInboundRouter().removeRouter(router); |
61 | } | |
62 | 0 | registered = registered || router instanceof ForwardingConsumer; |
63 | ||
64 | 0 | } |
65 | 0 | if (! registered) |
66 | { | |
67 | 0 | service.getInboundRouter().addRouter(new ForwardingConsumer()); |
68 | } | |
69 | // Make sure if other routers on the inbound router, they are honoured | |
70 | 0 | service.getInboundRouter().setMatchAll(true); |
71 | 0 | } |
72 | ||
73 | } |