001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mx.util;
023:
024: import javax.management.ObjectName;
025:
026: /**
027: * An observed object
028: */
029: public class ObservedObject {
030: // Constants -----------------------------------------------------
031: /**
032: * Used to reset errors in {@link #alreadyNotified}.
033: */
034: public static final int RESET_FLAGS_ALREADY_NOTIFIED = 0;
035:
036: /**
037: * An observed attribute type error has been notified.
038: */
039: public static final int RUNTIME_ERROR_NOTIFIED = 8;
040:
041: /**
042: * An observed object error has been notified.
043: */
044: public static final int OBSERVED_OBJECT_ERROR_NOTIFIED = 1;
045:
046: /**
047: * An observed attribute error has been notified.
048: */
049: public static final int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED = 2;
050:
051: /**
052: * An observed attribute type error has been notified.
053: */
054: public static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED = 4;
055:
056: // Attributes ----------------------------------------------------
057:
058: /**
059: * The object name.
060: */
061: private ObjectName objectName;
062:
063: /**
064: * The notified attribute.
065: */
066: private int alreadyNotified = RESET_FLAGS_ALREADY_NOTIFIED;
067:
068: /**
069: * The derived gauge.
070: */
071: private Object derivedGauge;
072:
073: /**
074: * The last value.
075: */
076: private Object lastValue;
077:
078: /**
079: * The derived gauge timestamp.
080: */
081: private long derivedGaugeTimeStamp;
082:
083: /**
084: * The threshold.
085: */
086: private Object threshold;
087:
088: // Static --------------------------------------------------------
089:
090: // Constructors --------------------------------------------------
091:
092: /**
093: * Construct a new observed object.
094: *
095: * @param objectName the object name.
096: */
097: public ObservedObject(ObjectName objectName) {
098: if (objectName == null)
099: throw new IllegalArgumentException("Null object name");
100: this .objectName = objectName;
101: }
102:
103: // Public --------------------------------------------------------
104:
105: public ObjectName getObjectName() {
106: return objectName;
107: }
108:
109: public int getAlreadyNotified() {
110: return alreadyNotified;
111: }
112:
113: public boolean isAlreadyNotified(int mask) {
114: return (alreadyNotified & mask) != 0;
115: }
116:
117: public boolean notAlreadyNotified(int mask) {
118: if ((alreadyNotified & mask) == 0) {
119: alreadyNotified |= mask;
120: return true;
121: }
122: return false;
123: }
124:
125: public void setNotAlreadyNotified(int mask) {
126: alreadyNotified &= ~mask;
127: }
128:
129: public void setAlreadyNotified(int mask) {
130: alreadyNotified |= mask;
131: }
132:
133: public void resetAlreadyNotified() {
134: alreadyNotified = RESET_FLAGS_ALREADY_NOTIFIED;
135: }
136:
137: public Object getDerivedGauge() {
138: return derivedGauge;
139: }
140:
141: public void setDerivedGauge(Object gauge) {
142: derivedGauge = gauge;
143: }
144:
145: public Object getLastValue() {
146: return lastValue;
147: }
148:
149: public void setLastValue(Object last) {
150: lastValue = last;
151: }
152:
153: public long getDerivedGaugeTimeStamp() {
154: return derivedGaugeTimeStamp;
155: }
156:
157: public void setDerivedGaugeTimeStamp(long ts) {
158: derivedGaugeTimeStamp = ts;
159: }
160:
161: public Object getThreshold() {
162: return threshold;
163: }
164:
165: public void setThreshold(Object threshold) {
166: this .threshold = threshold;
167: }
168:
169: /**
170: * @return human readable string.
171: */
172: public String toString() {
173: StringBuffer buffer = new StringBuffer(100);
174: buffer.append(getClass().getName()).append("@").append(
175: System.identityHashCode(this )).append("{");
176: buffer.append(" objectName=").append(getObjectName());
177: buffer.append(" alreadyNotified=").append(getAlreadyNotified());
178: buffer.append(" threshold=").append(getThreshold());
179: buffer.append(" derivedGauge=").append(getDerivedGauge());
180: buffer.append(" derivedGaugeTS=").append(
181: getDerivedGaugeTimeStamp());
182: buffer.append(" lastValue=").append(getLastValue());
183: return buffer.append("}").toString();
184: }
185:
186: }
|