org.springframework.jmx.access

Class MBeanClientInterceptor

  • java.lang.Object
    • org.springframework.jmx.access.MBeanClientInterceptor
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected Log logger
      Logger available to subclasses.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void afterPropertiesSet()
      Prepares the MBeanServerConnection if the "connectOnStartup" is turned on (which it is by default).
      protected java.lang.Object convertResultValueIfNecessary(java.lang.Object result, MethodParameter parameter)
      Convert the given result object (from attribute access or operation invocation) to the specified target class for returning from the proxy method.
      void destroy()
      Invoked by the containing BeanFactory on destruction of a bean.
      protected java.lang.Object doInvoke(MethodInvocation invocation)
      Route the invocation to the configured managed resource.
      java.util.Map<java.lang.String,?> getEnvironment()
      Allow Map access to the environment to be set for the connector, with the option to add or override specific entries.
      protected java.lang.Class<?> getManagementInterface()
      Return the management interface of the target MBean, or null if none specified.
      protected java.lang.Object handleConnectFailure(MethodInvocation invocation, java.lang.Exception ex)
      Refresh the connection and retry the MBean invocation if possible.
      java.lang.Object invoke(MethodInvocation invocation)
      Route the invocation to the configured managed resource..
      protected boolean isPrepared()
      Return whether this client interceptor has already been prepared, i.e.
      void prepare()
      Ensures that an MBeanServerConnection is configured and attempts to detect a local connection if one is not supplied.
      void setAgentId(java.lang.String agentId)
      Set the agent id of the MBeanServer to locate.
      void setBeanClassLoader(java.lang.ClassLoader beanClassLoader)
      Callback that supplies the bean class loader to a bean instance.
      void setConnectOnStartup(boolean connectOnStartup)
      Set whether or not the proxy should connect to the MBeanServer at creation time ("true") or the first time it is invoked ("false").
      void setEnvironment(java.util.Map<java.lang.String,?> environment)
      Specify the environment for the JMX connector.
      void setManagementInterface(java.lang.Class<?> managementInterface)
      Set the management interface of the target MBean, exposing bean property setters and getters for MBean attributes and conventional Java methods for MBean operations.
      void setObjectName(java.lang.Object objectName)
      Set the ObjectName of the MBean which calls are routed to, as ObjectName instance or as String.
      void setRefreshOnConnectFailure(boolean refreshOnConnectFailure)
      Set whether to refresh the MBeanServer connection on connect failure.
      void setServer(javax.management.MBeanServerConnection server)
      Set the MBeanServerConnection used to connect to the MBean which all invocations are routed to.
      void setServiceUrl(java.lang.String url)
      Set the service URL of the remote MBeanServer.
      void setUseStrictCasing(boolean useStrictCasing)
      Set whether to use strict casing for attributes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        protected final Log logger
        Logger available to subclasses.
    • Constructor Detail

      • MBeanClientInterceptor

        public MBeanClientInterceptor()
    • Method Detail

      • setServer

        public void setServer(javax.management.MBeanServerConnection server)
        Set the MBeanServerConnection used to connect to the MBean which all invocations are routed to.
      • setServiceUrl

        public void setServiceUrl(java.lang.String url)
                           throws java.net.MalformedURLException
        Set the service URL of the remote MBeanServer.
        Throws:
        java.net.MalformedURLException
      • setEnvironment

        public void setEnvironment(@Nullable
                                   java.util.Map<java.lang.String,?> environment)
        Specify the environment for the JMX connector.
        See Also:
        JMXConnectorFactory.connect(javax.management.remote.JMXServiceURL, java.util.Map)
      • getEnvironment

        @Nullable
        public java.util.Map<java.lang.String,?> getEnvironment()
        Allow Map access to the environment to be set for the connector, with the option to add or override specific entries.

        Useful for specifying entries directly, for example via "environment[myKey]". This is particularly useful for adding or overriding entries in child bean definitions.

      • setAgentId

        public void setAgentId(java.lang.String agentId)
        Set the agent id of the MBeanServer to locate.

        Default is none. If specified, this will result in an attempt being made to locate the attendant MBeanServer, unless the "serviceUrl" property has been set.

        See Also:

        Specifying the empty String indicates the platform MBeanServer.

      • setConnectOnStartup

        public void setConnectOnStartup(boolean connectOnStartup)
        Set whether or not the proxy should connect to the MBeanServer at creation time ("true") or the first time it is invoked ("false"). Default is "true".
      • setRefreshOnConnectFailure

        public void setRefreshOnConnectFailure(boolean refreshOnConnectFailure)
        Set whether to refresh the MBeanServer connection on connect failure. Default is "false".

        Can be turned on to allow for hot restart of the JMX server, automatically reconnecting and retrying in case of an IOException.

      • setObjectName

        public void setObjectName(java.lang.Object objectName)
                           throws javax.management.MalformedObjectNameException
        Set the ObjectName of the MBean which calls are routed to, as ObjectName instance or as String.
        Throws:
        javax.management.MalformedObjectNameException
      • setUseStrictCasing

        public void setUseStrictCasing(boolean useStrictCasing)
        Set whether to use strict casing for attributes. Enabled by default.

        When using strict casing, a JavaBean property with a getter such as getFoo() translates to an attribute called Foo. With strict casing disabled, getFoo() would translate to just foo.

      • setManagementInterface

        public void setManagementInterface(@Nullable
                                           java.lang.Class<?> managementInterface)
        Set the management interface of the target MBean, exposing bean property setters and getters for MBean attributes and conventional Java methods for MBean operations.
      • getManagementInterface

        @Nullable
        protected final java.lang.Class<?> getManagementInterface()
        Return the management interface of the target MBean, or null if none specified.
      • afterPropertiesSet

        public void afterPropertiesSet()
        Prepares the MBeanServerConnection if the "connectOnStartup" is turned on (which it is by default).
        Specified by:
        afterPropertiesSet in interface InitializingBean
      • prepare

        public void prepare()
        Ensures that an MBeanServerConnection is configured and attempts to detect a local connection if one is not supplied.
      • isPrepared

        protected boolean isPrepared()
        Return whether this client interceptor has already been prepared, i.e. has already looked up the server and cached all metadata.
      • handleConnectFailure

        @Nullable
        protected java.lang.Object handleConnectFailure(MethodInvocation invocation,
                                                                  java.lang.Exception ex)
                                                           throws java.lang.Throwable
        Refresh the connection and retry the MBean invocation if possible.

        If not configured to refresh on connect failure, this method simply rethrows the original exception.

        Parameters:
        invocation - the invocation that failed
        ex - the exception raised on remote invocation
        Returns:
        the result value of the new invocation, if succeeded
        Throws:
        java.lang.Throwable - an exception raised by the new invocation, if it failed as well
        See Also:
        setRefreshOnConnectFailure(boolean), doInvoke(org.aopalliance.intercept.MethodInvocation)
      • doInvoke

        @Nullable
        protected java.lang.Object doInvoke(MethodInvocation invocation)
                                               throws java.lang.Throwable
        Route the invocation to the configured managed resource. Correctly routes JavaBean property access to MBeanServerConnection.get/setAttribute and method invocation to MBeanServerConnection.invoke.
        Parameters:
        invocation - the MethodInvocation to re-route
        Returns:
        the value returned as a result of the re-routed invocation
        Throws:
        java.lang.Throwable - an invocation error propagated to the user
      • convertResultValueIfNecessary

        @Nullable
        protected java.lang.Object convertResultValueIfNecessary(@Nullable
                                                                           java.lang.Object result,
                                                                           MethodParameter parameter)
        Convert the given result object (from attribute access or operation invocation) to the specified target class for returning from the proxy method.
        Parameters:
        result - the result object as returned by the MBeanServer
        parameter - the method parameter of the proxy method that's been invoked
        Returns:
        the converted result object, or the passed-in object if no conversion is necessary
      • destroy

        public void destroy()
        Description copied from interface: DisposableBean
        Invoked by the containing BeanFactory on destruction of a bean.
        Specified by:
        destroy in interface DisposableBean