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


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.org
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package javax.management.monitor;
009:
010:        import javax.management.MBeanNotificationInfo;
011:        import javax.management.ObjectName;
012:
013:        /**
014:         * Defines a monitor MBean designed to observe the values of a string
015:         * attribute.
016:         * <P>
017:         * A string monitor sends notifications as follows:
018:         * <UL>
019:         * <LI> if the attribute value matches the string to compare value,
020:         *      a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_MATCHED match notification} is sent.
021:         *      The notify match flag must be set to <CODE>true</CODE>.
022:         *      <BR>Subsequent matchings of the string to compare values do not
023:         *      cause further notifications unless
024:         *      the attribute value differs from the string to compare value.
025:         * <LI> if the attribute value differs from the string to compare value,
026:         *      a {@link MonitorNotification#STRING_TO_COMPARE_VALUE_DIFFERED differ notification} is sent.
027:         *      The notify differ flag must be set to <CODE>true</CODE>.
028:         *      <BR>Subsequent differences from the string to compare value do
029:         *      not cause further notifications unless
030:         *      the attribute value matches the string to compare value.
031:         * </UL>
032:         *
033:         * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
034:         */
035:
036:        public class StringMonitor extends Monitor implements 
037:                StringMonitorMBean {
038:
039:            private String stringToCompare = "";
040:            private boolean notifyMatch = false;
041:            private boolean notifyDiffer = false;
042:            //  private String derivedGauge = "";
043:            //  private long derivedGaugeTimestamp = System.currentTimeMillis();
044:
045:            private long times = 0L; // except the first time
046:
047:            public StringMonitor() {
048:
049:            }
050:
051:            public void start() {
052:                super ._start();
053:            }
054:
055:            public synchronized void stop() {
056:                super ._stop();
057:            }
058:
059:            public String getDerivedGauge(ObjectName observedObject) {
060:                return ((StringMonitorData) getMonitorData(observedObject)).derivedGauge;
061:            }
062:
063:            public long getDerivedGaugeTimeStamp(ObjectName observedObject) {
064:                return ((StringMonitorData) getMonitorData(observedObject)).derivedGaugeTimestamp;
065:            }
066:
067:            public String getStringToCompare() {
068:                return stringToCompare;
069:            }
070:
071:            public void setStringToCompare(String value)
072:                    throws IllegalArgumentException {
073:                if (value == null)
074:                    throw new IllegalArgumentException(
075:                            "The string to compare cannot be null.");
076:                stringToCompare = value;
077:            }
078:
079:            public boolean getNotifyMatch() {
080:                return notifyMatch;
081:            }
082:
083:            public void setNotifyMatch(boolean value) {
084:                notifyMatch = value;
085:            }
086:
087:            public boolean getNotifyDiffer() {
088:                return notifyDiffer;
089:            }
090:
091:            public void setNotifyDiffer(boolean value) {
092:                notifyDiffer = value;
093:            }
094:
095:            public MBeanNotificationInfo[] getNotificationInfo() {
096:                String[] notifTypes = { MonitorNotification.RUNTIME_ERROR,
097:                        MonitorNotification.OBSERVED_OBJECT_ERROR,
098:                        MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
099:                        MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
100:                        MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
101:                        MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED };
102:                MBeanNotificationInfo[] notifInfos = { new MBeanNotificationInfo(
103:                        notifTypes, MonitorNotification.class.getName(),
104:                        "Notifications sent by the StringMonitor MBean") };
105:                return notifInfos;
106:            }
107:
108:            // implemented by every entity monitor
109:            protected void doMonitor(ObjectName observedObject, Object value) {
110:                //    System.out.println("StringMonitor.doMonitor()");
111:                StringMonitorData data = (StringMonitorData) getMonitorData(observedObject);
112:                try {
113:                    long derivedGaugeTimestamp = System.currentTimeMillis(); // update timestamp
114:                    data.derivedGaugeTimestamp = derivedGaugeTimestamp;
115:                    if (!(value instanceof  String)) {
116:                        sendNotification(
117:                                MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
118:                                derivedGaugeTimestamp,
119:                                "The observed attribute type must be a string type.",
120:                                data.derivedGauge, stringToCompare,
121:                                observedObject);
122:                        return;
123:                    }
124:                    if (stringToCompare == null) {
125:                        sendNotification(
126:                                MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
127:                                derivedGaugeTimestamp,
128:                                "The observed attribute target value must not be null",
129:                                data.derivedGauge, stringToCompare,
130:                                observedObject);
131:                        return;
132:                    }
133:                    // attribute value not change
134:                    if (data.derivedGauge.equals(value))
135:                        return;
136:
137:                    boolean matches = stringToCompare.equals(value);
138:                    //    System.out.println("Matches: " + matches);
139:                    boolean lastMatches = stringToCompare
140:                            .equals(data.derivedGauge);
141:                    //    System.out.println("lastMatches: " + lastMatches);
142:
143:                    // notify match when this time is matches and last time is not matched
144:                    if (notifyMatch && matches) {
145:                        if (times == 0 || !lastMatches)
146:                            sendNotification(
147:                                    MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
148:                                    derivedGaugeTimestamp, "",
149:                                    data.derivedGauge, stringToCompare,
150:                                    observedObject);
151:                    }
152:
153:                    // notify differ when this time is not match and last time is matched
154:                    if (notifyDiffer && !matches) {
155:                        if (times == 0 || lastMatches)
156:                            sendNotification(
157:                                    MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED,
158:                                    derivedGaugeTimestamp, "",
159:                                    data.derivedGauge, stringToCompare,
160:                                    observedObject);
161:                    }
162:
163:                    data.derivedGauge = (String) value; // update derived gauge
164:                    times++;
165:                } catch (Exception e) {
166:                    sendNotification(MonitorNotification.RUNTIME_ERROR,
167:                            data.derivedGaugeTimestamp, e.getMessage(), null,
168:                            null, observedObject);
169:                }
170:            }
171:
172:            public void addObservedObject(ObjectName objectName)
173:                    throws IllegalArgumentException {
174:                if (objectName == null)
175:                    throw new IllegalArgumentException(
176:                            "The object to observe cannot be null.");
177:                observedObjects.put(objectName, new StringMonitorData(
178:                        objectName));
179:
180:            }
181:
182:            class StringMonitorData extends MonitorData {
183:                String derivedGauge = "";
184:                long derivedGaugeTimestamp = System.currentTimeMillis();
185:
186:                public StringMonitorData(ObjectName objectName) {
187:                    super (objectName);
188:                }
189:
190:                public ObjectName getObjectName() {
191:                    return super.getObjectName();
192:                }
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.