1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.example.notifications; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.context.notification.BlockingServerEvent; |
11 | |
import org.mule.context.notification.CustomNotification; |
12 | |
|
13 | |
import java.net.InetAddress; |
14 | |
import java.net.UnknownHostException; |
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
public class HeartbeatNotification extends CustomNotification implements BlockingServerEvent |
21 | |
{ |
22 | |
private static final long serialVersionUID = -3246036188011581121L; |
23 | |
|
24 | |
public static final int HEARTBEAT = CUSTOM_EVENT_ACTION_START_RANGE + 1300; |
25 | |
|
26 | |
static |
27 | |
{ |
28 | 0 | registerAction("mule heartbeat", HEARTBEAT); |
29 | 0 | } |
30 | |
|
31 | |
public HeartbeatNotification(MuleContext context) |
32 | |
{ |
33 | 0 | super(getHostInfo(), HEARTBEAT, context.getConfiguration().getId()); |
34 | 0 | } |
35 | |
|
36 | |
protected static String getHostInfo() |
37 | |
{ |
38 | |
try |
39 | |
{ |
40 | 0 | InetAddress host = InetAddress.getLocalHost(); |
41 | 0 | return host.getHostName() + " (" + host.getHostAddress() + ")"; |
42 | |
} |
43 | 0 | catch (UnknownHostException e) |
44 | |
{ |
45 | 0 | return "unknown"; |
46 | |
} |
47 | |
} |
48 | |
|
49 | |
@Override |
50 | |
public String toString() |
51 | |
{ |
52 | 0 | return EVENT_NAME + "{" + "action=" + getActionName(action) + ", resourceId=" + resourceIdentifier |
53 | |
+ ", timestamp=" + timestamp + "}"; |
54 | |
} |
55 | |
} |