Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BridgeComponent |
|
| 3.0;3 |
1 | /* | |
2 | * $Id: BridgeComponent.java 7963 2007-08-21 08:53:15Z dirk.olmes $ | |
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.components.simple; | |
12 | ||
13 | import org.mule.config.ConfigurationException; | |
14 | import org.mule.impl.UMODescriptorAware; | |
15 | import org.mule.routing.inbound.ForwardingConsumer; | |
16 | import org.mule.umo.UMODescriptor; | |
17 | import org.mule.umo.UMOEventContext; | |
18 | import org.mule.umo.lifecycle.Callable; | |
19 | import org.mule.umo.routing.UMOInboundRouter; | |
20 | ||
21 | import java.util.Iterator; | |
22 | ||
23 | /** | |
24 | * The BridgeComponent is a standard Mule component that enables a bridge between an inbound and outbound endpoints. | |
25 | * Transformers can be used on the endpoints to convert the data being received in order to 'bridge' from one | |
26 | * endpoint transport to another. When the BridgeComponent is used, it configures itself so that it will | |
27 | * not actually be invoked, instead it tells Mule to bypass invocation of the component, which has a slight performance | |
28 | * improvement. Note that because the component is never actually invoked any interceptors configured on the component | |
29 | * will not be invoked either. | |
30 | */ | |
31 | 0 | public class BridgeComponent implements UMODescriptorAware, Callable |
32 | { | |
33 | ||
34 | public void setDescriptor(UMODescriptor descriptor) throws ConfigurationException | |
35 | { | |
36 | // Adding a forwarding consumer will cause the inbound routing to | |
37 | // directly invoke the outbound router, bypassing the component | |
38 | ||
39 | // first check there isn't one already registered | |
40 | 0 | boolean registered = false; |
41 | 0 | for (Iterator iterator = descriptor.getInboundRouter().getRouters().iterator(); iterator.hasNext();) |
42 | { | |
43 | 0 | UMOInboundRouter router = (UMOInboundRouter) iterator.next(); |
44 | 0 | if (router instanceof ForwardingConsumer) |
45 | { | |
46 | 0 | registered = true; |
47 | } | |
48 | ||
49 | 0 | } |
50 | 0 | if (!registered) |
51 | { | |
52 | 0 | descriptor.getInboundRouter().addRouter(new ForwardingConsumer()); |
53 | } | |
54 | // Make sure if other routers on the inbound router, they are honoured | |
55 | 0 | descriptor.getInboundRouter().setMatchAll(true); |
56 | 0 | } |
57 | ||
58 | public Object onCall(UMOEventContext context) throws Exception | |
59 | { | |
60 | 0 | throw new UnsupportedOperationException( |
61 | "A bridge should not ever receive an event, instead the event should be directly dispatched from the inbound endpoint to the outbound router. Component is: " | |
62 | + context.getComponentDescriptor().getName()); | |
63 | } | |
64 | } |