Class DefaultMBeanServerAccess

java.lang.Object
org.jolokia.server.core.util.jmx.DefaultMBeanServerAccess
All Implemented Interfaces:
EventListener, NotificationListener, MBeanServerAccess

public class DefaultMBeanServerAccess extends Object implements MBeanServerAccess, NotificationListener
Base class for providing access to the list of MBeanServer handled by this agent.
Since:
22.01.13
Author:
roland
  • Constructor Details

    • DefaultMBeanServerAccess

      public DefaultMBeanServerAccess()
      Constructor using default MBeanServers
    • DefaultMBeanServerAccess

      public DefaultMBeanServerAccess(Set<MBeanServerConnection> pServers)
      Create an MBeanServer executor for calling MBeanServers
      Parameters:
      pServers - mbean servers to wrap and call
  • Method Details

    • getMBeanServers

      public Set<MBeanServerConnection> getMBeanServers()
      Get all MBeanServers
      Specified by:
      getMBeanServers in interface MBeanServerAccess
      Returns:
      all MBeanServers in the merge order
    • getJolokiaMBeanServer

      protected MBeanServerConnection getJolokiaMBeanServer()
      Override this method if you want to provide a Jolokia private MBeanServer. Note, that this method should only return a non-null value, if the Jolokia private MBean Server has some MBeans registered
      Returns:
      the Jolokia MBeanServer
    • each

      Iterate over all MBeanServers managed and call the handler via a callback. If is null or a pattern, the MBean names are queried on each MBeanServer and feed into the callback. If it is a full object name, then all MBeanServers are called with this object name in turn.
      Specified by:
      each in interface MBeanServerAccess
      Parameters:
      pObjectName - object name to lookup, which can be a pattern in which case a query is performed.
      pCallback - the action to be called for each MBean found on every server
      Throws:
      IOException
      ReflectionException
      MBeanException
    • call

      Call an action an the first MBeanServer on which the action does not throw an InstanceNotFoundException will considered to be successful and this method returns with the return value of the succesful action. If no action was succesful, an IllegalArgumentException is raised (containing the last InstanceNotFoundException from the last tried server)
      Specified by:
      call in interface MBeanServerAccess
      Type Parameters:
      T - type of the return value
      Parameters:
      pObjectName - objectname given through to the action
      pMBeanAction - the action to call
      pExtraArgs - any extra args given also to the action
      Returns:
      the return value of the succesful action
      Throws:
      IOException
      ReflectionException
      MBeanException - if the JMX call causes an issue
      AttributeNotFoundException
      InstanceNotFoundException
    • queryNames

      public Set<ObjectName> queryNames(ObjectName pObjectName) throws IOException
      Query all MBeanServer and return the union of all results
      Specified by:
      queryNames in interface MBeanServerAccess
      Parameters:
      pObjectName - pattern to query for. If null, then all MBean of all MBeanServers are returned
      Returns:
      the found MBeans
      Throws:
      IOException - if called remotely and an IOError occured.
    • unregisterFromMBeanNotifications

      public void unregisterFromMBeanNotifications()
      Unregister us as listener from every registered server
    • handleNotification

      public void handleNotification(Notification pNotification, Object pHandback)
      Specified by:
      handleNotification in interface NotificationListener
    • hasMBeansListChangedSince

      public boolean hasMBeansListChangedSince(long pTimestamp)
      Check whether the set of MBeans in all managed MBeanServer has been changed since the given time. The input is the epoch time in seconds, however, milliseconds would be much more appropriate. However, the Jolokia responses contain currently time measured in seconds. This should be changed in a future version, but this implies a quite heavy API changed (and if this is changed, the key "timestamp" should be changed to "time", too, in order to fail early in case of problems). In order to avoid inconsistencies for sub-second updates, we are comparing conservatively (so hasBeenUpdated might return "true" more often than required).
      Specified by:
      hasMBeansListChangedSince in interface MBeanServerAccess
      Parameters:
      pTimestamp - seconds since 1.1.1970
      Returns:
      true if the MBeans has been updated since this time, false otherwise
    • dumpMBeanServers

      public String dumpMBeanServers()