Source Code Cross Referenced for SystemServiceLoggerMBeanImpl.java in  » ESB » open-esb » com » sun » jbi » management » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » com.sun.jbi.management.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)SystemServiceLoggerMBeanImpl.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.management.support;
030:
031:        import com.sun.jbi.management.common.LoggerMBean;
032:        import com.sun.jbi.management.support.MBeanHelper;
033:        import com.sun.jbi.management.LocalStringKeys;
034:
035:        import java.util.logging.Logger;
036:        import java.util.logging.Level;
037:
038:        import javax.management.Notification;
039:        import javax.management.NotificationListener;
040:        import javax.management.AttributeChangeNotification;
041:        import javax.management.MBeanServer;
042:        import javax.management.MBeanRegistration;
043:        import javax.management.ObjectName;
044:
045:        /**
046:         * LoggerMBean defines standard controls for setting the properties of a
047:         * single JBI Framework service or JBI Installable Component logger.
048:         *
049:         * @author Sun Microsystems, Inc.
050:         */
051:        public class SystemServiceLoggerMBeanImpl extends
052:                DefaultLoggerMBeanImpl implements  LoggerMBean,
053:                NotificationListener, MBeanRegistration,
054:                com.sun.jbi.util.Constants {
055:            /**
056:             * Flag to determine if this logger Mbean is listening to log level
057:             * changes.
058:             */
059:            private boolean isListening;
060:
061:            /**
062:             *
063:             */
064:            com.sun.jbi.StringTranslator mTranslator;
065:
066:            /** Constructs a <CODE>SystemServiceLoggerMBeanImpl</CODE>.  */
067:            public SystemServiceLoggerMBeanImpl(Logger mLogger)
068:                    throws Exception {
069:                //allocate a logger:
070:                this (mLogger, mLogger.getName());
071:
072:                mTranslator = com.sun.jbi.util.EnvironmentAccess.getContext()
073:                        .getStringTranslator("com.sun.jbi.management");
074:                isListening = false;
075:            }
076:
077:            /** Constructs a <CODE>SystemServiceLoggerMBeanImpl</CODE>.  */
078:            public SystemServiceLoggerMBeanImpl(Logger mLogger,
079:                    String aDisplayName) throws Exception {
080:                //allocate a logger:
081:                //mLogger = mLogger;
082:                //mDisplayName = aDisplayName;
083:                super (mLogger, aDisplayName);
084:
085:                // If there is a persisted log level for this logger
086:                // set the log level based on that.
087:                Level level = MBeanHelper.getLogLevel(mLogger.getName(),
088:                        com.sun.jbi.util.EnvironmentAccess.getContext());
089:
090:                if (level != null) {
091:                    mLogger.setLevel(level);
092:                }
093:
094:                mTranslator = com.sun.jbi.util.EnvironmentAccess.getContext()
095:                        .getStringTranslator("com.sun.jbi.management");
096:
097:                isListening = false;
098:            }
099:
100:            /*---------------------------------------------------------------------------------*\
101:             *                           NotificationListener Operations                       *
102:            \*---------------------------------------------------------------------------------*/
103:
104:            /**
105:             *  handle a notification from the Logger Configuration MBean
106:             *
107:             * @param notification - the notification 
108:             * @param the callback passed in 
109:             */
110:            public void handleNotification(Notification notification,
111:                    Object handback) {
112:                if (notification instanceof  AttributeChangeNotification) {
113:                    AttributeChangeNotification notif = (AttributeChangeNotification) notification;
114:
115:                    if (notif.getAttributeName().equals(mLogger.getName())) {
116:                        mLogger
117:                                .fine("run time log level change notifictaion for "
118:                                        + mLogger.getName()
119:                                        + " from "
120:                                        + notif.getOldValue()
121:                                        + " to "
122:                                        + notif.getNewValue());
123:                    }
124:
125:                    String level = (String) notif.getNewValue();
126:                    try {
127:                        if (level == null || level == "null"
128:                                || LOG_LEVEL_DEFAULT.equals(level)) {
129:                            super .setDefault();
130:                        } else {
131:                            mLogger.setLevel(Level.parse(level));
132:                        }
133:                    } catch (IllegalArgumentException iex) {
134:                        mLogger.fine("Failed to set log level for logger "
135:                                + mLogger.getName() + " to " + level + " : "
136:                                + iex.getMessage());
137:                    }
138:                }
139:            }
140:
141:            /*---------------------------------------------------------------------------------*\
142:             *                           MBean Registration Operations                         *
143:            \*---------------------------------------------------------------------------------*/
144:
145:            /**
146:             * Preregsitration event. 
147:             */
148:            public ObjectName preRegister(MBeanServer server, ObjectName name)
149:                    throws Exception {
150:                return name;
151:            }
152:
153:            /**
154:             * Post registration event. Start listening to log level changes
155:             */
156:            public void postRegister(Boolean registrationDone) {
157:                if (registrationDone) {
158:                    startListeningToLogLevelChanges();
159:                    isListening = true;
160:                    mLogger
161:                            .fine("Logger "
162:                                    + mLogger.getName()
163:                                    + " is now listening for changes in the logger configuration");
164:                }
165:            }
166:
167:            /**
168:             * Prederegistration event. 
169:             */
170:            public void preDeregister() throws Exception {
171:                // nop
172:            }
173:
174:            /**
175:             * Post deregistration event. Stop listening to log level changes
176:             */
177:            public void postDeregister() {
178:                if (isListening) {
179:                    stopListeningToLogLevelChanges();
180:                    isListening = false;
181:                    mLogger
182:                            .fine("Logger "
183:                                    + mLogger.getName()
184:                                    + " has stopped listening for changes in the logger configuration");
185:                }
186:            }
187:
188:            /*---------------------------------------------------------------------------------*\
189:             *                           Private Helpers                                       *
190:            \*---------------------------------------------------------------------------------*/
191:
192:            /**
193:             * Register as a listener for attribute change events
194:             */
195:            private void startListeningToLogLevelChanges() {
196:                javax.management.MBeanServer mbeanServer = com.sun.jbi.util.EnvironmentAccess
197:                        .getContext().getMBeanServer();
198:
199:                /**
200:                 * Create a AttributeChangeNotificationFilter 
201:                 */
202:                javax.management.AttributeChangeNotificationFilter filter = new javax.management.AttributeChangeNotificationFilter();
203:                filter.disableAllAttributes();
204:                filter.enableAttribute(mLogger.getName());
205:
206:                try {
207:                    mbeanServer.addNotificationListener(MBeanHelper
208:                            .getLoggerConfigMBeanName(), this , filter, null);
209:                } catch (Exception ex) {
210:                    String[] params = new String[] { mDisplayName,
211:                            mLogger.getName(),
212:                            MBeanHelper.getLoggerConfigMBeanName().toString(),
213:                            ex.getMessage() };
214:                    String errMsg = mTranslator
215:                            .getString(
216:                                    LocalStringKeys.JBI_ADMIN_FAILED_ADD_LOGGER_LISTENER,
217:                                    params);
218:                    mLogger.info(errMsg);
219:                }
220:            }
221:
222:            /**
223:             * Stop listening to attribute change events
224:             */
225:            private void stopListeningToLogLevelChanges() {
226:                javax.management.MBeanServer mbeanServer = com.sun.jbi.util.EnvironmentAccess
227:                        .getContext().getMBeanServer();
228:
229:                try {
230:                    if (mbeanServer.isRegistered(MBeanHelper
231:                            .getLoggerConfigMBeanName())) {
232:                        mbeanServer.removeNotificationListener(MBeanHelper
233:                                .getLoggerConfigMBeanName(), this );
234:                    }
235:                } catch (Exception ex) {
236:                    String[] params = new String[] { mDisplayName,
237:                            mLogger.getName(),
238:                            MBeanHelper.getLoggerConfigMBeanName().toString(),
239:                            ex.getMessage() };
240:                    String errMsg = mTranslator
241:                            .getString(
242:                                    LocalStringKeys.JBI_ADMIN_FAILED_RM_LOGGER_LISTENER,
243:                                    params);
244:                    mLogger.warning(errMsg);
245:                }
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.