Class ObjectRecorder

  • All Implemented Interfaces:
    java.lang.Runnable

    public class ObjectRecorder
    extends java.lang.Thread
    The ObjectRecorder takes records(inspections) of an objects state using reflection and accessibility- framework.

    It's strategy is to:

      - try to set any field accessible.
      - try to get the value of the field.
      - if not succeed: try to invoke a bean- conform getter.
      - if NoSuchMethod, it's useless (no implementation of MagicClazz here).
     

    Furthermore the ObjectRecorder has a history - size (buffer) and an adjustable distance between each inspection.

    Version:
    $Revision: 1.10 $
    Author:
    Achim Westermann
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  ObjectRecorder.ObjectInspection
      Data container for the inspection of the internal intance.
      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected IRingBuffer<ObjectRecorder.ObjectInspection> m_buffer
      Fast buffer to store recorded fiels.
      protected javax.swing.event.EventListenerList m_changeListeners
      The listeners on this recorder.
      protected java.lang.reflect.Field[] m_fields
      The fields to inspect on the instance.
      protected long m_interval
      The time - interval between to inspections of the Object.
      protected java.lang.Object m_toinspect
      The instance to inspect.
      protected static boolean VERBOSE
      Verbosity constant.
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectRecorder​(java.lang.Object toinspect, long interval)
      Creates an instance that will inspect the given Object in the given time interval.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addChangeListener​(javax.swing.event.ChangeListener x)
      Adds a change listener that will be informed about new recordings of the inspected instances.
      boolean equals​(java.lang.Object obj)  
      protected void fireChange()
      Informs the listeners about a change of this instance.
      TimeStampedValue[] getAttributeHistory​(java.lang.String attributeName)
      The History returned by this Method represents the past of the field specified by attributeName.
      java.lang.String[] getAttributeNames()
      Returns the names of the fields to inspect.
      java.lang.Object getInspected()
      Returns the inspected instance.
      TimeStampedValue getLastValue​(java.lang.String fieldname)
      Returns the last recorded value taken from the given field along with the time stamp identifying the time this value was recored.
      IRingBuffer<ObjectRecorder.ObjectInspection> getRingBuffer()
      Returns the internal fifo buffer that stores the ObjectRecorder.ObjectInspection instances that have been done.
      int hashCode()  
      void inspect()
      Makes a record of the state of the object specified in the constructor.
      void removeChangeListener​(javax.swing.event.ChangeListener x)
      Removes the given listener for changes of the inpsected instance.
      void run()  
      void setHistoryLength​(int length)
      Define the amount of recorded states of the Object to inspect that remain in memory.
      void setInterval​(long sleeptime)
      Sets the interval for inpection of the instance to inspect in ms.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • m_changeListeners

        protected javax.swing.event.EventListenerList m_changeListeners
        The listeners on this recorder.
      • m_fields

        protected java.lang.reflect.Field[] m_fields
        The fields to inspect on the instance.
      • m_interval

        protected long m_interval
        The time - interval between to inspections of the Object.
      • m_toinspect

        protected java.lang.Object m_toinspect
        The instance to inspect.
    • Constructor Detail

      • ObjectRecorder

        public ObjectRecorder​(java.lang.Object toinspect,
                              long interval)
        Creates an instance that will inspect the given Object in the given time interval.

        Parameters:
        toinspect - the instance to inspect.
        interval - the interval of inspection in ms.
    • Method Detail

      • addChangeListener

        public void addChangeListener​(javax.swing.event.ChangeListener x)
        Adds a change listener that will be informed about new recordings of the inspected instances.

        Parameters:
        x - the change listener that will be informed about new recordings of the inspected instances.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • fireChange

        protected void fireChange()
        Informs the listeners about a change of this instance.

      • getAttributeHistory

        public TimeStampedValue[] getAttributeHistory​(java.lang.String attributeName)
                                               throws javax.naming.directory.NoSuchAttributeException
        The History returned by this Method represents the past of the field specified by attributeName. It starts from low index with the newest values taken from the inspected Object and ends with the oldest.
        Parameters:
        attributeName - field name of the internal instance to inspect.
        Returns:
        An array filled with TimeStampedValues that represent the past of the last inspections of the field with attributeName.
        Throws:
        javax.naming.directory.NoSuchAttributeException - if the attribute / field described by the given argument does not exist on the internal Object to instpect.
        See Also:
        getInspected()
      • getAttributeNames

        public java.lang.String[] getAttributeNames()
        Returns the names of the fields to inspect.

        Returns:
        the names of the fields to inspect.
      • getInspected

        public java.lang.Object getInspected()
        Returns the inspected instance.

        Returns:
        the inspected instance.
      • getLastValue

        public TimeStampedValue getLastValue​(java.lang.String fieldname)
                                      throws javax.naming.directory.NoSuchAttributeException
        Returns the last recorded value taken from the given field along with the time stamp identifying the time this value was recored.

        Parameters:
        fieldname - the field whose value was recorded.
        Returns:
        the last recorded value taken from the given field along with the time stamp identifying the time this value was recored.
        Throws:
        javax.naming.directory.NoSuchAttributeException - if no such field exists on the Object to inspect.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • inspect

        public void inspect()
        Makes a record of the state of the object specified in the constructor. The new record is stored in a RingBuffer and contains all retrieveable values of the Object specified in the constructor. Reflection is used to get the values. If a field is private it's value is tried to be taken from the Object by invoking a getter - method conform with the bean - specification: The name of the method has to be "get" followed by the name of the field with first letter upper case.
      • removeChangeListener

        public void removeChangeListener​(javax.swing.event.ChangeListener x)
        Removes the given listener for changes of the inpsected instance.

        Parameters:
        x - the listener to remove.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
        See Also:
        Runnable.run()
      • setHistoryLength

        public void setHistoryLength​(int length)
        Define the amount of recorded states of the Object to inspect that remain in memory.

        Default value is 100.

        Parameters:
        length - the amount of recorded states of the Object to inspect that remain in memory.
      • setInterval

        public void setInterval​(long sleeptime)
        Sets the interval for inpection of the instance to inspect in ms.

        Parameters:
        sleeptime - the interval for inpection of the instance to inspect in ms.
        See Also:
        ObjectRecorder(Object, long)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Thread
        See Also:
        Object.toString()