The examplesDir/HeartBeat directory contains all of the files for the Agent and Client applications which demonstrate the heartbeat mechanism through an RMI connector.
Compile all files in this directory with the javac command. For example, on the Solaris platform with the Korn shell, you would type:
$ cd examplesDir/HeartBeat/ $ javac -classpath classpath *.java |
To demonstrate the various communication scenarios, we run the example three times: once to see a normal termination, once to see how the manager reacts to a lost connection, and once to see how the agent reacts to a lost connection.
Launch the agent on another host or in another terminal window with the following command:
$ java -classpath classpath Agent |
The agent only creates the RMI connector server to which the client application will establish a connection, and then it waits for management operations.
Wait for the agent to be completely initialized, then launch the manager with the following command, where hostname is the name of the machine running the agent. The RMI connector in this example uses port 1099 by default. If you launched the agent on the same machine, you can omit the hostname and the port number:
$ java -classpath classpath Client hostname 1099 |
The client application creates the RMI connector client, configures its heartbeat, and registers a notification listener, as seen in the code examples. When the connection is established, the listener outputs the notification information in the terminal window.
Press <Enter> in the manager window to call the disconnect method on the connector client and stop the Client application.
In the terminal window, the heartbeat notification listener outputs the information for the normal connection termination before the application ends.
Leave the agent application running for the next scenario.
Launch the Client application again with the same command as before:
$ java -classpath classpath Client hostname 1099 |
When the connection is established, type <Control-C> in the agent's window to stop the connector server and the agent application. This simulates a broken communication channel as seen by the connector client.
Less than a second later, when the next heartbeat fails, the heartbeat retrying notification is displayed in the manager's terminal window. Two seconds later, after both retries have failed, the lost connection and terminated connection notifications are displayed.
Press <Enter> in the manager window to exit the Client application.
Launch the agent in debug mode on another host or in another terminal window with the following command:
$ java -classpath classpath -DLEVEL_DEBUG Agent |
Wait for the agent to be completely initialized, then launch the Client application again with the same command as before:
$ java -classpath classpath Client hostname 1099 |
When the connection is established, you should see the periodic heartbeat messages in the debug output of the agent.
This time, type <Control-C> in the client's window to stop the connector client and the manager application. This simulates a broken communication channel as seen by the connector server in the agent.
After the heartbeat retry timeout elapses in the agent, you should see the lost connection message in the heartbeat debugging output of the agent.
Type <Control-C> in the agent window to stop the agent application and end the example.