Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractCatchAllStrategy |
|
| 1.25;1.25 |
1 | /* | |
2 | * $Id: AbstractCatchAllStrategy.java 20343 2010-11-24 21:02:10Z mike.schilling $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.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; | |
12 | ||
13 | import org.mule.api.MuleEvent; | |
14 | import org.mule.api.routing.OutboundRouterCatchAllStrategy; | |
15 | import org.mule.api.routing.RouterStatisticsRecorder; | |
16 | import org.mule.api.routing.RoutingException; | |
17 | import org.mule.management.stats.RouterStatistics; | |
18 | ||
19 | import org.apache.commons.logging.Log; | |
20 | import org.apache.commons.logging.LogFactory; | |
21 | ||
22 | ||
23 | /** | |
24 | * <code>RouterCatchAllStrategy</code> is a strategy interface that allows developers to hook in custom code when | |
25 | * an event is being routed on the inbound or outbound but does not match any of the criteria defined for the routing. | |
26 | * | |
27 | * Think of catch all strategies as a safety net for your events to ensure that all events will get processed. If you | |
28 | * do not use conditional routing logic, you will not need a catch all strategy. | |
29 | * | |
30 | * Note that it is advised to use this base class over the {@link org.mule.api.routing.OutboundRouterCatchAllStrategy} interface | |
31 | * so that the {@link org.mule.management.stats.RouterStatistics} are available. | |
32 | * | |
33 | * @see org.mule.routing.LoggingCatchAllStrategy | |
34 | * @see org.mule.routing.ForwardingCatchAllStrategy | |
35 | */ | |
36 | 0 | public abstract class AbstractCatchAllStrategy implements OutboundRouterCatchAllStrategy, RouterStatisticsRecorder |
37 | { | |
38 | /** | |
39 | * logger used by this class | |
40 | */ | |
41 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
42 | ||
43 | /** Router statistics used to monitor if a catch all strategy is invoked and if any events are dispatched | |
44 | * from the strategy i.e. from the {@link org.mule.routing.ForwardingCatchAllStrategy}. | |
45 | */ | |
46 | protected RouterStatistics statistics; | |
47 | ||
48 | ||
49 | public RouterStatistics getRouterStatistics() | |
50 | { | |
51 | 0 | return statistics; |
52 | } | |
53 | ||
54 | public void setRouterStatistics(RouterStatistics statistics) | |
55 | { | |
56 | 0 | this.statistics = statistics; |
57 | 0 | } |
58 | ||
59 | /** | |
60 | * This method will be invoked when an event is received or being sent where the criteria of the router(s) do not | |
61 | * match the current event. | |
62 | * | |
63 | * @return A result message from this processing. Depending on the messaging style being used this might become the | |
64 | * response message to a client or remote service call. | |
65 | * @throws org.mule.api.routing.RoutingException | |
66 | * if there is a failure while processing this message. | |
67 | */ | |
68 | public final MuleEvent process(MuleEvent event) throws RoutingException | |
69 | { | |
70 | 0 | RouterStatistics stats = getRouterStatistics(); |
71 | 0 | if(stats !=null && stats.isEnabled()) |
72 | { | |
73 | 0 | stats.incrementCaughtMessage(); |
74 | } | |
75 | else | |
76 | { | |
77 | 0 | logger.warn("Routing statistics not set on catch all strategy, this invocation will not be recorded."); |
78 | } | |
79 | 0 | return doCatchMessage(event); |
80 | } | |
81 | ||
82 | public abstract MuleEvent doCatchMessage(MuleEvent event) throws RoutingException; | |
83 | ||
84 | } |