Source Code Cross Referenced for JMX.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » jems » as » 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 » Portal » jboss portal 2.6.4 » org.jboss.portal.jems.as 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.jems.as;
023:
024:        import org.apache.log4j.Logger;
025:        import org.jboss.mx.util.MBeanProxy;
026:        import org.jboss.mx.util.MBeanProxyCreationException;
027:        import org.jboss.mx.util.MBeanServerLocator;
028:        import org.jboss.mx.util.ObjectNameConverter;
029:
030:        import javax.management.InstanceNotFoundException;
031:        import javax.management.ListenerNotFoundException;
032:        import javax.management.MBeanRegistrationException;
033:        import javax.management.MBeanServer;
034:        import javax.management.MalformedObjectNameException;
035:        import javax.management.NotificationFilter;
036:        import javax.management.NotificationListener;
037:        import javax.management.ObjectName;
038:        import java.util.Comparator;
039:        import java.util.Hashtable;
040:        import java.util.Properties;
041:
042:        /**
043:         * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
044:         * @version $Revision: 8784 $
045:         */
046:        public final class JMX {
047:
048:            private static final Logger log = Logger.getLogger(JMX.class);
049:
050:            public static ObjectName extend(ObjectName name,
051:                    Properties keyProperties) {
052:                try {
053:                    Hashtable table = name.getKeyPropertyList();
054:                    table.putAll(keyProperties);
055:                    return ObjectNameConverter.convert(name.getDomain(), table);
056:                } catch (MalformedObjectNameException e) {
057:                    log.error("", e);
058:                    throw new RuntimeException();
059:                }
060:            }
061:
062:            /** ObjectName comparator based on canonical name lexicography. */
063:            public static Comparator OBJECT_NAME_COMPARATOR = new Comparator() {
064:                public int compare(Object o1, Object o2) {
065:                    ObjectName n1 = (ObjectName) o1;
066:                    ObjectName n2 = (ObjectName) o2;
067:                    return n1.getCanonicalName().compareTo(
068:                            n2.getCanonicalName());
069:                }
070:            };
071:
072:            public static void safeUnregister(MBeanServer server,
073:                    ObjectName name) {
074:                if (server != null) {
075:                    if (name != null) {
076:                        try {
077:                            server.unregisterMBean(name);
078:                        } catch (InstanceNotFoundException e) {
079:                            log.error("MBean " + name + " nto here");
080:                        } catch (MBeanRegistrationException e) {
081:                            log
082:                                    .error(
083:                                            "MBean threw an exception during unregistration",
084:                                            e.getTargetException());
085:                        }
086:                    } else {
087:                        log.error("Cannot unregister a null MBean");
088:                    }
089:                } else {
090:                    log.error("Cannot unregister with a null MBeanServer");
091:                }
092:            }
093:
094:            /**
095:             * Retrieves the MBeanProxy associated with the given class and name from the specified MBeanServer.
096:             *
097:             * @param clazz  the interface implemented by the MBean which is to be retrieved
098:             * @param name   the MBean's ObjectName
099:             * @param server the MBeanServer from which to retrieve the MBeanProxy
100:             * @return a MBeanProxy for the specified MBean if it exists
101:             * @throws RuntimeException if the MBean couldn't be retrieved
102:             */
103:            public static Object getMBeanProxy(Class clazz, ObjectName name,
104:                    MBeanServer server) {
105:                try {
106:                    return MBeanProxy.get(clazz, name, server);
107:                } catch (MBeanProxyCreationException e) {
108:                    String message = "Couldn't retrieve '"
109:                            + name.getCanonicalName() + "' MBean with class "
110:                            + clazz.getName();
111:                    log.error(message, e);
112:                    throw new RuntimeException(message, e);
113:                }
114:            }
115:
116:            /**
117:             * Retrieves the MBeanProxy associated with the given class and name from the JBoss microkernel as returned by
118:             * <code>MBeanServerLocator.locateJBoss()</code>.
119:             *
120:             * @param clazz the interface implemented by the MBean which is to be retrieved
121:             * @param name  a String representation of the MBean's ObjectName
122:             * @return a MBeanProxy for the specified MBean if it exists
123:             * @throws IllegalArgumentException if the given name is not a valid ObjectName
124:             * @throws RuntimeException         if the MBean couldn't be retrieved
125:             * @see #getMBeanProxy(Class, javax.management.ObjectName, javax.management.MBeanServer)
126:             * @since 2.4
127:             */
128:            public static Object getMBeanProxy(Class clazz, String name) {
129:                ObjectName objecName;
130:                try {
131:                    objecName = new ObjectName(name);
132:                } catch (MalformedObjectNameException e) {
133:                    throw new IllegalArgumentException("'" + name
134:                            + "' is not a valid ObjectName");
135:                }
136:                MBeanServer server = MBeanServerLocator.locateJBoss();
137:                return getMBeanProxy(clazz, objecName, server);
138:            }
139:
140:            public static boolean addNotificationListener(MBeanServer server,
141:                    ObjectName name, NotificationListener listener,
142:                    NotificationFilter filter, Object handback) {
143:                try {
144:                    server.addNotificationListener(name, listener, filter,
145:                            handback);
146:                    return true;
147:                } catch (InstanceNotFoundException e) {
148:                    return false;
149:                }
150:            }
151:
152:            public static boolean removeNotificationListener(
153:                    MBeanServer server, ObjectName name,
154:                    NotificationListener listener) {
155:                try {
156:                    server.removeNotificationListener(name, listener);
157:                    return true;
158:                } catch (InstanceNotFoundException e) {
159:                    log.error("Cannot remove notification listener", e);
160:                    return false;
161:                } catch (ListenerNotFoundException e) {
162:                    log.error("Cannot remove notification listener", e);
163:                    return false;
164:                }
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.