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>
A handler for dealing with a certain Jolokia command
- 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 fo 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.handleAllServerRequest(org.jolokia.server.core.util.jmx.MBeanServerAccess pServerManager, R pRequest, Object pPreviousResult) Override this if you want to have all servers at once for processing the request (like need for merging info as for alistcommand).booleanhandleAllServersAtOnce(R pRequest) Override this if you want all servers as list in the argument, e.g.handleSingleServerRequest(MBeanServerConnection pServer, R pRequest) Handle a request for a single server and throw anInstanceNotFoundExceptionif the request cannot be handle by the provided server.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
Override this if you want all servers as list in the argument, e.g. to query each server on your own. By default, dispatching of the servers are done for you- 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 InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.EmptyResponseException Handle a request for a single server and throw anInstanceNotFoundExceptionif the request cannot be handle by the provided server. Does a check for restrictions as well- Specified by:
handleSingleServerRequestin interfaceCommandHandler<R extends org.jolokia.server.core.request.JolokiaRequest>- Parameters:
pServer- server to trypRequest- request to process- Returns:
- the object result from the request
- Throws:
InstanceNotFoundException- if the provided server cant handle the requestAttributeNotFoundExceptionReflectionExceptionMBeanExceptionIOExceptionorg.jolokia.server.core.request.NotChangedExceptionorg.jolokia.server.core.request.EmptyResponseException
-
handleAllServerRequest
public Object handleAllServerRequest(org.jolokia.server.core.util.jmx.MBeanServerAccess pServerManager, R pRequest, Object pPreviousResult) throws ReflectionException, InstanceNotFoundException, MBeanException, AttributeNotFoundException, IOException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.EmptyResponseException Override this if you want to have all servers at 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:
ReflectionExceptionInstanceNotFoundExceptionMBeanExceptionAttributeNotFoundExceptionIOExceptionorg.jolokia.server.core.request.NotChangedExceptionorg.jolokia.server.core.request.EmptyResponseException
-
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:
-
doHandleSingleServerRequest
protected abstract Object doHandleSingleServerRequest(MBeanServerConnection server, R request) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.EmptyResponseException Abstract method to be subclassed by a concrete handler for performing the request.- Parameters:
server- server to tryrequest- request to process- Returns:
- the object result from the request
- Throws:
InstanceNotFoundExceptionAttributeNotFoundExceptionReflectionExceptionMBeanExceptionIOExceptionorg.jolokia.server.core.request.NotChangedExceptionorg.jolokia.server.core.request.EmptyResponseException
-
doHandleAllServerRequest
protected Object doHandleAllServerRequest(org.jolokia.server.core.util.jmx.MBeanServerAccess serverManager, R request, Object pPreviousResult) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, org.jolokia.server.core.request.NotChangedException, org.jolokia.server.core.request.EmptyResponseException Default implementation fo handling a request for multiple servers at once. A subclass, which returns,trueonhandleAllServersAtOnce(JolokiaRequest), needs to override this method.- Parameters:
serverManager- all MBean servers found in this JVMrequest- the original requestpPreviousResult- a previous result which for merging requests can be used to merge files- Returns:
- the result of the the request.
- Throws:
IOExceptionAttributeNotFoundExceptionInstanceNotFoundExceptionMBeanExceptionReflectionExceptionorg.jolokia.server.core.request.NotChangedExceptionorg.jolokia.server.core.request.EmptyResponseException
-
destroy
Lifecycle 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
-
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
-