After every 5 seconds a node pings the server. If the ping is successful, node’s time-stamp gets updated into the server database.After every 3 minutes server checks if there is any time-stamp older than 3 minutes. If it founds any,it removes the node from it’s database.
Now the problem. I am unable to implement this query. For example I want it in a rather simple way like :
// Get the server time-stamp in milliseconds
select LastPingedAt from JustPinged where LastPingedAt > 3 Minutes"
// If it finds any,delete each of them from the database.
The logic :
Let the server's time stamp at the point of checking be 'serverStamp'
Let the node's time stamp (time in milliseconds when it last pinged) in the
database's table be 'nodeStamp'.
If ( serverStamp - nodeStamp > 3 minutes)
// Delete those nodes
If( severStamp - nodeStamp < 3 minutes)
// retain those nodes
I am unable to design a the query to implement further.
At any point, JustPinged table looks like :
--------------------------|----------------------
NodesThatJustPinged | LastPingedAt
--------------------------|-----------------------
xxx.xxx.xxx.xxx | 1355406367402
--------------------------|-----------------------
yyy.yyy.yyy.yyy | 1355406421277
--------------------------|-----------------------
The time is in milliseconds as from new GregorianCalendar().getTimeInMillis().
There is no need to get all of the records and process them in your program. This can be done with a single SQL statement. All you need to execute is a statement like this:
So you just need to build the string in Java, interpolating the current time value, and run it: