Package org.jolokia.service.jmx.handler
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckForModifiedSince(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 requestprotected abstract voidcheckForRestriction(R pRequest) Check whether there is a restriction on the type to apply.protected voidCheck whether a command of the given type is allowedvoiddestroy()Lifecycle method called when agent goes down.protected ObjectdoHandleAllServerRequest(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 ObjectdoHandleSingleServerRequest(MBeanServerConnection server, R request) Abstract method to be subclassed by a concrete handler for performing the request on a singleMBeanServerConnectionafter 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 previousRequestHandlerat once for processing the request (like need for merging info as for alistcommand).booleanhandleAllServersAtOnce(R pRequest) Override this if you want all available MBeanServers to be passed to this command handler, e.g., to query each server on your own.handleSingleServerRequest(MBeanServerConnection pServer, R pRequest) Handle a request for a singleMBeanServerConnection.voidLifecycle method in order to initialize the handlerprotected booleanisObjectNameHidden(ObjectName name) Checks whether anObjectNameshould be removed (filtered out) from results oflistorsearchoperations.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jolokia.service.jmx.api.CommandHandler
getType
-
Field Details
-
context
protected org.jolokia.server.core.service.api.JolokiaContext context -
pProvider
-
-
Constructor Details
-
AbstractCommandHandler
public AbstractCommandHandler()
-
-
Method Details
-
init
Description copied from interface:CommandHandlerLifecycle method in order to initialize the handler- Specified by:
initin interfaceCommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>- Parameters:
pContext- the jolokia contextpProvider- provider to use for returned names. Handlers can use this for returning meta data with the proper provider prefixed.
-
handleAllServersAtOnce
Description copied from interface:CommandHandlerOverride 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 theRequestHandlerand this command handler is called throughCommandHandler.handleSingleServerRequest(MBeanServerConnection, JolokiaRequest).- Specified by:
handleAllServersAtOncein interfaceCommandHandler<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) orCommandHandler.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:CommandHandlerHandle a request for a singleMBeanServerConnection. Coordination of the servers and other request handlers is taken care of externally.- Specified by:
handleSingleServerRequestin interfaceCommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>- Parameters:
pServer- server to send the request topRequest- request to process- Returns:
- the result of sending a request to the MBean server
- Throws:
IOException- when there's an error invokingMBeanServerConnectionJMException- JMX checked exception, because most requests are handled by dealing with MBeansorg.jolokia.server.core.request.NotChangedException- when (according to request parameters) user wants HTTP 304 if nothing has changedorg.jolokia.server.core.request.BadRequestException- because some commands do more user input parsing in addition to what was checked when theJolokiaRequestwas createdorg.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:CommandHandlerOverride this if you want to iterate over all available servers and potentially use a result from a previousRequestHandlerat once for processing the request (like need for merging info as for alistcommand). This method is only called whenCommandHandler.handleAllServersAtOnce(JolokiaRequest)returnstrue- Specified by:
handleAllServerRequestin interfaceCommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>- Parameters:
pServerManager- server manager holding all MBeans servers detectedpRequest- request to processpPreviousResult- a previous result which for merging requests can be used to merge files- Returns:
- the object found
- Throws:
IOExceptionJMException- for any JMX exceptionorg.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) failsorg.jolokia.server.core.request.EmptyResponseException- for Jolokia notification stream handling
-
destroy
Description copied from interface:CommandHandlerLifecycle method called when agent goes down. Should be overridden by a handler if required.- Specified by:
destroyin interfaceCommandHandler<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 singleMBeanServerConnectionafter the checks are performed. Subclasses should only implement the command logic.- Parameters:
server- server to tryrequest- request to process- Returns:
- the object result from the request
- Throws:
IOException- when there's an error invokingMBeanServerConnectionJMException- JMX checked exception, because most requests are handled by dealing with MBeansJMRuntimeException- JMX unchecked exception, because most requests are handled by dealing with MBeansorg.jolokia.server.core.request.NotChangedException- when (according to request parameters) user wants HTTP 304 if nothing has changedorg.jolokia.server.core.request.BadRequestException- because some commands do more user input parsing in addition to what was checked when theJolokiaRequestwas createdorg.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,truefromhandleAllServersAtOnce(JolokiaRequest), needs to override this method. IfhandleAllServersAtOnce(JolokiaRequest)returnsfalse, the iteration over availableconnectionsis performed by the caller (RequestHandler).- Parameters:
serverManager- all MBean servers found in this JVMrequest- the original requestpPreviousResult- 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 invokingMBeanServerConnectionJMException- JMX checked exception, because most requests are handled by dealing with MBeansJMRuntimeException- JMX unchecked exception, because most requests are handled by dealing with MBeansorg.jolokia.server.core.request.NotChangedException- when (according to request parameters) user wants HTTP 304 if nothing has changedorg.jolokia.server.core.request.BadRequestException- because some commands do more user input parsing in addition to what was checked when theJolokiaRequestwas createdorg.jolokia.server.core.request.EmptyResponseException- if the response should not be closed (expecting further async/stream data)
-
checkForRestriction
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
Checks whether anObjectNameshould be removed (filtered out) from results oflistorsearchoperations.- 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 MBeanServerspRequest- 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
-