KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > umo > manager > UMOServerNotification


1 /*
2  * $Id: UMOServerNotification.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
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 JavaDoc;
18
19 /**
20  * <code>UMOServerNotification</code> is an event triggered by something happening
21  * in the Server itself such as the server starting or a component being registered
22  *
23  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
24  * @version $Revision: 3798 $
25  */

26 public abstract class UMOServerNotification extends EventObject JavaDoc
27 {
28     public static final String JavaDoc TYPE_INFO = "info";
29     public static final String JavaDoc TYPE_WARNING = "warn";
30     public static final String JavaDoc TYPE_ERROR = "error";
31     public static final String JavaDoc TYPE_FATAL = "fatal";
32
33     public static final int MANAGER_EVENT_ACTION_START_RANGE = 100;
34     public static final int MODEL_EVENT_ACTION_START_RANGE = 200;
35     public static final int COMPONENT_EVENT_ACTION_START_RANGE = 300;
36     public static final int SECURITY_EVENT_ACTION_START_RANGE = 400;
37     public static final int MANAGEMENT_EVENT_ACTION_START_RANGE = 500;
38     public static final int ADMIN_EVENT_ACTION_START_RANGE = 600;
39     public static final int CONNECTION_EVENT_ACTION_START_RANGE = 700;
40     public static final int MESSAGE_EVENT_ACTION_START_RANGE = 800;
41     public static final int SPACE_EVENT_ACTION_START_RANGE = 900;
42     public static final int REGISTRY_EVENT_ACTION_START_RANGE = 1000;
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 JavaDoc NULL_MESSAGE = new Object JavaDoc();
47
48     public final String JavaDoc EVENT_NAME = ClassUtils.getClassName(getClass());
49
50     protected String JavaDoc serverId;
51
52     protected long timestamp;
53
54     protected int action = NULL_ACTION;
55
56     /**
57      * The resourceIdentifier is used when firing inbound server notifications such
58      * as Admin notifications or other action notifications triggered by an external
59      * source Used to associate the event with a particular resource. For example, if
60      * the event was a ComponentNotification the resourceIdentifier could be the name
61      * of a particular component
62      */

63     protected String JavaDoc resourceIdentifier = null;
64
65     public UMOServerNotification(Object JavaDoc 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 JavaDoc message, int action, String JavaDoc 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 JavaDoc getServerId()
91     {
92         return serverId;
93     }
94
95     public String JavaDoc 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 JavaDoc toString()
111     {
112         return EVENT_NAME + "{" + "action=" + getActionName(action) + ", resourceId=" + resourceIdentifier
113                + ", serverId=" + serverId + ", timestamp=" + timestamp + "}";
114     }
115
116     protected String JavaDoc getPayloadToString()
117     {
118         return source.toString();
119     }
120
121     public String JavaDoc getType()
122     {
123         return TYPE_INFO;
124     }
125
126     public String JavaDoc getActionName()
127     {
128         return getActionName(action);
129     }
130
131     protected abstract String JavaDoc getActionName(int action);
132 }
133
Popular Tags