1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl; |
12 | |
|
13 | |
import org.mule.impl.model.AbstractComponent; |
14 | |
import org.mule.management.stats.ComponentStatistics; |
15 | |
import org.mule.umo.UMOComponent; |
16 | |
import org.mule.umo.UMOEvent; |
17 | |
import org.mule.umo.UMOMessage; |
18 | |
import org.mule.umo.endpoint.UMOEndpoint; |
19 | |
import org.mule.umo.endpoint.UMOImmutableEndpoint; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public class DefaultComponentExceptionStrategy extends DefaultExceptionStrategy |
27 | |
{ |
28 | |
|
29 | |
|
30 | |
|
31 | |
protected UMOComponent component; |
32 | |
|
33 | |
protected ComponentStatistics statistics; |
34 | |
|
35 | |
public DefaultComponentExceptionStrategy() |
36 | |
{ |
37 | 1636 | super(); |
38 | 1636 | } |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public DefaultComponentExceptionStrategy(UMOComponent component) |
47 | |
{ |
48 | 0 | super(); |
49 | 0 | setComponent(component); |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public UMOComponent getComponent() |
56 | |
{ |
57 | 0 | return component; |
58 | |
} |
59 | |
|
60 | |
protected void defaultHandler(Throwable t) |
61 | |
{ |
62 | |
|
63 | |
|
64 | |
|
65 | 0 | if (component == null) |
66 | |
{ |
67 | 0 | UMOEvent event = RequestContext.getEvent(); |
68 | 0 | if (event == null) |
69 | |
{ |
70 | |
|
71 | 0 | logger.fatal("The Default Component Exception Strategy has been invoked but there is no current event on the context"); |
72 | 0 | logger.fatal("The error is: " + t.getMessage(), t); |
73 | |
} |
74 | |
else |
75 | |
{ |
76 | 0 | setComponent(event.getComponent()); |
77 | |
} |
78 | |
} |
79 | |
|
80 | 0 | if (statistics != null) |
81 | |
{ |
82 | 0 | statistics.incExecutionError(); |
83 | |
} |
84 | |
|
85 | 0 | super.defaultHandler(t); |
86 | 0 | } |
87 | |
|
88 | |
protected void logFatal(UMOMessage message, Throwable t) |
89 | |
{ |
90 | 0 | super.logFatal(message, t); |
91 | 0 | if (statistics != null) |
92 | |
{ |
93 | 0 | statistics.incFatalError(); |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
protected void routeException(UMOMessage message, UMOImmutableEndpoint failedEndpoint, Throwable t) |
98 | |
{ |
99 | 0 | UMOEndpoint ep = getEndpoint(t); |
100 | 0 | if (ep != null) |
101 | |
{ |
102 | 0 | super.routeException(message, failedEndpoint, t); |
103 | 0 | if (statistics != null) |
104 | |
{ |
105 | 0 | statistics.getOutboundRouterStat().incrementRoutedMessage(ep); |
106 | |
} |
107 | |
} |
108 | 0 | } |
109 | |
|
110 | |
public void setComponent(UMOComponent component) |
111 | |
{ |
112 | 0 | this.component = component; |
113 | 0 | if (component instanceof AbstractComponent) |
114 | |
{ |
115 | 0 | this.statistics = ((AbstractComponent) component).getStatistics(); |
116 | |
} |
117 | 0 | } |
118 | |
} |