Class AbstractServerDetector

java.lang.Object
org.jolokia.server.detector.jee.AbstractServerDetector
All Implemented Interfaces:
Comparable<org.jolokia.server.core.detector.ServerDetector>, org.jolokia.server.core.detector.ServerDetector, org.jolokia.server.core.service.api.JolokiaService<org.jolokia.server.core.detector.ServerDetector>
Direct Known Subclasses:
AbstractOsgiServerDetector, ActiveMQDetector, ArtemisDetector, GeronimoDetector, GlassfishDetector, JBossDetector, JettyDetector, LightstreamerDetector, TomcatDetector, WeblogicDetector, WebsphereDetector

public abstract class AbstractServerDetector extends Object implements org.jolokia.server.core.detector.ServerDetector
Base class for server detectors.
Since:
05.11.10
Author:
roland
  • Constructor Details

    • AbstractServerDetector

      protected AbstractServerDetector(String pName, int pOrder)
      The order of this detector
      Parameters:
      pOrder - detector's order
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface org.jolokia.server.core.detector.ServerDetector
    • init

      public void init(Map<String,Object> pConfig)
      Specified by:
      init in interface org.jolokia.server.core.detector.ServerDetector
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.jolokia.server.core.service.api.JolokiaService<org.jolokia.server.core.detector.ServerDetector>
    • init

      public void init(org.jolokia.server.core.service.api.JolokiaContext pJolokiaContext)
      Specified by:
      init in interface org.jolokia.server.core.service.api.JolokiaService<org.jolokia.server.core.detector.ServerDetector>
    • isEnabled

      public boolean isEnabled(org.jolokia.server.core.service.api.JolokiaContext pContext)
      Specified by:
      isEnabled in interface org.jolokia.server.core.service.api.JolokiaService<org.jolokia.server.core.detector.ServerDetector>
    • getConfig

      protected Object getConfig(String pKey)
    • searchMBeans

      protected Set<ObjectName> searchMBeans(org.jolokia.server.core.util.jmx.MBeanServerAccess pMBeanServerAccess, String pMbeanPattern)
      Check for the existence of a certain MBean. All known MBeanServers are queried
      Parameters:
      pMBeanServerAccess - mbean servers to query for
      pMbeanPattern - MBean name pattern for MBeans to check for
      Returns:
      set of ObjectNames if the pattern matches, or an empty set if not mbean has been found
    • mBeanExists

      protected boolean mBeanExists(org.jolokia.server.core.util.jmx.MBeanServerAccess pMBeanServerManger, String pObjectName)
      Check whether a certain MBean exists
      Parameters:
      pMBeanServerManger - set of MBeanServers to query for
      pObjectName - the objectname to check. Can be a pattern in which case this method return true if one or more MBeans of all MBeanServers match this pattern
      Returns:
      true if at least one MBean of the given name (or pattern) exists
    • getAttributeValue

      protected String getAttributeValue(org.jolokia.server.core.util.jmx.MBeanServerAccess pMBeanServerAccess, String pMBean, String pAttribute)
      Get the string representation of an attribute
      Parameters:
      pMBeanServerAccess - set of MBeanServers to query. The first one wins.
      pMBean - object name of MBean to lookup
      pAttribute - attribute to lookup
      Returns:
      string value of attribute or null if the attribute could not be fetched
    • getAttributeValue

      protected String getAttributeValue(org.jolokia.server.core.util.jmx.MBeanServerAccess pMBeanServerAccess, ObjectName pMBean, String pAttribute)
      Get the string representation of an attribute
      Parameters:
      pMBeanServerAccess - set of MBeanServers to query. The first one wins.
      pMBean - name of MBean to lookup
      pAttribute - attribute to lookup
      Returns:
      string value of attribute or null if the attribute could not be fetched
    • getSingleStringAttribute

      protected String getSingleStringAttribute(org.jolokia.server.core.util.jmx.MBeanServerAccess pMBeanServerAccess, String pMBeanName, String pAttribute)
      Get a single attribute for a given MBeanName pattern.
      Parameters:
      pMBeanServerAccess - MBeanServer manager to query
      pMBeanName - a MBean name or pattern. If multiple MBeans are found, each is queried for the attribute
      pAttribute - the attribute to lookup
      Returns:
      the string value of the attribute or null if either no MBeans could be found, or 0 or more than 1 attribute are found on those mbeans
    • getVersionFromJsr77

      protected String getVersionFromJsr77(org.jolokia.server.core.util.jmx.MBeanServerAccess pMbeanServers)
      Get the version number from a JSR-77 compliant server
      Parameters:
      pMbeanServers - servers to query
      Returns:
      version number or null if not found.
    • getMBeanServers

      public Set<MBeanServerConnection> getMBeanServers()
      Specified by:
      getMBeanServers in interface org.jolokia.server.core.detector.ServerDetector
    • getRequestInterceptor

      public org.jolokia.server.core.service.request.RequestInterceptor getRequestInterceptor(org.jolokia.server.core.util.jmx.MBeanServerAccess pMBeanServerAccess)
      Specified by:
      getRequestInterceptor in interface org.jolokia.server.core.detector.ServerDetector
    • compareTo

      public int compareTo(org.jolokia.server.core.detector.ServerDetector pDetector)
      Specified by:
      compareTo in interface Comparable<org.jolokia.server.core.detector.ServerDetector>
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.jolokia.server.core.service.api.JolokiaService<org.jolokia.server.core.detector.ServerDetector>
      Specified by:
      getOrder in interface org.jolokia.server.core.detector.ServerDetector
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • jvmAgentStartup

      public ClassLoader jvmAgentStartup(Instrumentation instrumentation)
      By default do nothing during JVM agent startup
      Specified by:
      jvmAgentStartup in interface org.jolokia.server.core.detector.ServerDetector
    • getContainerLocator

      public org.jolokia.server.core.service.container.ContainerLocator getContainerLocator(org.jolokia.server.core.service.api.LogHandler logHandler)
      Specified by:
      getContainerLocator in interface org.jolokia.server.core.detector.ServerDetector
    • isClassLoaded

      protected boolean isClassLoaded(String className, Instrumentation instrumentation)
      Tests if the given class name has been loaded by the JVM. Don't use this method in case you have access to the class loader which will be loading the class because the used approach is not very efficient.
      Parameters:
      className - the name of the class to check
      instrumentation -
      Returns:
      true if the class has been loaded by the JVM
      Throws:
      IllegalArgumentException - in case instrumentation or the provided class is null
    • getClassLoaded

      protected Class<?> getClassLoaded(String className, Instrumentation instrumentation)
      Just like isClassLoaded(java.lang.String, java.lang.instrument.Instrumentation) but returns the loaded class instead of a boolean
      Parameters:
      className -
      instrumentation -
      Returns:
    • getDetectionTimeout

      protected int getDetectionTimeout()
      If a detector requires an active-wait loop, this is the total timeout (in ms). If -1, it means the waiting is disabled. But given detector has to actively invoke waiting code.
      Returns:
    • getDetectionInterval

      protected int getDetectionInterval()
      A wait (in ms) between active-loop waiting cycles.
      Returns:
    • getDetectionFinalDelay

      protected int getDetectionFinalDelay()
      A final delay between ending the active-wait loop.
      Returns:
    • activeWait

      protected void activeWait(Instrumentation instrumentation, Supplier<Boolean> checker, String failedMessageFormat)
      A helper for dedicated detectors that implements active-waiting loop
      Parameters:
      instrumentation -
      checker -
      failedMessageFormat - a message format with a placeholder for total timeout used to format exception message for failed active-wait loop.