Class AbstractMonitor

All Implemented Interfaces:
AbstractMonitorMBean, Shutdownable, Runnable
Direct Known Subclasses:
AbstractStatistic, ClasspathMonitor, ConnectionMonitor, ResourcepathMonitor

public abstract class AbstractMonitor extends Shutdowner implements AbstractMonitorMBean
This abstract base class has some support to for registration and unregistration of a monitor class as shutdown hook. Originally this class was part of the PatternTesting project.
Author:
oliver
  • Constructor Details

    • AbstractMonitor

      public AbstractMonitor()
  • Method Details

    • run

      public void run()
      This method is called when the ClasspathMonitor is registered as shutdown hook.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
      See Also:
    • registerMeAsMBean

      public void registerMeAsMBean()
      With this method you can register the monitor with the default name.

      You can only register the monitor only once. If you want to register it with another name you have to first unregister it.

    • registerMeAsMBean

      public void registerMeAsMBean(String name)
      With this method you can register the monitor with your own name. This is e.g. useful if you have an application server with several applications.

      You can only register the monitor only once. If you want to register it with another name you have to first unregister it.

      Parameters:
      name - the MBean name (e.g. "my.class.Monitor")
    • registerMeAsMBean

      public void registerMeAsMBean(ObjectName name)
      With this method you can register the monitor with your own name. This is e.g. useful if you have an application server with several applications.

      You can only register the monitor only once. If you want to register it with another name you have to first unregister it.

      Parameters:
      name - the name
    • unregisterMeAsMBean

      public void unregisterMeAsMBean()
      Unregister monitor as MBean.
    • isMBean

      public boolean isMBean()
      If you want to ask JMX if bean is already registered you can ask the MBeanHelper or you can ask this method.
      Returns:
      true if MBean is already registered.
    • logMe

      public abstract void logMe()
      Prints the different MBean attributes to the log output.
      Specified by:
      logMe in interface AbstractMonitorMBean
    • getDumpDir

      public File getDumpDir()
      The base directory where all is dumped can be configured (see Config.getDumpDir(). Each monitor class has its own dump dir below the base directory.
      Specified by:
      getDumpDir in interface AbstractMonitorMBean
      Returns:
      the dump directory
      Since:
      2.3
    • dumpMe

      public File dumpMe() throws IOException
      This operation dumps the different MBean attributes to a temporary directory with classname as prefix. The name of the created directory is returned so that you can see it in the 'jconsole' (if you have triggered it from there).
      Specified by:
      dumpMe in interface AbstractMonitorMBean
      Returns:
      the file
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also:
    • dump

      protected void dump(BufferedWriter writer, String... getterMethodNames) throws IOException
      This operation dumps the different MBean attributes. Use this method if you want to have all relevant infos in one stream. This is e.g. used by the logMe() method.
      Parameters:
      writer - a buffered writer
      getterMethodNames - the names of the getter methods which returns an array
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • dump

      protected void dump(File dumpDir, String... getterMethodNames) throws IOException
      Dumps different arrays to the given dumpDir directory, each array in its own file. For each array a method name must be provided as argument. Each given method must return an array as result.
      Parameters:
      dumpDir - the dump dir
      getterMethodNames - the name of the getter methods which return an array
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • dumpMe

      public void dumpMe(String dirname) throws IOException
      This operation dumps the different MBean attributes to the given directory.
      Specified by:
      dumpMe in interface AbstractMonitorMBean
      Parameters:
      dirname - the directory name
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • dumpMe

      public void dumpMe(File dumpDir) throws IOException
      This operation dumps the different MBean attributes to the given directory.
      Parameters:
      dumpDir - the directory where the attributes are dumped to.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • copyResource

      protected void copyResource(String name, File file) throws IOException
      Copy a resource to the given file.
      Parameters:
      name - the name
      file - the dir
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • dumpArray

      protected static void dumpArray(Object[] array, File dir, String title) throws IOException
      Dumps an array to the given directory.
      Parameters:
      array - the array
      dir - the dir
      title - the title (or name of the generated file)
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • dumpArray

      protected static void dumpArray(Object[] array, BufferedWriter writer, String title) throws IOException
      Dump array.
      Parameters:
      array - the array
      writer - the writer
      title - the title
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • dumpHeadline

      protected static void dumpHeadline(BufferedWriter writer, String headline) throws IOException
      Dump headline.
      Parameters:
      writer - the writer
      headline - the headline
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • toStringArray

      protected static String[] toStringArray(URI[] uris)
      We remove the URI prefix from the result to be in-line with the other classpath methods.
      Parameters:
      uris - an array with URIs
      Returns:
      the string array
    • toString

      public String toString()
      As the toString implementation the name of the registered MBean is used.
      Overrides:
      toString in class Thread
      Returns:
      the registered MBean name