Class ResourcepathMonitor

All Implemented Interfaces:
AbstractMonitorMBean, ResourcepathMonitorMBean, Shutdownable, Runnable

public class ResourcepathMonitor extends AbstractMonitor implements ResourcepathMonitorMBean
Analogous to ClasspathMonitor this class allows you to ask for resources in the classpath. Originally this class was part of the PatternTesting project.
Author:
oliver
  • Constructor Details

    • ResourcepathMonitor

      protected ResourcepathMonitor()
      We offer only some services. So there is no need to instantiate it from outside.
  • Method Details

    • getInstance

      public static ResourcepathMonitor getInstance()
      Yes, it is a Singleton because it offers only some services. So we don't need the object twice.
      Returns:
      the only instance
    • registerAsMBean

      public static void registerAsMBean()
      With this method you can register the ResourcepathMonitor with the default name.

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

    • unregisterAsMBean

      public static void unregisterAsMBean()
      Unregister ResourcepathMonitor as MBean.
    • isRegisteredAsMBean

      public static boolean isRegisteredAsMBean()
      If you want to ask JMX if bean is already registered you can use this method.
      Returns:
      true if class is registered as MBean
    • getResources

      public String[] getResources()
      Scans the classpath for all resources. For performance reason we return no longer a copy but the origin array. Don't do changes for the returned array!
      Specified by:
      getResources in interface ResourcepathMonitorMBean
      Returns:
      all resources as String array
    • whichResource

      @Description("returns the URI of the given resource") public URI whichResource(String name)
      Looks if the given resource can be found in the classpath.
      Specified by:
      whichResource in interface ResourcepathMonitorMBean
      Parameters:
      name - of a resource e.g. "log4j.properties"
      Returns:
      URI of the given resource (or null if resource was not found)
      See Also:
    • getResourcesFor

      public Enumeration<URI> getResourcesFor(String name)
      Gets the resources for a given name.
      Parameters:
      name - the name
      Returns:
      the resources as URL enumeration
    • getNoResources

      public int getNoResources(String name)
      Gets the number of resources.
      Specified by:
      getNoResources in interface ResourcepathMonitorMBean
      Parameters:
      name - the name of the resource
      Returns:
      number of resources
      See Also:
    • isDoublet

      @Description("is the given classname or resource found more than once in the classpath?") public boolean isDoublet(String name)
      Is the given classname or resource a doublet, e.g. can it be found several times in the classpath? If the classname or resource is not in the classpath a java.util.NoSuchElementException will be thrown.
      Specified by:
      isDoublet in interface ResourcepathMonitorMBean
      Parameters:
      name - a classname or resource
      Returns:
      true if more than one classname or resource was found in the classpath
      Throws:
      NoSuchElementException - the no such element exception
      NoSuchElementException - if no classname or resource was found
      See Also:
    • getFirstDoublet

      @Description("returns the first doublet of the given classname or resource") public URI getFirstDoublet(String name)
      Returns the first doublet of the given classname or resource.
      Specified by:
      getFirstDoublet in interface ResourcepathMonitorMBean
      Parameters:
      name - a classname or resource
      Returns:
      the first doublet
      See Also:
    • getDoublet

      public URI getDoublet(String name, int nr)
      Gets the doublet.
      Specified by:
      getDoublet in interface ResourcepathMonitorMBean
      Parameters:
      name - the name
      nr - the nr
      Returns:
      the doublet
      See Also:
    • getDoublets

      public String[] getDoublets()
      Gets the doublets.

      Note: The Manifest file (META-INF/MANIFEST.MF) ist not counted as doublet file because it is not really a resource.

      Specified by:
      getDoublets in interface ResourcepathMonitorMBean
      Returns:
      the doublets
      See Also:
    • getDoubletResourcepath

      @Description("returns the classpath where doublets were found") public String[] getDoubletResourcepath()
      Looks for each found doublet resource in which classpath it was found. Resources like META-INF/MANIFEST.MF are not considered as doublet - otherwise you'll find all classpathes in the array.
      Specified by:
      getDoubletResourcepath in interface ResourcepathMonitorMBean
      Returns:
      the classpath where doublets were found
    • getDoubletResourcepathURIs

      protected URI[] getDoubletResourcepathURIs()
      Gets the URIs of the doublet resourcepath. Doublets in the META-INF folder are filtered out because these resources contains often some meta information of the JAR.
      Returns:
      the URIs of the doublets
    • getIncompatibleResources

      public String[] getIncompatibleResources()
      Incompatible resources are doublets with different content.
      Specified by:
      getIncompatibleResources in interface ResourcepathMonitorMBean
      Returns:
      doublet resources with different content
    • getIncompatibleResourcepath

      public String[] getIncompatibleResourcepath()
      Gets the classpath which contains incompatible resources. Resources in the META-INF folder are filtered out because resources in this folder contains often only some meta info of the JAR.
      Specified by:
      getIncompatibleResourcepath in interface ResourcepathMonitorMBean
      Returns:
      the classpathes where incompatible resources were found
    • getIncompatibleResourcepathURIs

      protected URI[] getIncompatibleResourcepathURIs()
      Gets the classpath which contains incompatible resources. Resources in the META-INF folder are filtered out because resources in this folder contains often only some meta info of the JAR.
      Returns:
      the resourcepath as array of URIs
    • logMe

      public void logMe()
      Logs the different array to the log output.
      Specified by:
      logMe in interface AbstractMonitorMBean
      Specified by:
      logMe in class AbstractMonitor
    • dumpMe

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