Class JolokiaContextImpl

java.lang.Object
org.jolokia.server.core.service.impl.JolokiaContextImpl
All Implemented Interfaces:
JolokiaContext, LogHandler, Restrictor

public class JolokiaContextImpl extends Object implements JolokiaContext
Central implementation of the JolokiaContext
Since:
09.04.13
Author:
roland
  • Method Details

    • setDebugStore

      public void setDebugStore(DebugStore debugStore)
    • registerMBean

      Register an MBean which gets automatically unregistered during shutdown.
      Specified by:
      registerMBean in interface JolokiaContext
      Parameters:
      pMBean - MBean to register
      pOptionalName - optional name under which the bean should be registered. If not provided, it depends on whether the MBean to register implements MBeanRegistration or not.
      Returns:
      the name under which the MBean is registered.
      Throws:
      MalformedObjectNameException
      NotCompliantMBeanException
      InstanceAlreadyExistsException
      MBeanRegistrationException
    • unregisterMBean

      public void unregisterMBean(ObjectName pObjectName) throws MBeanRegistrationException
      Unregister an MBean explicitly. This is typically not necessary but becomes necessary if a module goes down without shutting down the agen
      Specified by:
      unregisterMBean in interface JolokiaContext
      Parameters:
      pObjectName - name of the mbean to unregister
      Throws:
      MBeanRegistrationException
    • getMBeanServerAccess

      public MBeanServerAccess getMBeanServerAccess()
      Get an MBeanServerAccess for easy access of the JMX subsystem even when there are multiple MBeanServers available. It uses a template mechanism with callback
      Specified by:
      getMBeanServerAccess in interface JolokiaContext
      Returns:
      the executor to use
    • getAgentDetails

      public AgentDetails getAgentDetails()
      Get the details which specify the current agent. The returned details should not be kept but instead each time details are needed this interface should be queried again.
      Specified by:
      getAgentDetails in interface JolokiaContext
      Returns:
      the details for this agent.
    • getConfig

      public String getConfig(ConfigKey pOption)
      Get a configuration value if set as configuration or the default value if not
      Specified by:
      getConfig in interface JolokiaContext
      Parameters:
      pOption - the configuration key to lookup
      Returns:
      the configuration value or the default value if no configuration was given.
    • getConfig

      public String getConfig(ConfigKey pOption, boolean checkSysOrEnv)
      Get a configuration value if set as configuration or the default value if not
      Specified by:
      getConfig in interface JolokiaContext
      Parameters:
      pOption - the configuration key to lookup
      checkSysOrEnv - whether system property / environment variable should be checked first
      Returns:
      the configuration value or the default value if no configuration was given.
    • getConfigKeys

      public Set<ConfigKey> getConfigKeys()
      Get all keys stored in this configuration
      Specified by:
      getConfigKeys in interface JolokiaContext
    • getServices

      public <T extends JolokiaService<?>> SortedSet<T> getServices(Class<T> pType)
      Get Jolokia services of a certain kind. The returned list might be empty, but never null. The set is sorted according to the service order (see JolokiaService.getOrder()).
      Specified by:
      getServices in interface JolokiaContext
      Parameters:
      pType - requested service type
      Returns:
      sorted set of services or an empty set
    • getService

      public <T extends JolokiaService<?>> T getService(Class<T> pType)
      Get a single service. If more than one service of the given type has been registered, return the one with the highest order. If no one has been registered return null
      Specified by:
      getService in interface JolokiaContext
      Parameters:
      pType - requested service type
      Returns:
      the requested service or null if none has been registered
    • getMandatoryService

      public <T extends JolokiaService<?>> T getMandatoryService(Class<T> pType)
      Get a single, mandatory, service. If not present, then an exception is thrown. Also, an exception is raised if more than one service exist
      Specified by:
      getMandatoryService in interface JolokiaContext
      Parameters:
      pType - requested service type
      Returns:
      the requested service
    • isDebug

      public boolean isDebug()
      Check whether debug is switched on
      Specified by:
      isDebug in interface LogHandler
      Returns:
      true if debugging is enabled
    • debug

      public void debug(String message)
      Log a debug messages
      Specified by:
      debug in interface LogHandler
      Parameters:
      message - debug message
    • info

      public void info(String message)
      Log informal message
      Specified by:
      info in interface LogHandler
      Parameters:
      message - message to log
    • error

      public void error(String message, Throwable t)
      Log an error
      Specified by:
      error in interface LogHandler
      Parameters:
      message - error message
      t - exception causing this error
    • isHttpMethodAllowed

      public boolean isHttpMethodAllowed(HttpMethod pMethod)
      Check whether the HTTP method with which the request was sent is allowed.
      Specified by:
      isHttpMethodAllowed in interface Restrictor
      Parameters:
      pMethod - method to check
      Returns:
      true if there is no restriction on the method with which the request was sent, false otherwise
    • isTypeAllowed

      public boolean isTypeAllowed(RequestType pType)
      Check whether the provided command type is allowed in principal
      Specified by:
      isTypeAllowed in interface Restrictor
      Parameters:
      pType - type to check
      Returns:
      true, if the type is allowed, false otherwise
    • isAttributeReadAllowed

      public boolean isAttributeReadAllowed(ObjectName pName, String pAttribute)
      Check whether reading of an attribute is allowed
      Specified by:
      isAttributeReadAllowed in interface Restrictor
      Parameters:
      pName - MBean name
      pAttribute - attribute to check
      Returns:
      true if access is allowed
    • isAttributeWriteAllowed

      public boolean isAttributeWriteAllowed(ObjectName pName, String pAttribute)
      Check whether writing of an attribute is allowed
      Specified by:
      isAttributeWriteAllowed in interface Restrictor
      Parameters:
      pName - MBean name
      pAttribute - attribute to check
      Returns:
      true if access is allowed
    • isOperationAllowed

      public boolean isOperationAllowed(ObjectName pName, String pOperation)
      Check whether execution of an operation is allowed
      Specified by:
      isOperationAllowed in interface Restrictor
      Parameters:
      pName - MBean name
      pOperation - attribute to check
      Returns:
      true if access is allowed
    • isRemoteAccessAllowed

      public boolean isRemoteAccessAllowed(String... pHostOrAddress)
      Check whether access from the connected client is allowed. If at least one of the given parameters matches, then this method returns true.
      Specified by:
      isRemoteAccessAllowed in interface Restrictor
      Parameters:
      pHostOrAddress - one or more host or address names.
      Returns:
      true is access is allowed
    • isOriginAllowed

      public boolean isOriginAllowed(String pOrigin, boolean pStrictCheck)
      Check whether cross browser access via CORS is allowed. See the CORS specification for details
      Specified by:
      isOriginAllowed in interface Restrictor
      Parameters:
      pOrigin - the "Origin:" header provided within the request
      pStrictCheck - whether by-pass check when strict checking is disabled
      Returns:
      true if this cross browser request allowed, false otherwise