1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl.internal.admin; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.impl.MuleEvent; |
15 | |
import org.mule.impl.MuleMessage; |
16 | |
import org.mule.impl.MuleSession; |
17 | |
import org.mule.impl.NullSessionHandler; |
18 | |
import org.mule.impl.endpoint.MuleEndpoint; |
19 | |
import org.mule.providers.NullPayload; |
20 | |
import org.mule.umo.UMOEvent; |
21 | |
import org.mule.umo.UMOMessage; |
22 | |
import org.mule.umo.UMOSession; |
23 | |
import org.mule.umo.endpoint.UMOEndpoint; |
24 | |
import org.mule.umo.lifecycle.InitialisationException; |
25 | |
import org.mule.umo.manager.UMOServerNotification; |
26 | |
|
27 | |
import java.util.Map; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class EndpointNotificationLoggerAgent extends AbstractNotificationLoggerAgent |
34 | |
{ |
35 | |
|
36 | |
private String endpointAddress; |
37 | 0 | private UMOEndpoint logEndpoint = null; |
38 | |
private UMOSession session; |
39 | |
|
40 | |
protected void doInitialise() throws InitialisationException |
41 | |
{ |
42 | |
|
43 | |
try |
44 | |
{ |
45 | 0 | if (endpointAddress != null) |
46 | |
{ |
47 | 0 | logEndpoint = MuleEndpoint.getOrCreateEndpointForUri(endpointAddress, |
48 | |
UMOEndpoint.ENDPOINT_TYPE_SENDER); |
49 | |
} |
50 | |
else |
51 | |
{ |
52 | 0 | throw new InitialisationException( |
53 | |
CoreMessages.propertiesNotSet("endpointAddress"), this); |
54 | |
} |
55 | |
|
56 | 0 | session = new MuleSession(new MuleMessage(NullPayload.getInstance(), (Map) null), new NullSessionHandler()); |
57 | |
} |
58 | 0 | catch (Exception e) |
59 | |
{ |
60 | 0 | throw new InitialisationException(e, this); |
61 | 0 | } |
62 | 0 | } |
63 | |
|
64 | |
protected void logEvent(UMOServerNotification e) |
65 | |
{ |
66 | 0 | if (logEndpoint != null) |
67 | |
{ |
68 | |
try |
69 | |
{ |
70 | 0 | UMOMessage msg = new MuleMessage(e.toString(), (Map) null); |
71 | 0 | UMOEvent event = new MuleEvent(msg, logEndpoint, session, false); |
72 | 0 | logEndpoint.dispatch(event); |
73 | |
} |
74 | 0 | catch (Exception e1) |
75 | |
{ |
76 | |
|
77 | 0 | logger.error("Failed to dispatch event: " + e.toString() + " over endpoint: " + logEndpoint |
78 | |
+ ". Error is: " + e1.getMessage(), e1); |
79 | 0 | } |
80 | |
} |
81 | 0 | } |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public String getDescription() |
89 | |
{ |
90 | 0 | StringBuffer buf = new StringBuffer(); |
91 | 0 | buf.append(getName()).append(": "); |
92 | 0 | if (endpointAddress != null) |
93 | |
{ |
94 | 0 | buf.append("Forwarding notifications to: " + endpointAddress); |
95 | |
} |
96 | 0 | return buf.toString(); |
97 | |
} |
98 | |
|
99 | |
public String getEndpointAddress() |
100 | |
{ |
101 | 0 | return endpointAddress; |
102 | |
} |
103 | |
|
104 | |
public void setEndpointAddress(String endpointAddress) |
105 | |
{ |
106 | 0 | this.endpointAddress = endpointAddress; |
107 | 0 | } |
108 | |
} |