KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > util > ObservedObject


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mx.util;
23
24 import javax.management.ObjectName JavaDoc;
25
26 /**
27  * An observed object
28  */

29 public class ObservedObject
30 {
31   // Constants -----------------------------------------------------
32
/**
33     * Used to reset errors in {@link #alreadyNotified}.
34     */

35    public static final int RESET_FLAGS_ALREADY_NOTIFIED = 0;
36
37    /**
38     * An observed attribute type error has been notified.
39     */

40    public static final int RUNTIME_ERROR_NOTIFIED = 8;
41
42    /**
43     * An observed object error has been notified.
44     */

45    public static final int OBSERVED_OBJECT_ERROR_NOTIFIED = 1;
46
47    /**
48     * An observed attribute error has been notified.
49     */

50    public static final int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED = 2;
51
52    /**
53     * An observed attribute type error has been notified.
54     */

55    public static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED = 4;
56
57   // Attributes ----------------------------------------------------
58

59   /**
60    * The object name.
61    */

62   private ObjectName JavaDoc objectName;
63   
64   /**
65    * The notified attribute.
66    */

67   private int alreadyNotified = RESET_FLAGS_ALREADY_NOTIFIED;
68   
69   /**
70    * The derived gauge.
71    */

72   private Object JavaDoc derivedGauge;
73   
74   /**
75    * The last value.
76    */

77   private Object JavaDoc lastValue;
78   
79   /**
80    * The derived gauge timestamp.
81    */

82   private long derivedGaugeTimeStamp;
83   
84   /**
85    * The threshold.
86    */

87   private Object JavaDoc threshold;
88
89   // Static --------------------------------------------------------
90

91   // Constructors --------------------------------------------------
92

93   /**
94    * Construct a new observed object.
95    *
96    * @param objectName the object name.
97    */

98   public ObservedObject(ObjectName JavaDoc objectName)
99   {
100      if (objectName == null)
101         throw new IllegalArgumentException JavaDoc("Null object name");
102      this.objectName = objectName;
103   }
104
105   // Public --------------------------------------------------------
106

107   public ObjectName JavaDoc getObjectName()
108   {
109      return objectName;
110   }
111
112   public int getAlreadyNotified()
113   {
114      return alreadyNotified;
115   }
116
117   public boolean isAlreadyNotified(int mask)
118   {
119      return (alreadyNotified & mask) != 0;
120   }
121
122   public boolean notAlreadyNotified(int mask)
123   {
124      if ((alreadyNotified & mask) == 0)
125      {
126         alreadyNotified |= mask;
127         return true;
128      }
129      return false;
130   }
131
132   public void setNotAlreadyNotified(int mask)
133   {
134      alreadyNotified &= ~mask;
135   }
136
137   public void setAlreadyNotified(int mask)
138   {
139      alreadyNotified |= mask;
140   }
141
142   public void resetAlreadyNotified()
143   {
144      alreadyNotified = RESET_FLAGS_ALREADY_NOTIFIED;
145   }
146
147   public Object JavaDoc getDerivedGauge()
148   {
149      return derivedGauge;
150   }
151
152   public void setDerivedGauge(Object JavaDoc gauge)
153   {
154      derivedGauge = gauge;
155   }
156
157   public Object JavaDoc getLastValue()
158   {
159      return lastValue;
160   }
161
162   public void setLastValue(Object JavaDoc last)
163   {
164      lastValue = last;
165   }
166
167   public long getDerivedGaugeTimeStamp()
168   {
169      return derivedGaugeTimeStamp;
170   }
171
172   public void setDerivedGaugeTimeStamp(long ts)
173   {
174      derivedGaugeTimeStamp = ts;
175   }
176
177   public Object JavaDoc getThreshold()
178   {
179      return threshold;
180   }
181
182   public void setThreshold(Object JavaDoc threshold)
183   {
184      this.threshold = threshold;
185   }
186
187    /**
188     * @return human readable string.
189     */

190    public String JavaDoc toString()
191    {
192       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(100);
193       buffer.append(getClass().getName()).append("@").append(System.identityHashCode(this)).append("{");
194       buffer.append(" objectName=").append(getObjectName());
195       buffer.append(" alreadyNotified=").append(getAlreadyNotified());
196       buffer.append(" threshold=").append(getThreshold());
197       buffer.append(" derivedGauge=").append(getDerivedGauge());
198       buffer.append(" derivedGaugeTS=").append(getDerivedGaugeTimeStamp());
199       buffer.append(" lastValue=").append(getLastValue());
200       return buffer.append("}").toString();
201    }
202
203 }
204
Popular Tags