Environment providers for JMX remote connections
From JPPF 6.2 Documentation
Main Page > Customizing JPPF > JMX environment providers |
JPPF provides a management and monitoring API that relies on the JMX remote APIs and the JMXMP remote connector. This extension allows user-defined code to override or add parameters to those provided by default to both sides of each JMX connection. A possible use for this is to provide a way to use external tools such as JConsole or VisualVM to monitor JPPF servers and nodes. It can also be used to configure more sphisticated authentication and authorization protocols such as provided in the SASL profile of the JMXMP protocol. Of course, there can be many more uses.
To establish a JMX connection, JPPF uses the following standard JMX remote APIs:
- on the server side of the connection:
JMXConnectorServerFactory.newJMXConnectorServer(
JMXServiceURL serviceURL, Map<String,?> environment, MBeanServer mbeanServer)
- on the client side of the connection:
JMXConnectorFactory.newJMXConnector(JMXServiceURL serviceURL, Map<String,?> environment)
You will note that both sides of the connection accept an environment parameter, which contains the parameters provided to the JMX remote connector. An environment provider allows you to define a different set of parameters that may override or add to these environment properties.
To achieve this, JPPF has two interfaces, one for each side of a JMX connection:
ServerEnvironmentProvider is defined like this:
public interface ServerEnvironmentProvider { // Get a set of environment properties add to or override those // passed to each new remote connector server Map<String, ?> getEnvironment(); }
ClientEnvironmentProvider is defined like this:
public interface ClientEnvironmentProvider { // Get a set of environment properties add to or override those // passed to each new remote connector Map<String, ?> getEnvironment(); }
To create an environment provider, you need to create a class with a no-args constructor, which implements one of these interfaces. For example, here is a simple client environment provider:
public class MyClientProvider implements ClientEnvironmentProvider { @Override public Map<String, ?> getEnvironment() { Object myObject = ...; Map<String, Object> env = new HashMap<>(); env.put("my.property", myObject); return env; } }
Note: for this code to compile, you need the jppf-jmxremote_optional-x.y.z.jar file in your build path.
As for many other extensions, environment providers are discovered via the Service Provider Interface (SPI) mechanism:
For a server environment provider:
- create a file javax.management.remote.generic.ServerEnvironmentProvider in the META-INF/services folder
- in this file, add the fully qualified class name of your implementation of ServerEnvironmentProvider
For a client environment provider:
- create a file javax.management.remote.generic.ClientEnvironmentProvider in the META-INF/services folder
- in this file, add the fully qualified class name of your implementation of ClientEnvironmentProvider
Main Page > Customizing JPPF > JMX environment providers |