View Javadoc

1   /*
2    * $Id: WireTap.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.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  public class WireTap extends SelectiveConsumer
27  {
28      private volatile String endpoint;
29      private volatile UMOImmutableEndpoint tap;
30  
31      public boolean isMatch(UMOEvent event) throws MessagingException
32      {
33          if (endpoint != null)
34          {
35              return super.isMatch(event);
36          }
37          else
38          {
39              logger.warn("No endpoint identifier is set on this wire tap");
40              return false;
41          }
42      }
43  
44      public UMOEvent[] process(UMOEvent event) throws MessagingException
45      {
46          try
47          {
48              event.getSession().dispatchEvent(event.getMessage(), tap);
49          }
50          catch (UMOException e)
51          {
52              // TODO MULE-863: What should we really do?
53              logger.error(e.getMessage(), e);
54          }
55          return super.process(event);
56      }
57  
58      public String getEndpoint()
59      {
60          return endpoint;
61      }
62  
63      public void setEndpoint(String endpoint) throws UMOException
64      {
65          this.endpoint = endpoint;
66          if (this.endpoint != null)
67          {
68              tap = MuleManager.getInstance().lookupEndpoint(this.endpoint);
69              if (tap == null)
70              {
71                  tap = new ImmutableMuleEndpoint(this.endpoint, false);
72              }
73          }
74      }
75  
76  }