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

/**
 * An observed object
 */
/* package */ class ObservedObject
{
  // Constants -----------------------------------------------------
  
  // Attributes ----------------------------------------------------
  
  /**
   * The object name.
   */
  private ObjectName objectName;
  
  /**
   * The notified attribute.
   */
  private int alreadyNotified = Monitor.RESET_FLAGS_ALREADY_NOTIFIED;
  
  /**
   * The derived gauge.
   */
  private Object derivedGauge;
  
  /**
   * The last value.
   */
  private Object lastValue;
  
  /**
   * The derived gauge timestamp.
   */
  private long derivedGaugeTimeStamp;
  
  /**
   * The threshold.
   */
  private Object threshold;

  // Static --------------------------------------------------------
  
  // Constructors --------------------------------------------------

  /**
   * Construct a new observed object.
   *
   * @param objectName the object name.
   */
  ObservedObject(ObjectName objectName)
  {
     if (objectName == null)
        throw new IllegalArgumentException("Null object name");
     this.objectName = objectName;
  }

  // Public --------------------------------------------------------

  ObjectName getObjectName()
  {
     return objectName;
  }

  int getAlreadyNotified()
  {
     return alreadyNotified;
  }

  boolean isAlreadyNotified(int mask)
  {
     return (alreadyNotified & mask) == 0;
  }

  boolean notAlreadyNotified(int mask)
  {
     if ((alreadyNotified & mask) == 0)
     {
        alreadyNotified |= mask;
        return true;
     }
     return false;
  }

  void setNotAlreadyNotified(int mask)
  {
     alreadyNotified &= ~mask;
  }

  void resetAlreadyNotified()
  {
     alreadyNotified = Monitor.RESET_FLAGS_ALREADY_NOTIFIED;
  }

  Object getDerivedGauge()
  {
     return derivedGauge;
  }

  void setDerivedGauge(Object gauge)
  {
     derivedGauge = gauge;
  }

  Object getLastValue()
  {
     return lastValue;
  }

  void setLastValue(Object last)
  {
     lastValue = last;
  }

  long getDerivedGaugeTimeStamp()
  {
     return derivedGaugeTimeStamp;
  }

  void setDerivedGaugeTimeStamp(long ts)
  {
     derivedGaugeTimeStamp = ts;
  }

  Object getThreshold()
  {
     return threshold;
  }

  void setThreshold(Object threshold)
  {
     this.threshold = threshold;
  }

  // X implementation ----------------------------------------------

  // Y overrides ---------------------------------------------------

   /**
    * @return human readable string.
    */
   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());
      return buffer.append("}").toString();
   }

  // Package protected ---------------------------------------------

  // Protected -----------------------------------------------------

  // Private -------------------------------------------------------

  // Inner classes -------------------------------------------------
}
