package org.jboss.mx.util;
import javax.management.ObjectName;
public class ObservedObject
{
public static final int RESET_FLAGS_ALREADY_NOTIFIED = 0;
public static final int RUNTIME_ERROR_NOTIFIED = 8;
public static final int OBSERVED_OBJECT_ERROR_NOTIFIED = 1;
public static final int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED = 2;
public static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED = 4;
private ObjectName objectName;
private int alreadyNotified = RESET_FLAGS_ALREADY_NOTIFIED;
private Object derivedGauge;
private Object lastValue;
private long derivedGaugeTimeStamp;
private Object threshold;
public ObservedObject(ObjectName objectName)
{
if (objectName == null)
throw new IllegalArgumentException("Null object name");
this.objectName = objectName;
}
public ObjectName getObjectName()
{
return objectName;
}
public int getAlreadyNotified()
{
return alreadyNotified;
}
public boolean isAlreadyNotified(int mask)
{
return (alreadyNotified & mask) != 0;
}
public boolean notAlreadyNotified(int mask)
{
if ((alreadyNotified & mask) == 0)
{
alreadyNotified |= mask;
return true;
}
return false;
}
public void setNotAlreadyNotified(int mask)
{
alreadyNotified &= ~mask;
}
public void setAlreadyNotified(int mask)
{
alreadyNotified |= mask;
}
public void resetAlreadyNotified()
{
alreadyNotified = RESET_FLAGS_ALREADY_NOTIFIED;
}
public Object getDerivedGauge()
{
return derivedGauge;
}
public void setDerivedGauge(Object gauge)
{
derivedGauge = gauge;
}
public Object getLastValue()
{
return lastValue;
}
public void setLastValue(Object last)
{
lastValue = last;
}
public long getDerivedGaugeTimeStamp()
{
return derivedGaugeTimeStamp;
}
public void setDerivedGaugeTimeStamp(long ts)
{
derivedGaugeTimeStamp = ts;
}
public Object getThreshold()
{
return threshold;
}
public void setThreshold(Object threshold)
{
this.threshold = threshold;
}
public String toString()
{
StringBuffer buffer = new StringBuffer(100);
buffer.append(getClass().getName()).append("@").append(System.identityHashCode(this)).append("{");
buffer.append(" objectName=").append(getObjectName());
buffer.append(" alreadyNotified=").append(getAlreadyNotified());
buffer.append(" threshold=").append(getThreshold());
buffer.append(" derivedGauge=").append(getDerivedGauge());
buffer.append(" derivedGaugeTS=").append(getDerivedGaugeTimeStamp());
buffer.append(" lastValue=").append(getLastValue());
return buffer.append("}").toString();
}
}