1
2
3
4
5
6
7
8
9
10
11 package org.mule.umo.manager;
12
13 import org.mule.MuleManager;
14 import org.mule.impl.endpoint.MuleEndpointURI;
15 import org.mule.util.ClassUtils;
16
17 import java.util.EventObject;
18
19
20
21
22
23
24 public abstract class UMOServerNotification extends EventObject
25 {
26 public static final String TYPE_INFO = "info";
27 public static final String TYPE_WARNING = "warn";
28 public static final String TYPE_ERROR = "error";
29 public static final String TYPE_FATAL = "fatal";
30
31 public static final int MANAGER_EVENT_ACTION_START_RANGE = 100;
32 public static final int MODEL_EVENT_ACTION_START_RANGE = 200;
33 public static final int COMPONENT_EVENT_ACTION_START_RANGE = 300;
34 public static final int SECURITY_EVENT_ACTION_START_RANGE = 400;
35 public static final int MANAGEMENT_EVENT_ACTION_START_RANGE = 500;
36 public static final int ADMIN_EVENT_ACTION_START_RANGE = 600;
37 public static final int CONNECTION_EVENT_ACTION_START_RANGE = 700;
38 public static final int MESSAGE_EVENT_ACTION_START_RANGE = 800;
39 public static final int SPACE_EVENT_ACTION_START_RANGE = 900;
40 public static final int REGISTRY_EVENT_ACTION_START_RANGE = 1000;
41 public static final int EXCEPTION_EVENT_ACTION_START_RANGE = 1100;
42 public static final int TRANSACTION_EVENT_ACTION_START_RANGE = 1200;
43 public static final int CUSTOM_EVENT_ACTION_START_RANGE = 100000;
44
45 public static final int NULL_ACTION = 0;
46 public static final Object NULL_MESSAGE = "";
47
48 public final String EVENT_NAME = ClassUtils.getClassName(getClass());
49
50 protected String serverId;
51
52 protected long timestamp;
53
54 protected int action = NULL_ACTION;
55
56
57
58
59
60
61
62
63 protected String resourceIdentifier = null;
64
65 public UMOServerNotification(Object message, int action)
66 {
67 super((message == null ? NULL_MESSAGE : message));
68 this.action = action;
69 if (MuleManager.isInstanciated())
70 {
71 serverId = MuleManager.getInstance().getId();
72 }
73 timestamp = System.currentTimeMillis();
74 }
75
76 public UMOServerNotification(Object message, int action, String resourceIdentifier)
77 {
78 super((message == null ? NULL_MESSAGE : message));
79 this.action = action;
80 this.resourceIdentifier = resourceIdentifier;
81 serverId = MuleManager.getInstance().getId();
82 timestamp = System.currentTimeMillis();
83 }
84
85 public int getAction()
86 {
87 return action;
88 }
89
90 public String getServerId()
91 {
92 return serverId;
93 }
94
95 public String getResourceIdentifier()
96 {
97 return resourceIdentifier;
98 }
99
100 public long getTimestamp()
101 {
102 return timestamp;
103 }
104
105 public boolean isResourceIdentifierAnUri()
106 {
107 return MuleEndpointURI.isMuleUri(resourceIdentifier);
108 }
109
110 public String toString()
111 {
112 return EVENT_NAME + "{" + "action=" + getActionName(action) + ", resourceId=" + resourceIdentifier
113 + ", serverId=" + serverId + ", timestamp=" + timestamp + "}";
114 }
115
116 protected String getPayloadToString()
117 {
118 return source.toString();
119 }
120
121 public String getType()
122 {
123 return TYPE_INFO;
124 }
125
126 public String getActionName()
127 {
128 return getActionName(action);
129 }
130
131 protected abstract String getActionName(int action);
132 }