|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgov.sandia.ccaffeine.dc.distributed.HeartbeatMonitor
public class HeartbeatMonitor
This class listens for the arrival of heartbeats. If no heartbeat is received within a reasonable amount of time then a HeartbeatEvent is sent to every HeartbeatListener.
This class can be used by a server to monitor its connection to a client. The client can periodically sending heartbeats to the server. When the client dies or is disconnected then the client can no longer send heartbeats to the server. This client monitors the amount of time between heartbeats. If a long amount of time passes without a heartbeat then the server can be notified that the client has lost its connection to the server.
SAMPLE CODE:
HeartbeatMonitor heartbeatMonitor = new HeartbeatMonitor();
heartbeatMonitor.setNumberOfMillisecondsToWaitForHeartbeat(5000);
heartbeatMonitor.addHeartbeatListener(this);
heartbeatMonitor.start();
:
this.heartbeatMonitor.receivedHeartbeat
(new HeartbeatEvent(this));
:
public void didNotReceiveHeartbeat(HeartbeatEvent event) {
System.out.println("did not recieve heartbeat");
}
Field Summary | |
---|---|
protected int |
numberOfMillisecondsToWaitForHeartbeat
|
protected javax.swing.Timer |
timer
|
Constructor Summary | |
---|---|
HeartbeatMonitor()
|
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent event)
It has been a very long time since the arrival of the last heartbeat. |
void |
addHeartbeatListener(HeartbeatListener listener)
Register a Heartbeat Listener. |
protected void |
broadcastDidNotReceiveHeartbeatEvent(HeartbeatEvent event)
Tell all registered Heartbeat listeners that it has been a very long time since the last heartbeat arrived. |
void |
broadcastDidNotRecevieHeartbeatEvent()
Tell all registered Heartbeat listeners that it has been a very long time since the last heartbeat arrived. |
protected void |
broadcastReceivedHeartbeatEvent(HeartbeatEvent event)
Tell all registered Heartbeat listeners that a heartbeat arrived. |
void |
broadcastReceviedHeartbeatEvent()
Tell all registered Heartbeat listeners that a heartbeat arrived. |
void |
didNotReceiveHeartbeat(HeartbeatEvent event)
Call this method whenever you want to notify this class that you did NOT receive a heartbeat. |
int |
getNumberOfMillisecondsToWaitForHeartbeat()
Retrieve the number of milliseconds that we will wait for a heartbeat. |
void |
receivedHeartbeat(HeartbeatEvent event)
Call this method whenever you want to notify this class that you received a heartbeat. |
void |
removeHeartbeatListener(HeartbeatListener listener)
Unregister a Heartbeat Listener. |
void |
setNumberOfMillisecondsToWaitForHeartbeat(int numberOfMillisecondsToWaitForHeartbeat)
Set the number of milliseconds that we will wait for a heartbeat. |
void |
start()
Start monitoring the arrival of heartbeats. |
void |
stop()
Stop monitoring the arrival of heartbeats. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected javax.swing.Timer timer
protected int numberOfMillisecondsToWaitForHeartbeat
Constructor Detail |
---|
public HeartbeatMonitor()
Method Detail |
---|
public int getNumberOfMillisecondsToWaitForHeartbeat()
public void setNumberOfMillisecondsToWaitForHeartbeat(int numberOfMillisecondsToWaitForHeartbeat)
numberOfMillisecondsToWaitForHeartbeat
- The number of milliseconds we will wait
for the arrival of a heartbeat.public void receivedHeartbeat(HeartbeatEvent event)
receivedHeartbeat
in interface HeartbeatListener
public void didNotReceiveHeartbeat(HeartbeatEvent event)
didNotReceiveHeartbeat
in interface HeartbeatListener
public void start()
public void stop()
public void actionPerformed(java.awt.event.ActionEvent event)
actionPerformed
in interface java.awt.event.ActionListener
event
- public void addHeartbeatListener(HeartbeatListener listener)
listener
- The Heartbeat Listener
that wants to be notified whenever this class
recieves a heartbeat or when a very long
time passes without the arrival of a heartbeat.public void removeHeartbeatListener(HeartbeatListener listener)
listener
- The Heartbeat Listener
that no longer wants to be notified
whenever this class
recieves a heartbeat or when a very long
time passes without the arrival of a heartbeat.public void broadcastReceviedHeartbeatEvent()
protected void broadcastReceivedHeartbeatEvent(HeartbeatEvent event)
event
- The event that is generated
whenever a heartbeat arrivespublic void broadcastDidNotRecevieHeartbeatEvent()
event
- The event that is generated
whenever a heartbeat does NOT arrive
for a very long time.protected void broadcastDidNotReceiveHeartbeatEvent(HeartbeatEvent event)
event
- The event that is generated
whenever a heartbeat does NOT arrive
for a very long time.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |