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