01: /*
02: * $Id: BridgeComponent.java 10529 2008-01-25 05:58:36Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: public class BridgeComponent implements ServiceAware, Callable {
37:
38: public Object onCall(MuleEventContext context) throws Exception {
39: throw new UnsupportedOperationException(
40: "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: "
41: + context.getService().getName());
42: }
43:
44: public void setService(Service service)
45: throws ConfigurationException {
46: // Add a ForwardingConsumer, which punts message to oubound router, unless already present
47: boolean registered = false;
48: if (service.getInboundRouter() == null) {
49: service
50: .setInboundRouter(new DefaultInboundRouterCollection());
51: }
52: for (Iterator routers = service.getInboundRouter().getRouters()
53: .iterator(); routers.hasNext();) {
54: InboundRouter router = (InboundRouter) routers.next();
55: //Remove if present
56: if (router instanceof InboundPassThroughRouter) {
57: service.getInboundRouter().removeRouter(router);
58: }
59: registered = registered
60: || router instanceof ForwardingConsumer;
61:
62: }
63: if (!registered) {
64: service.getInboundRouter().addRouter(
65: new ForwardingConsumer());
66: }
67: // Make sure if other routers on the inbound router, they are honoured
68: service.getInboundRouter().setMatchAll(true);
69: }
70:
71: }
|