Because the broadcaster and the listener are running on separate machines or in separate JVMs on the same host, their notifications must be forwarded from one to the other. The mechanism for doing this is completely transparent to the components of the Java Dynamic Management Kit.
Briefly, the connector client instructs the connector server to add its own agent-side listener to the designated broadcaster using the methods of the MBeans server. Then, the connector server implements a buffering cache mechanism to centralize notifications before serializing them to be forwarded to the connector client. By design, the agent doesn't control the buffering and forwarding mechanism; it is the manager where the listeners reside that has this privilege.
Neither the broadcaster nor the listener need to implement any extra methods, or even be aware that the other party is remote. Only the designer needs to be aware of communication issues such as delays: you can't expect the listener to be invoked immediately after a remote broadcaster sends a notification.
The forwarding mechanism allows you to configure how and when notifications are forwarded. This allows you to optimize the communication strategy between your agents and managers.
There are two basic modes for notification forwarding: push mode and pull mode. They are named according to the action performed on a notification that has been sent and is in the connector server's buffer. This notification is either pushed to the manager at the agent's initiative, or pulled by the manager at its own initiative.
The push mode for notification forwarding is the simplest because it implements the expected behavior of a notification. When a notification is sent from an MBean to its listener, it is immediately pushed to the manager-side where the listener's handler method is called. There is no delay in the caching, and if the communication layer is quick enough, the listener is invoked almost immediately after the notification is sent.
Push mode is the default forwarding policy of a newly instantiated connector client.
In our manager example, we explicitly set the connector client in push mode and then trigger the agent-side notifications.
System.out.println("\n>>> Set notification forward mode to PUSH."); connectorClient.setMode(ClientNotificationHandler.PUSH_MODE); System.out.println(">>> Have our MBean broadcast 10 notifications..."); params[0] = new Integer(10); signatures[0] = "java.lang.Integer"; connectorClient.invoke(mbean, "sendNotifications", params, signatures); System.out.println(">>> Done."); System.out.println(">>> Receiving notifications...\n"); // Nothing to do but wait while our handler receives the notifications Thread.sleep(2000); |
As we shall see when describing the pull mode, the connector client exposes the methods for controlling the agent's notification buffer. This caching buffer is not used in push mode, so these methods do not affect pushed notifications. The methods do however set internal variables that will be taken into account if and when pull mode is enabled. Future versions of the product may implement push-mode buffering to provide added functionality.
The advantage of push mode is that it works without any further intervention: notifications eventually reach their remote listeners. Push mode works when the communication layer and the listener's processing capacity are adapted to the notification emission rate, or more specifically to the potential emission rate. Since all notifications are immediately sent to the manager hosts, a burst of notifications will cause a burst of traffic that may or may not be adapted to the communication layer.
If your communication layer is likely to be saturated or must be preserved in all cases, either your design should control broadcasters to prevent bursts of notifications, or you should use the pull mode which has this control functionality built-in. The push mode is ideal if you have reliable and fast communication between your agents and your managers. You may also dynamically switch between modes, allowing a management application to fine-tune its communication policy depending on the number of notifications that must be handled.