Source Code Cross Referenced for MX4JStringMonitor.java in  » JMX » mx4j » mx4j » monitor » 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 » JMX » mx4j » mx4j.monitor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */
008:
009:        package mx4j.monitor;
010:
011:        import javax.management.MBeanNotificationInfo;
012:        import javax.management.NotCompliantMBeanException;
013:        import javax.management.ObjectName;
014:        import javax.management.monitor.MonitorNotification;
015:
016:        import mx4j.log.Logger;
017:
018:        /**
019:         * @version $Revision: 1.3 $
020:         */
021:        public class MX4JStringMonitor extends MX4JMonitor implements 
022:                MX4JStringMonitorMBean {
023:            private static final String EMPTY = "";
024:
025:            private String stringToCompare = EMPTY;
026:            private boolean notifyMatch;
027:            private boolean notifyDiffer;
028:
029:            public MX4JStringMonitor() throws NotCompliantMBeanException {
030:                super (MX4JStringMonitorMBean.class);
031:            }
032:
033:            public MX4JStringMonitor(Class management)
034:                    throws NotCompliantMBeanException {
035:                super (management);
036:            }
037:
038:            public MBeanNotificationInfo[] getNotificationInfo() {
039:                // TODO
040:                return new MBeanNotificationInfo[0];
041:            }
042:
043:            public synchronized String getStringToCompare() {
044:                return stringToCompare;
045:            }
046:
047:            public synchronized void setStringToCompare(String value)
048:                    throws IllegalArgumentException {
049:                if (value == null)
050:                    throw new IllegalArgumentException(
051:                            "String to compare cannot be null");
052:                this .stringToCompare = value;
053:            }
054:
055:            public synchronized boolean getNotifyMatch() {
056:                return notifyMatch;
057:            }
058:
059:            public synchronized void setNotifyMatch(boolean notifyMatch) {
060:                this .notifyMatch = notifyMatch;
061:            }
062:
063:            public synchronized boolean getNotifyDiffer() {
064:                return notifyDiffer;
065:            }
066:
067:            public synchronized void setNotifyDiffer(boolean notifyDiffer) {
068:                this .notifyDiffer = notifyDiffer;
069:            }
070:
071:            public String getDerivedGauge(ObjectName objectName) {
072:                StringMonitorInfo info = (StringMonitorInfo) getMonitorInfo(objectName);
073:                return info.getGauge();
074:            }
075:
076:            public long getDerivedGaugeTimeStamp(ObjectName objectName) {
077:                StringMonitorInfo info = (StringMonitorInfo) getMonitorInfo(objectName);
078:                return info.getTimestamp();
079:            }
080:
081:            protected MonitorInfo createMonitorInfo() {
082:                return new StringMonitorInfo();
083:            }
084:
085:            protected int compare(String left, String right) {
086:                return left == null ? right == null ? 0 : -1
087:                        : right == null ? 1 : left.compareTo(right);
088:            }
089:
090:            protected void monitor(ObjectName name, String attribute,
091:                    Object value, MonitorInfo monitorInfo) {
092:                if (!(value instanceof  String)) {
093:                    sendErrorNotification(monitorInfo,
094:                            MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
095:                            "Attribute type must be a String, not "
096:                                    + value.getClass(), name, attribute);
097:                    return;
098:                }
099:
100:                String gauge = (String) value;
101:
102:                String reference = null;
103:                synchronized (this ) {
104:                    reference = getStringToCompare();
105:                }
106:
107:                Logger logger = getLogger();
108:
109:                StringMonitorInfo info = (StringMonitorInfo) monitorInfo;
110:                if (logger.isEnabledFor(Logger.DEBUG)) {
111:                    logger.debug("Computing gauge, previous values are: "
112:                            + info);
113:                    logger.debug("Current values are: gauge=" + gauge
114:                            + ", stringToCompare=" + reference);
115:                }
116:
117:                compareAndSendNotification(gauge, reference, info, name,
118:                        attribute);
119:
120:                info.setGauge(gauge);
121:                info.setTimestamp(System.currentTimeMillis());
122:            }
123:
124:            private void compareAndSendNotification(String gauge,
125:                    String reference, StringMonitorInfo info, ObjectName name,
126:                    String attribute) {
127:                Logger logger = getLogger();
128:
129:                boolean equals = compare(gauge, reference) == 0;
130:
131:                if (info.isDifferNotified() && !equals) {
132:                    if (logger.isEnabledFor(Logger.DEBUG))
133:                        logger.debug("Difference already notified, gauge="
134:                                + gauge + ", string-to-compare=" + reference);
135:                    return;
136:                }
137:                if (info.isMatchNotified() && equals) {
138:                    if (logger.isEnabledFor(Logger.DEBUG))
139:                        logger.debug("Match already notified, gauge=" + gauge
140:                                + ", string-to-compare=" + reference);
141:                    return;
142:                }
143:
144:                if (equals) {
145:                    if (logger.isEnabledFor(Logger.DEBUG))
146:                        logger.debug("Gauge matches, gauge=" + gauge
147:                                + ", string-to-compare=" + reference);
148:                    info.setDifferNotified(false);
149:                    if (getNotifyMatch()) {
150:                        if (logger.isEnabledFor(Logger.DEBUG))
151:                            logger.debug("Sending string match notification");
152:                        info.setMatchNotified(true);
153:                        sendNotification(
154:                                MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
155:                                "Gauge " + gauge + " matched " + reference,
156:                                name, attribute, gauge, reference);
157:                    } else {
158:                        info.setMatchNotified(false);
159:                        if (logger.isEnabledFor(Logger.DEBUG))
160:                            logger
161:                                    .debug("StringMonitor is configured in non-match-notification mode");
162:                    }
163:                } else {
164:                    if (logger.isEnabledFor(Logger.DEBUG))
165:                        logger.debug("Gauge differs, gauge=" + gauge
166:                                + ", string-to-compare=" + reference);
167:                    info.setMatchNotified(false);
168:                    if (getNotifyDiffer()) {
169:                        if (logger.isEnabledFor(Logger.DEBUG))
170:                            logger.debug("Sending string differ notification");
171:                        info.setDifferNotified(true);
172:                        sendNotification(
173:                                MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED,
174:                                "Gauge " + gauge + " differs from " + reference,
175:                                name, attribute, gauge, reference);
176:                    } else {
177:                        info.setDifferNotified(false);
178:                        if (logger.isEnabledFor(Logger.DEBUG))
179:                            logger
180:                                    .debug("StringMonitor is configured in non-differ-notification mode");
181:                    }
182:                }
183:            }
184:
185:            protected class StringMonitorInfo extends MonitorInfo {
186:                private String gauge;
187:                private long timestamp;
188:                private boolean matchNotified;
189:                private boolean differNotified;
190:
191:                public String getGauge() {
192:                    return gauge;
193:                }
194:
195:                public void setGauge(String gauge) {
196:                    this .gauge = gauge;
197:                }
198:
199:                public long getTimestamp() {
200:                    return timestamp;
201:                }
202:
203:                public void setTimestamp(long timestamp) {
204:                    this .timestamp = timestamp;
205:                }
206:
207:                public boolean isMatchNotified() {
208:                    return matchNotified;
209:                }
210:
211:                public void setMatchNotified(boolean matchNotified) {
212:                    this .matchNotified = matchNotified;
213:                }
214:
215:                public boolean isDifferNotified() {
216:                    return differNotified;
217:                }
218:
219:                public void setDifferNotified(boolean differNotified) {
220:                    this .differNotified = differNotified;
221:                }
222:
223:                public void clearNotificationStatus() {
224:                    super .clearNotificationStatus();
225:                    differNotified = false;
226:                    matchNotified = false;
227:                }
228:
229:                public String toString() {
230:                    StringBuffer buffer = new StringBuffer(super .toString());
231:                    buffer.append(", gauge=").append(getGauge());
232:                    buffer.append(", matchNotified=").append(isMatchNotified());
233:                    buffer.append(", differNotified=").append(
234:                            isDifferNotified());
235:                    return buffer.toString();
236:                }
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.