Source Code Cross Referenced for MBeanSubsystem.java in  » Portal » Open-Portal » com » sun » portal » monitoring » 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 » Open Portal » com.sun.portal.monitoring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.monitoring;
006:
007:        import com.sun.portal.log.common.PortalLogger;
008:
009:        import javax.management.*;
010:        import javax.management.openmbean.CompositeData;
011:        import javax.management.openmbean.CompositeDataSupport;
012:        import javax.management.openmbean.OpenDataException;
013:        import java.util.Iterator;
014:        import java.util.Map;
015:        import java.util.TreeMap;
016:        import java.util.logging.Logger;
017:        import java.util.logging.Level;
018:        import java.util.logging.LogRecord;
019:
020:        public class MBeanSubsystem extends NotificationBroadcasterSupport
021:                implements  DynamicMBean, NotificationBroadcaster {
022:            private static final Logger logger = PortalLogger
023:                    .getLogger(MBeanSubsystem.class);
024:
025:            private static LogRecord getLogRecord(Level level, String message,
026:                    Object[] parameters, Throwable t) {
027:                LogRecord result = new LogRecord(level, message);
028:                result.setLoggerName(logger.getName());
029:                result.setParameters(parameters);
030:                result.setThrown(t);
031:                return result;
032:            }
033:
034:            public MBeanSubsystem(SubsystemImpl subsystemImpl,
035:                    MonitoringContext monitoringContext) {
036:                this .subsystem = subsystemImpl;
037:
038:                subsystemWrapper = new SubsystemWrapper(subsystem.isDisabled(),
039:                        monitoringContext);
040:                subsystemWrapper.setResourceBundleBaseName(subsystem
041:                        .getResourceBundleBaseName());
042:
043:                SubsystemNotificationFilter subsystemNotificationFilter = new SubsystemNotificationFilter();
044:                subsystemNotificationFilter
045:                        .setEnabledAttributes(SubsystemImpl.NOTIFICATION_ATTRIBUTE_NAMES);
046:                addNotificationListener(subsystemImpl,
047:                        subsystemNotificationFilter, null);
048:            }
049:
050:            private Subsystem subsystem;
051:            private SubsystemWrapper subsystemWrapper;
052:
053:            public Object getAttribute(String name)
054:                    throws AttributeNotFoundException, MBeanException,
055:                    ReflectionException {
056:                if (name == null) {
057:                    throw new AttributeNotFoundException("null");
058:                }
059:
060:                if (name.length() == 0) {
061:                    throw new AttributeNotFoundException("");
062:                }
063:
064:                CompositeData compositeData;
065:                try {
066:                    compositeData = subsystemWrapper.toCompositeData();
067:                } catch (OpenDataException e) {
068:                    if (logger.isLoggable(Level.SEVERE)) {
069:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
070:                                new Object[] { e.getLocalizedMessage() }, e));
071:                    }
072:                    throw new MBeanException(e);
073:                }
074:
075:                Object result;
076:                if (compositeData.containsKey(name)) {
077:                    result = compositeData.get(name);
078:                } else {
079:                    throw new AttributeNotFoundException(name);
080:                }
081:
082:                return result;
083:            }
084:
085:            private Map getItemNamesValues(CompositeData compositeData) {
086:                String[] itemNames = subsystemWrapper.getItemNames();
087:                Object[] itemValues = compositeData.getAll(itemNames);
088:                Map map = new TreeMap();
089:                for (int i = 0; i < itemNames.length; i++) {
090:                    map.put(itemNames[i], itemValues[i]);
091:                }
092:
093:                return map;
094:            }
095:
096:            public void setAttribute(Attribute attribute)
097:                    throws AttributeNotFoundException,
098:                    InvalidAttributeValueException, MBeanException,
099:                    ReflectionException {
100:                if (attribute == null) {
101:                    throw new AttributeNotFoundException("null");
102:                } else if (attribute.getName() == null) {
103:                    throw new AttributeNotFoundException("null");
104:                }
105:
106:                CompositeData compositeData;
107:                try {
108:                    compositeData = subsystemWrapper.toCompositeData();
109:                } catch (OpenDataException e) {
110:                    if (logger.isLoggable(Level.SEVERE)) {
111:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
112:                                new Object[] { e.getLocalizedMessage() }, e));
113:                    }
114:                    throw new MBeanException(e);
115:                }
116:
117:                if (compositeData.containsKey(attribute.getName())) {
118:                    Map itemNamesValues = getItemNamesValues(compositeData);
119:                    Object oldValue = itemNamesValues.get(attribute.getName());
120:                    Object newValue = attribute.getValue();
121:
122:                    itemNamesValues.put(attribute.getName(), attribute
123:                            .getValue());
124:                    try {
125:                        compositeData = new CompositeDataSupport(compositeData
126:                                .getCompositeType(), itemNamesValues);
127:                    } catch (OpenDataException e) {
128:                        if (logger.isLoggable(Level.SEVERE)) {
129:                            logger.log(getLogRecord(Level.SEVERE,
130:                                    "PSMN_CSPM0001", new Object[] { e
131:                                            .getLocalizedMessage() }, e));
132:                        }
133:                        throw new MBeanException(e);
134:                    }
135:
136:                    try {
137:                        subsystemWrapper.fromCompositeData(compositeData);
138:                    } catch (OpenDataException e) {
139:                        if (logger.isLoggable(Level.SEVERE)) {
140:                            logger.log(getLogRecord(Level.SEVERE,
141:                                    "PSMN_CSPM0001", new Object[] { e
142:                                            .getLocalizedMessage() }, e));
143:                        }
144:                        throw new MBeanException(e);
145:                    }
146:
147:                    if (!oldValue.equals(newValue)) {
148:                        AttributeChangeNotification acn = new AttributeChangeNotification(
149:                                this , 0, 0, null, attribute.getName(), null,
150:                                oldValue, newValue);
151:                        sendNotification(acn);
152:                    }
153:                } else {
154:                    throw new AttributeNotFoundException(attribute.getName());
155:                }
156:            }
157:
158:            public AttributeList getAttributes(String[] names) {
159:                AttributeList result = null;
160:
161:                if (names != null) {
162:                    if (names.length != 0) {
163:                        result = new AttributeList();
164:                        for (int i = 0; i < names.length; i++) {
165:                            try {
166:                                result.add(new Attribute(names[i],
167:                                        getAttribute(names[i])));
168:                            } catch (AttributeNotFoundException e) {
169:                                if (logger.isLoggable(Level.SEVERE)) {
170:                                    logger
171:                                            .log(getLogRecord(
172:                                                    Level.SEVERE,
173:                                                    "PSMN_CSPM0001",
174:                                                    new Object[] { e
175:                                                            .getLocalizedMessage() },
176:                                                    e));
177:                                }
178:                            } catch (MBeanException e) {
179:                                if (logger.isLoggable(Level.SEVERE)) {
180:                                    logger
181:                                            .log(getLogRecord(
182:                                                    Level.SEVERE,
183:                                                    "PSMN_CSPM0001",
184:                                                    new Object[] { e
185:                                                            .getLocalizedMessage() },
186:                                                    e));
187:                                }
188:                            } catch (ReflectionException e) {
189:                                if (logger.isLoggable(Level.SEVERE)) {
190:                                    logger
191:                                            .log(getLogRecord(
192:                                                    Level.SEVERE,
193:                                                    "PSMN_CSPM0001",
194:                                                    new Object[] { e
195:                                                            .getLocalizedMessage() },
196:                                                    e));
197:                                }
198:                            }
199:                        }
200:                    }
201:                }
202:
203:                return result;
204:            }
205:
206:            public AttributeList setAttributes(AttributeList attributeList) {
207:                AttributeList result = new AttributeList();
208:
209:                if (attributeList != null) {
210:                    for (Iterator iterator = attributeList.iterator(); iterator
211:                            .hasNext();) {
212:                        Attribute attribute = (Attribute) iterator.next();
213:                        try {
214:                            setAttribute(attribute);
215:                            result.add(attribute);
216:                        } catch (AttributeNotFoundException anfe) {
217:                            throw new RuntimeException(anfe);
218:                        } catch (InvalidAttributeValueException iave) {
219:                            throw new RuntimeException(iave);
220:                        } catch (MBeanException mbe) {
221:                            throw new RuntimeException(mbe);
222:                        } catch (ReflectionException re) {
223:                            throw new RuntimeException(re);
224:                        }
225:                    }
226:                }
227:
228:                return result;
229:            }
230:
231:            public Object invoke(String name, Object[] params,
232:                    String[] paramTypes) throws MBeanException,
233:                    ReflectionException {
234:                if (name.equals("getRegistry")) {
235:                    return subsystem.getRegistry();
236:                } else if (name.equals("reset")) {
237:                    try {
238:                        subsystem.stop(Boolean.TRUE);
239:                    } catch (MonitoringException e) {
240:                        if (logger.isLoggable(Level.SEVERE)) {
241:                            logger.log(getLogRecord(Level.SEVERE,
242:                                    "PSMN_CSPM0001", new Object[] { e
243:                                            .getLocalizedMessage() }, e));
244:                        }
245:                    }
246:                    return null;
247:                } else if (name.equals("destroy")) {
248:                    try {
249:                        subsystem.destroy();
250:                    } catch (MonitoringException e) {
251:                        if (logger.isLoggable(Level.SEVERE)) {
252:                            logger.log(getLogRecord(Level.SEVERE,
253:                                    "PSMN_CSPM0001", new Object[] { e
254:                                            .getLocalizedMessage() }, e));
255:                        }
256:                    }
257:                    return null;
258:                }
259:
260:                throw new ReflectionException(new NoSuchMethodException(name));
261:            }
262:
263:            public MBeanInfo getMBeanInfo() {
264:                try {
265:                    return subsystemWrapper.getMBeanInfo();
266:                } catch (OpenDataException e) {
267:                    if (logger.isLoggable(Level.SEVERE)) {
268:                        logger.log(getLogRecord(Level.SEVERE, "PSMN_CSPM0001",
269:                                new Object[] { e.getLocalizedMessage() }, e));
270:                    }
271:                    return null;
272:                }
273:            }
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.