KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > inbound > WireTap


1 /*
2  * $Id: WireTap.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.routing.inbound;
12
13 import org.mule.MuleManager;
14 import org.mule.impl.ImmutableMuleEndpoint;
15 import org.mule.umo.MessagingException;
16 import org.mule.umo.UMOEvent;
17 import org.mule.umo.UMOException;
18 import org.mule.umo.endpoint.UMOImmutableEndpoint;
19
20 /**
21  * An inbound router that can forward every message to another destination as defined
22  * in the "endpoint" property. This can be a logical destination of a URI. <p/> A
23  * filter can be applied to this router so that only events matching a criteria will
24  * be tapped.
25  *
26  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
27  * @version $Revision: 3798 $
28  */

29 public class WireTap extends SelectiveConsumer
30 {
31     private String JavaDoc endpoint;
32
33     private UMOImmutableEndpoint tap;
34
35     public boolean isMatch(UMOEvent event) throws MessagingException
36     {
37         if (endpoint != null)
38         {
39             return super.isMatch(event);
40         }
41         else
42         {
43             logger.warn("No endpoint identifier is set on this wire tap");
44             return false;
45         }
46     }
47
48     public UMOEvent[] process(UMOEvent event) throws MessagingException
49     {
50
51         try
52         {
53             event.getSession().dispatchEvent(event.getMessage(), tap);
54         }
55         catch (UMOException e)
56         {
57             logger.error(e.getMessage(), e);
58         }
59         return super.process(event);
60     }
61
62     public String JavaDoc getEndpoint()
63     {
64         return endpoint;
65     }
66
67     public void setEndpoint(String JavaDoc endpoint) throws UMOException
68     {
69         this.endpoint = endpoint;
70         if (this.endpoint != null)
71         {
72             tap = MuleManager.getInstance().lookupEndpoint(this.endpoint);
73             if (tap == null)
74             {
75                 tap = new ImmutableMuleEndpoint(this.endpoint, false);
76             }
77         }
78     }
79 }
80
Popular Tags