JMX Transport User Guide
Connecting to MBean server
If you do not define JmxConnector, the default one connects to the Platform MBean Server using ManagementFactory.getPlatformMBeanServer() .
JmxConnector Properties
| Property |
Description |
Default |
Required |
| serviceUrl |
If set, specifies the JMX service URL to an MBean Agent; if null - connecting to the Platform MBean Server . |
null |
No |
| environment |
A map passed to both JMXConnectorFactory.connect() (creating the connector) and JMXConnector.connect() (establishing the actual connection). |
null |
No |
| delegationSubject |
Used when we want to authenticate as certain user and execute the actions on behalf of third party (similar to the sudo Unix command). See Subject for more details. |
null |
No |
| mbeanAliases |
A map defining shortcuts for known MBean names. You can use either these aliases or the full object names in the EndpointURIs to the same effect. This property somewhat deviates from the normal behaviour in the way that when we use the setter, the values are added to the map instead of replacing it. If we pass a mapping for existing key, it overrides the old one. If we want to delete some values, pass in a mapping to null. |
~delegate - the MBean server delegate
~connector - the JmxConnector if using remote connection. |
No |
JmxConnector Configuration Example
The following snippet shows how to connect using JMX RMIConnector to some MBean server registered in a remote RMI Registry.
- The serviceUrl specifies to MBean server exposed on RMI Connector, registered under the name of "jmx" in RMI Registry listening on localhost:1099.
- We pass the same environment map to the connector factory and the connector, containing two string properties ('user' and 'pass').
- We lookup a delegationSubject from a Spring container. If the subject is null, the connection has the permissions of the authenticated principle (determined by the user and pass properties passed as environment)
<connector name="JmxLocal" className="org.mule.providers.jmx.JmxConnector">
<properties>
<property name="serviceUrl" value="service:jmx:rmi://localhost/jndi/rmi://somehost:1099/jmx"/>
<container-property name="delegationSubject" reference="jmx.principal" container="spring" required="false"/>
<map name="environment">
<property name="user" value="username"/>
<property name="pass" value="secret"/>
</map>
<map name="mbeanAliases">
<property name="stub" value="myapp:type=com.acme.Stub,name=TheStub"/>
<property name="mule-manager"
value="Mule.Myapp:type=org.mule.ManagementContext,name=MuleServerInfo"/>
</map>
</properties>
</connector>
Invoking JMX operation
Invoking JMX operations is as simple as dispatching an event containing array payload to JMX operation endpoint.
| Mule Method |
Description |
| dispatch |
Invokes the JMX operation asynchronously and throws away the result. |
| send |
Invokes the JMX operation synchronously returns the result. |
| receive |
Tries to invoke the method without arguments and returns the result. If there is no method with such name and no args - throws exception. |
The passed arguments should match in count and type the operation signature. If the operation is overloaded, we will try to select the right one based on the count and type of the arguments. If more than one overloaded operations match the arguments, we will throw exception.
Example:
interface FoobarMbean {
void operation(Object arg);
void operation(Date arg);
}
In this case, we will not be able to resolve the operation if the actual argument is of type Date because both methods are a legal match.
If we specify 'signature' endpoint parameter, it's a semicolon-separated list of signature strings. In this case each argument is checked to end on the signature string in that position. (i.e. 'String' will match java.lang.String and com.foo.String, while 'lang.String' will match only the first one.)
If we specify the 'raw' endpoint parameter without value or any other value than 'false', then the parameters are extracted from the untransformed payload.
Manipulating JMX attributes
JMX attributes are manipulated by sending and receiving messages to attribute endpoint. Keep in mind that this is pretty inefficient way of accessing multiple attributes of the same MBean (compared to the MBeanServerConnection.setAttributes() method).
| Mule Method |
Description |
| dispatch |
Sets the attribute to the payload. |
| send |
Sets the attribute to the payload, then gets the attribute value and compares with the payload and returns the boolean result of the comparison. |
| receive |
Gets the attribute value and returns it as a payload. |
 |
When the attribute value is null, the UMOMessage's payload will be an actual instance of NullPayload. You need to make an instanceof check first in your code, before you cast the payload to the expected type. |
Receiving JMX notifications
The JMX notifications can be received by listening on an inbound endpoint. Currently, the JMX transport provides no facility to broadcast notifications.
- The ~delegate is an alias for the MBeanServerDelegate, allowing to listen for notifications from the MBean server.
- The ~connector is an aliases for the connector used to ewstablish the connection with the MBean server. When using local MBean server, the connector will be null and any attempt to listen for notifications will be ignored.
- The <types-spec> is optional parameter and specifies semicolon-separated list of notification-types to listen for, which are used to set up a NotificationFilterSupport and also can be used with the derived MBeanServerNotificationFilter .
- The ~delegate MBean supports the following type aliases:
- .registered - a new bean is registered in the MBean server
- .unregistered - a bean is removed from the MBean server
- The ~connector MBean supports the following type aliases:
- .opened - connection received
- .closed - connection closed
- .failed - connection failed
- .notif-lost - there is a chance that some motifications have been lost
- The <attributes-spec> is optional parameter and specifies semicolon-separated list of attributes to listen for, which are used to set up an AttributeChangeNotificationFilter.
- The <beans-spec> is a list of object names separated by semicolons. It's used to set up a MBeanServerNotificationFilter Each element is considered a string representation of an object name, optionally prefixed with exclamation mark. For each object name we add either inclusion or exclusion pattern (the ones prefixed with '!' are excluded). A special case is the asterisk, which enables/disables everything. If using asterisk, it should be the first element in the list.
Transformers
Perhaps we should put them in a separate "Semi-structured data" module together with the collection, string transformers and structure-schema validators?
ObjectToArray transformer
Handles some common transformations producing arrays:
| Input |
Output |
| NullPayload |
Null singleton array {{new Object[] { null }}} |
| Primitive array (int[], char[], etc.) |
Boxed array (Integer[], Character[]) |
| Object array |
Object array of the same type. |
| Iterable (including all collections) |
Object[] containing the elements returned by the iterator. |
| Anything else |
Singleton array {{new Object[] { obj }}} |
ArraySizeNormalizer transformer
Accepts array of any size and converts it to array of the same type and fixed size. If the input array is longer than the desired size - it gets truncated, if it was shorter - it gets padded with nulls, zeroes or falses.
Has the following attributes
- desiredLength - an integer determining the desired length of the output array. If negative, the transformer would not modify the input, but will throw IllegalArgumentException if the input is not an array. Default value is -1.
- trimLeading - determines where does the truncation/padding occur. If false (default) - it gets padded at the end ant the trailing elements are truncated; if true - it gets padded at the front and the leading elements get truncated.
URI examples
jmx:operation:jmx:attribute:jmx:notification:jmx:notification:jmx:notification:jmx:operation:jmx:notification:jmx:notification:jmx:notification:jmx:notification:jmx:notification: