KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > ext > logging > LogRecordEmitter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24
25 package com.sun.appserv.management.ext.logging;
26
27 import java.util.Set JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import java.util.logging.LogRecord JavaDoc;
31
32 import javax.management.Notification JavaDoc;
33 import javax.management.NotificationEmitter JavaDoc;
34
35 import com.sun.appserv.management.base.ListenerInfo;
36 import com.sun.appserv.management.base.Util;
37 import com.sun.appserv.management.util.misc.GSetUtil;
38
39
40 /**
41     Emits {@link LogRecord} as JMX {@link Notification}.
42     <p>
43     The {@link LogRecord} is embedded within a Notification as follows:
44     notif.getType() => a Notification type beginning with {@link #LOG_RECORD_NOTIFICATION_PREFIX}<br>
45     notif.getSource() => ObjectName of {@link Logging} MBean that emitted the Notification
46     notif.getUserData() => Map&lt;String,Object> with keys as described below.
47     <p>
48     To avoid deserialization problems, an actual {@link LogRecord} is <i>not</i>
49     transmitted. Instead, its important fields are extracted and placed into a Map
50     obtained as follows:
51 <pre><code>
52     final Map<String,Object> fields = (Map<String,Object>)notif.getUserData();
53 </code></pre>
54     Alternately, you may use {@link Util#getAMXNotificationValue} to extract any]
55     particular field.
56     <p>
57     Valid keys within the Map are:
58     <ul>
59     <li>{@link #LOG_RECORD_AS_STRING_KEY} value is the String version of the entire LogRecord</li>
60     </ul>
61     <p>
62
63     Here is an example of how to retrieve the LogRecord information when a Notification is received:
64 <code><pre>
65 final Notifcation notif = <the notification>;
66 final String type = notif.getType();
67 final LogRecord logRecord = (LogRecord){@link Util#getAMXNotificationValue}( notif, LOG_RECORD_KEY );
68 final String logRecordString = (String){@link Util#getAMXNotificationValue}( notif, LOG_RECORD_STRING_KEY );
69 </pre></code>
70     @since AS 9.0
71  */

72 public interface LogRecordEmitter extends NotificationEmitter JavaDoc, ListenerInfo
73 {
74     /**
75         An emitted Notification will have this prefix for its type. Subtypes include:
76         <ul>
77         <li>{@link #LOG_RECORD_NOTIFICATION_SEVERE_TYPE}</li>
78         <li>{@link #LOG_RECORD_NOTIFICATION_WARNING_TYPE}</li>
79         <li>{@link #LOG_RECORD_NOTIFICATION_INFO_TYPE}</li>
80         <li>{@link #LOG_RECORD_NOTIFICATION_CONFIG_TYPE}</li>
81         <li>{@link #LOG_RECORD_NOTIFICATION_FINE_TYPE}</li>
82         <li>{@link #LOG_RECORD_NOTIFICATION_FINER_TYPE}</li>
83         <li>{@link #LOG_RECORD_NOTIFICATION_FINEST_TYPE}</li>
84         <li>{@link #LOG_RECORD_NOTIFICATION_OTHER_TYPE}</li>
85         </ul>
86      */

87     /** Notification type <i>prefix</i> for a LogRecord Notification */
88     public static final String JavaDoc LOG_RECORD_NOTIFICATION_PREFIX = "com.sun.appserv.management.ext.logging.Logging.";
89     
90     /** Notification type for a SEVERE LogRecord */
91     public static final String JavaDoc LOG_RECORD_SEVERE_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + Level.SEVERE;
92     
93     /** Notification type for a WARNING LogRecord */
94     public static final String JavaDoc LOG_RECORD_WARNING_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + Level.WARNING;
95     
96     /** Notification type for an INFO LogRecord */
97     public static final String JavaDoc LOG_RECORD_INFO_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + Level.INFO;
98     
99     /** Notification type for a CONFIG LogRecord */
100     public static final String JavaDoc LOG_RECORD_CONFIG_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + Level.CONFIG;
101     
102     /** Notification type for a FINE LogRecord */
103     public static final String JavaDoc LOG_RECORD_FINE_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + Level.FINE;
104     
105     /** Notification type for a FINER LogRecord */
106     public static final String JavaDoc LOG_RECORD_FINER_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + Level.FINER;
107     
108     /** Notification type for a FINEST LogRecord */
109     public static final String JavaDoc LOG_RECORD_FINEST_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + Level.FINEST;
110     
111     /** Notification type for any other level eg a specific level number not equivalent to any of the standard ones */
112     public static final String JavaDoc LOG_RECORD_OTHER_NOTIFICATION_TYPE = LOG_RECORD_NOTIFICATION_PREFIX + "OTHER";
113     
114     public static final Set JavaDoc<String JavaDoc> ALL_LOG_RECORD_NOTIFICATION_TYPES = Collections.unmodifiableSet(
115         GSetUtil.newSet( new String JavaDoc[]
116             {
117                 LOG_RECORD_SEVERE_NOTIFICATION_TYPE,
118                 LOG_RECORD_WARNING_NOTIFICATION_TYPE,
119                 LOG_RECORD_INFO_NOTIFICATION_TYPE,
120                 LOG_RECORD_CONFIG_NOTIFICATION_TYPE,
121                 LOG_RECORD_FINE_NOTIFICATION_TYPE,
122                 LOG_RECORD_FINER_NOTIFICATION_TYPE,
123                 LOG_RECORD_FINEST_NOTIFICATION_TYPE,
124                 LOG_RECORD_OTHER_NOTIFICATION_TYPE,
125             } ));
126     
127     
128     /**
129         All keys within the Map found in Notification.getUserData() have this prefix.
130      */

131     public static final String JavaDoc LOG_RECORD_KEY_PREFIX = "LogRecord.";
132     
133     /**
134         Key to access the string representation of the {@link java.util.logging.LogRecord}.
135         This value will always be present and non-null.
136         Use {@link com.sun.appserv.management.base.Util#getAMXNotificationValue}(LOG_RECORD_STRING_KEY)
137         to obtain this value.
138      */

139     public static final String JavaDoc LOG_RECORD_AS_STRING_KEY = LOG_RECORD_KEY_PREFIX + "toString";
140     
141     /** value: Level */
142     public static final String JavaDoc LOG_RECORD_LEVEL_KEY = LOG_RECORD_KEY_PREFIX + "Level";
143     
144     /** value: String */
145     public static final String JavaDoc LOG_RECORD_LOGGER_NAME_KEY = LOG_RECORD_KEY_PREFIX + "LoggerName";
146     
147     /** value: String */
148     public static final String JavaDoc LOG_RECORD_MESSAGE_KEY = LOG_RECORD_KEY_PREFIX + "Message";
149     
150     /** value: Long */
151     public static final String JavaDoc LOG_RECORD_MILLIS_KEY = LOG_RECORD_KEY_PREFIX + "Millis";
152     
153     /** value: Long */
154     public static final String JavaDoc LOG_RECORD_SEQUENCE_NUMBER_KEY = LOG_RECORD_KEY_PREFIX + "SequenceNumber";
155     
156     /** value: String */
157     public static final String JavaDoc LOG_RECORD_SOURCE_CLASS_NAME_KEY = LOG_RECORD_KEY_PREFIX + "SourceClassName";
158     
159     /** value: String */
160     public static final String JavaDoc LOG_RECORD_SOURCE_METHOD_NAME_KEY = LOG_RECORD_KEY_PREFIX + "SourceMethodName";
161     
162     /** value: Integer */
163     public static final String JavaDoc LOG_RECORD_THREAD_ID_KEY = LOG_RECORD_KEY_PREFIX + "ThreadID";
164     
165     /**
166         value: Throwable
167         <p>
168         All Throwables are remapped to standard java exceptions; the value will
169         be a Throwable, but it may not be the original Throwable as thrown on the server side.
170         <p>
171         If nothing was thrown this key will not be found in the Map.
172       */

173     public static final String JavaDoc LOG_RECORD_THROWN_KEY = LOG_RECORD_KEY_PREFIX + "Thrown";
174     
175     /**
176         value: Throwable
177         <p>
178         If LogRecord.getThrown() was non-null, this value is the innermost Throwable eg the root cause
179         found by following Throwable.getCause() until the innermost Throwable is reached.
180         <p>
181         If the root cause is the same as the thrown exception, then this value will not exist.
182       */

183     public static final String JavaDoc LOG_RECORD_ROOT_CAUSE_KEY = LOG_RECORD_KEY_PREFIX + "ThrownRootCause";
184     
185     /**
186         Get the number of listeners for the specified log level.
187         @param logLevel
188         @return number of listeners listening for messages of the specified level, or higher level
189      */

190     public int getLogLevelListenerCount( final Level JavaDoc logLevel );
191 }
192
193
194
195
196
197
Popular Tags