Source Code Cross Referenced for DynamicMBeanFactory.java in  » Scripting » Pnuts » org » pnuts » jmx » 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 » Scripting » Pnuts » org.pnuts.jmx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.pnuts.jmx;
002:
003:        import pnuts.lang.Package;
004:        import pnuts.lang.PnutsFunction;
005:        import pnuts.lang.Context;
006:        import java.util.*;
007:        import javax.management.*;
008:
009:        /*
010:         * functions in a map represents JMX operations
011:         * non-function objects in a map represents JMX attributes
012:         */
013:        public class DynamicMBeanFactory {
014:
015:            public static DynamicMBean create(Map/*<String,Object>*/map,
016:                    Context context) {
017:                return create(map, null, context);
018:            }
019:
020:            public static DynamicMBean create(Map/*<String,Object>*/map,
021:                    Set monitoredVars, Context context) {
022:                return new MBean(map, monitoredVars, context);
023:            }
024:
025:            static class MBean extends NotificationBroadcasterSupport implements 
026:                    DynamicMBean {
027:                private Map/*<String,Object>*/map;
028:                private Context context;
029:                private String description;
030:                private Set monitoredVars;
031:                private long sequenceNumber = 0L;
032:
033:                MBean(Map/*<String,Object>*/map, Set monitoredVars,
034:                        Context context) {
035:                    this .map = map;
036:                    this .context = context;
037:                    this .monitoredVars = monitoredVars;
038:                }
039:
040:                public Object getAttribute(String attribute)
041:                        throws AttributeNotFoundException, MBeanException,
042:                        ReflectionException {
043:                    Object value = map.get(attribute);
044:                    if (value != null && !(value instanceof  PnutsFunction)) {
045:                        return value;
046:                    }
047:                    throw new AttributeNotFoundException();
048:                }
049:
050:                public void setAttribute(Attribute attribute)
051:                        throws AttributeNotFoundException,
052:                        InvalidAttributeValueException, MBeanException,
053:                        ReflectionException {
054:                    String name = attribute.getName();
055:                    Object newValue = attribute.getValue();
056:                    Object oldValue = map.put(name, newValue);
057:                    if (oldValue == null || !oldValue.equals(newValue)) {
058:                        checkMonitoredVars(name, oldValue, newValue);
059:                    }
060:                }
061:
062:                public AttributeList getAttributes(String[] attributes) {
063:                    AttributeList list = new AttributeList();
064:                    for (int i = 0, len = attributes.length; i < len; i++) {
065:                        String name = attributes[i];
066:                        Object value = map.get(name);
067:                        if (value != null && !(value instanceof  PnutsFunction)) {
068:                            list.add(new Attribute(name, value));
069:                        }
070:                    }
071:                    return list;
072:                }
073:
074:                public AttributeList setAttributes(AttributeList attributes) {
075:                    AttributeList list = new AttributeList();
076:                    //	    for (Attribute attr : attributes){
077:                    for (Iterator it = attributes.iterator(); it.hasNext();) {
078:                        Attribute attr = (Attribute) it.next();
079:                        String name = attr.getName();
080:                        Object newValue = attr.getValue();
081:                        Object oldValue = map.put(name, newValue);
082:                        if (oldValue == null || !oldValue.equals(newValue)) {
083:                            list.add(attr);
084:                            checkMonitoredVars(name, oldValue, newValue);
085:                        }
086:                    }
087:                    return list;
088:                }
089:
090:                public Object invoke(String actionName, Object params[],
091:                        String signature[]) throws MBeanException,
092:                        ReflectionException {
093:                    try {
094:                        Object value = map.get(actionName);
095:
096:                        if (value instanceof  PnutsFunction) {
097:                            PnutsFunction func = (PnutsFunction) value;
098:                            try {
099:                                return func.call(params, context);
100:                            } catch (Exception e) {
101:                                throw new MBeanException(e);
102:                            }
103:                        }
104:                    } catch (Exception e) {
105:                        throw new ReflectionException(e);
106:                    }
107:                    return null;
108:                }
109:
110:                protected void checkMonitoredVars(String name, Object oldValue,
111:                        Object newValue) {
112:                    if (monitoredVars != null && monitoredVars.contains(name)) {
113:                        Notification n = new AttributeChangeNotification(this ,
114:                                sequenceNumber++, System.currentTimeMillis(),
115:                                "", name, "java.lang.Object", oldValue,
116:                                newValue);
117:                        sendNotification(n);
118:                    }
119:                }
120:
121:                public void setDescription(String description) {
122:                    this .description = description;
123:                }
124:
125:                private MBeanAttributeInfo[] attributeInfo() {
126:                    ArrayList/*<MBeanAttributeInfo>*/list = new ArrayList/*<MBeanAttributeInfo>*/();
127:                    //	    for (Map.Entry<String,Object> entry : map.entrySet()){
128:                    for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
129:                        Map.Entry entry = (Map.Entry) it.next();
130:                        String name = (String) entry.getKey();
131:                        Object value = entry.getValue();
132:                        if (!(value instanceof  PnutsFunction)) {
133:                            list
134:                                    .add(new MBeanAttributeInfo(name,
135:                                            "java.lang.Object", null, true,
136:                                            true, false));
137:                        }
138:                    }
139:                    return (MBeanAttributeInfo[]) list
140:                            .toArray(new MBeanAttributeInfo[list.size()]);
141:                }
142:
143:                private MBeanOperationInfo[] operationInfo() {
144:                    ArrayList/*<MBeanOperationInfo>*/list = new ArrayList/*<MBeanOperationInfo>*/();
145:                    //	    for (Map.Entry<String,Object> entry : map.entrySet()){
146:                    for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
147:                        Map.Entry entry = (Map.Entry) it.next();
148:                        String name = (String) entry.getKey();
149:                        Object value = entry.getValue();
150:                        if (value instanceof  PnutsFunction) {
151:                            PnutsFunction func = (PnutsFunction) value;
152:                            list.add(new MBeanOperationInfo(name, null,
153:                                    new MBeanParameterInfo[0],
154:                                    "java.lang.Object",
155:                                    MBeanOperationInfo.UNKNOWN));
156:                        }
157:                    }
158:                    return (MBeanOperationInfo[]) list
159:                            .toArray(new MBeanOperationInfo[list.size()]);
160:                }
161:
162:                public MBeanInfo getMBeanInfo() {
163:                    MBeanAttributeInfo[] attributes = attributeInfo();
164:                    MBeanConstructorInfo[] constructors = null;
165:                    MBeanOperationInfo[] operations = operationInfo();
166:                    MBeanNotificationInfo[] notifications = null;
167:
168:                    return new MBeanInfo(this.getClass().getName(),
169:                            description, attributes, constructors, operations,
170:                            notifications);
171:                }
172:
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.