This package contains the core RJMX API. RJMX is an equinox plug-in that extends JMX with pluggable JMX based services and convenience look-up services to find agents to connect to. The default services encompass a compatibility layer, an attribute subscription engine, a notification service and others.

Example usage:


// Connect to thyself
IConnectionDescriptor descriptor = new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(); //$NON-NLS-1$
IServerHandle serverHandle = new ServerHandle(descriptor);
IConnectionHandle handle = serverHandle.connect("Usage description"); //$NON-NLS-1$
try {
	ISubscriptionService service = handle.getServiceOrDummy(ISubscriptionService.class);
	MRI attribute = new MRI(Type.ATTRIBUTE, "java.lang:type=Threading", "ThreadCount"); //$NON-NLS-1$ //$NON-NLS-2$
	service.addMRIValueListener(attribute, new IMRIValueListener() {
		@Override
		public void valueChanged(MRIValueEvent event) {
			System.out.println(event.getValue());
		}
	});
	IMRISubscription subscription = service.getMRISubscription(attribute);
	subscription.setUpdatePolicy(PolicyFactory.createSimpleUpdatePolicy(1500));
} finally {
	IOToolkit.closeSilently(handle);
}

// Iterate the model and try to connect to the ourselves
IServerModel model = RJMXPlugin.getDefault().getService(IServerModel.class);
for (IServer server : model.elements()) {
	IServerDescriptor descriptor = server.getServerHandle().getServerDescriptor();
	if (descriptor.getJvmInfo() != null && Integer.valueOf(LocalMBeanToolkit.getThisPID()).equals(descriptor.getJvmInfo().getPid())) {
		IConnectionHandle handle = server.getServerHandle().connect("Usage description"); //$NON-NLS-1$
		try {
			handle.getServiceOrDummy(IMBeanHelperService.class).getMBeanNames().size();
			return;
		} finally {
			IOToolkit.closeSilently(handle);
		}
	}
}

Notable interfaces and starting points:

IConnectionDescriptor represents a way to reach a server.

IConnectionHandle is an active connection to a server. Must always be closed when not used anymore.

IServerHandle is a handle used to connect to a server, share the connection between users (IConnectionHandles), keep track of all open IConnectionHandles and close the connection when all IConnectionHandles are closed.

IServer represents the entry point to a single server in the model.

Notice that the subscription thread is a deamon thread - if trying the example above in a main, add a Thread.sleep(10000) before the disconnect.