Class AbstractCommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>

java.lang.Object
org.jolokia.service.jmx.handler.AbstractCommandHandler<R>
All Implemented Interfaces:
CommandHandler<R>
Direct Known Subclasses:
ExecHandler, ListHandler, NotificationHandler, ReadHandler, SearchHandler, WriteHandler

public abstract class AbstractCommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest> extends Object implements CommandHandler<R>
Common functionality of all Jolokia command handlers. This includes permission checking.
Since:
Jun 12, 2009
Author:
roland
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.jolokia.server.core.service.api.JolokiaContext
     
    protected String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    checkForModifiedSince(org.jolokia.server.core.util.jmx.MBeanServerAccess pServerManager, org.jolokia.server.core.request.JolokiaRequest pRequest)
    Check, whether the set of MBeans for any managed MBeanServer has been change since the timestamp provided in the given request
    protected abstract void
    Check whether there is a restriction on the type to apply.
    protected void
    Check whether a command of the given type is allowed
    void
    Lifecycle method called when agent goes down.
    protected Object
    doHandleAllServerRequest(org.jolokia.server.core.util.jmx.MBeanServerAccess serverManager, R request, Object pPreviousResult)
    Default implementation for handling a request for multiple servers at once.
    protected abstract Object
    Abstract method to be subclassed by a concrete handler for performing the request on a single MBeanServerConnection after the checks are performed.
    handleAllServerRequest(org.jolokia.server.core.util.jmx.MBeanServerAccess pServerManager, R pRequest, Object pPreviousResult)
    Override this if you want to iterate over all available servers and potentially use a result from a previous RequestHandlerat once for processing the request (like need for merging info as for a list command).
    boolean
    Override this if you want all available MBeanServers to be passed to this command handler, e.g., to query each server on your own.
    Handle a request for a single MBeanServerConnection.
    void
    init(org.jolokia.server.core.service.api.JolokiaContext pContext, String pProvider)
    Lifecycle method in order to initialize the handler
    protected boolean
    Checks whether an ObjectName should be removed (filtered out) from results of list or search operations.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.jolokia.service.jmx.api.CommandHandler

    getType
  • Field Details

    • context

      protected org.jolokia.server.core.service.api.JolokiaContext context
    • pProvider

      protected String pProvider
  • Constructor Details

    • AbstractCommandHandler

      public AbstractCommandHandler()
  • Method Details

    • init

      public void init(org.jolokia.server.core.service.api.JolokiaContext pContext, String pProvider)
      Description copied from interface: CommandHandler
      Lifecycle method in order to initialize the handler
      Specified by:
      init in interface CommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>
      Parameters:
      pContext - the jolokia context
      pProvider - provider to use for returned names. Handlers can use this for returning meta data with the proper provider prefixed.
    • handleAllServersAtOnce

      public boolean handleAllServersAtOnce(R pRequest)
      Description copied from interface: CommandHandler
      Override this if you want all available MBeanServers to be passed to this command handler, e.g., to query each server on your own. By default, iteration over the available MBeanServers is done by the RequestHandler and this command handler is called through CommandHandler.handleSingleServerRequest(MBeanServerConnection, JolokiaRequest).
      Specified by:
      handleAllServersAtOnce in interface CommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>
      Parameters:
      pRequest - request to decide on whether to handle all request at once
      Returns:
      whether you want to have CommandHandler.handleSingleServerRequest(MBeanServerConnection, JolokiaRequest) (false) or CommandHandler.handleAllServerRequest(MBeanServerAccess, JolokiaRequest, Object) (true) called.
    • handleSingleServerRequest

      public Object handleSingleServerRequest(MBeanServerConnection pServer, R pRequest) throws IOException, JMException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.BadRequestException, org.jolokia.server.core.request.EmptyResponseException
      Description copied from interface: CommandHandler
      Handle a request for a single MBeanServerConnection. Coordination of the servers and other request handlers is taken care of externally.
      Specified by:
      handleSingleServerRequest in interface CommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>
      Parameters:
      pServer - server to send the request to
      pRequest - request to process
      Returns:
      the result of sending a request to the MBean server
      Throws:
      IOException - when there's an error invoking MBeanServerConnection
      JMException - JMX checked exception, because most requests are handled by dealing with MBeans
      org.jolokia.server.core.request.NotChangedException - when (according to request parameters) user wants HTTP 304 if nothing has changed
      org.jolokia.server.core.request.BadRequestException - because some commands do more user input parsing in addition to what was checked when the JolokiaRequest was created
      org.jolokia.server.core.request.EmptyResponseException - if the response should not be closed (expecting further async/stream data)
    • handleAllServerRequest

      public Object handleAllServerRequest(org.jolokia.server.core.util.jmx.MBeanServerAccess pServerManager, R pRequest, Object pPreviousResult) throws IOException, JMException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.BadRequestException, org.jolokia.server.core.request.EmptyResponseException
      Description copied from interface: CommandHandler
      Override this if you want to iterate over all available servers and potentially use a result from a previous RequestHandlerat once for processing the request (like need for merging info as for a list command). This method is only called when CommandHandler.handleAllServersAtOnce(JolokiaRequest) returns true
      Specified by:
      handleAllServerRequest in interface CommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>
      Parameters:
      pServerManager - server manager holding all MBeans servers detected
      pRequest - request to process
      pPreviousResult - a previous result which for merging requests can be used to merge files
      Returns:
      the object found
      Throws:
      IOException
      JMException - for any JMX exception
      org.jolokia.server.core.request.NotChangedException - for Jolokia handling of 304 (not changed)
      org.jolokia.server.core.request.BadRequestException - when processing of user input (like path in LIST command) fails
      org.jolokia.server.core.request.EmptyResponseException - for Jolokia notification stream handling
    • destroy

      public void destroy() throws JMException
      Description copied from interface: CommandHandler
      Lifecycle method called when agent goes down. Should be overridden by a handler if required.
      Specified by:
      destroy in interface CommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>
      Throws:
      JMException
    • doHandleSingleServerRequest

      protected abstract Object doHandleSingleServerRequest(MBeanServerConnection server, R request) throws IOException, JMException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.BadRequestException, org.jolokia.server.core.request.EmptyResponseException
      Abstract method to be subclassed by a concrete handler for performing the request on a single MBeanServerConnection after the checks are performed. Subclasses should only implement the command logic.
      Parameters:
      server - server to try
      request - request to process
      Returns:
      the object result from the request
      Throws:
      IOException - when there's an error invoking MBeanServerConnection
      JMException - JMX checked exception, because most requests are handled by dealing with MBeans
      JMRuntimeException - JMX unchecked exception, because most requests are handled by dealing with MBeans
      org.jolokia.server.core.request.NotChangedException - when (according to request parameters) user wants HTTP 304 if nothing has changed
      org.jolokia.server.core.request.BadRequestException - because some commands do more user input parsing in addition to what was checked when the JolokiaRequest was created
      org.jolokia.server.core.request.EmptyResponseException - if the response should not be closed (expecting further async/stream data)
    • doHandleAllServerRequest

      protected Object doHandleAllServerRequest(org.jolokia.server.core.util.jmx.MBeanServerAccess serverManager, R request, Object pPreviousResult) throws IOException, JMException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.BadRequestException, org.jolokia.server.core.request.EmptyResponseException
      Default implementation for handling a request for multiple servers at once. A subclass, which returns, true from handleAllServersAtOnce(JolokiaRequest), needs to override this method. If handleAllServersAtOnce(JolokiaRequest) returns false, the iteration over available connections is performed by the caller (RequestHandler).
      Parameters:
      serverManager - all MBean servers found in this JVM
      request - the original request
      pPreviousResult - a previous result which for merging requests can be used to merge the data
      Returns:
      the result of the the request.
      Throws:
      IOException - when there's an error invoking MBeanServerConnection
      JMException - JMX checked exception, because most requests are handled by dealing with MBeans
      JMRuntimeException - JMX unchecked exception, because most requests are handled by dealing with MBeans
      org.jolokia.server.core.request.NotChangedException - when (according to request parameters) user wants HTTP 304 if nothing has changed
      org.jolokia.server.core.request.BadRequestException - because some commands do more user input parsing in addition to what was checked when the JolokiaRequest was created
      org.jolokia.server.core.request.EmptyResponseException - if the response should not be closed (expecting further async/stream data)
    • checkForRestriction

      protected abstract void checkForRestriction(R pRequest)
      Check whether there is a restriction on the type to apply. This method should be overwritten by specific handlers if they support a more sophisticated check than only for the type
      Parameters:
      pRequest - request to check
    • checkType

      protected void checkType()
      Check whether a command of the given type is allowed
    • isObjectNameHidden

      protected boolean isObjectNameHidden(ObjectName name)
      Checks whether an ObjectName should be removed (filtered out) from results of list or search operations.
      Parameters:
      name -
      Returns:
    • checkForModifiedSince

      protected void checkForModifiedSince(org.jolokia.server.core.util.jmx.MBeanServerAccess pServerManager, org.jolokia.server.core.request.JolokiaRequest pRequest) throws org.jolokia.server.core.request.NotChangedException
      Check, whether the set of MBeans for any managed MBeanServer has been change since the timestamp provided in the given request
      Parameters:
      pServerManager - manager for all MBeanServers
      pRequest - the request from where to fetch the timestamp
      Throws:
      org.jolokia.server.core.request.NotChangedException - if there has been no REGISTER/UNREGISTER notifications in the meantime