Update our LAST_UPDATED column every minute while we're alive so that if we

lose connection with a peer for any reason, it will notice that we're still
alive and reconnect.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4732 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-06-13 23:36:25 +00:00
parent 2fa6146d93
commit 0c448bc92d
3 changed files with 24 additions and 10 deletions
@@ -579,6 +579,9 @@ public class PeerManager
_invoker.postUnit(new Invoker.Unit() {
public boolean invoke () {
try {
// let the world know that we're alive
_noderepo.heartbeatNode(_nodeName);
// then load up all the peer records
_nodes = _noderepo.loadNodes();
return true;
} catch (PersistenceException pe) {
@@ -51,8 +51,7 @@ public class NodeRecord
}
/** Creates a record for the specified node. */
public NodeRecord (String nodeName, String hostName, String publicHostName,
int port)
public NodeRecord (String nodeName, String hostName, String publicHostName, int port)
{
this.nodeName = nodeName;
this.hostName = hostName;
@@ -23,6 +23,7 @@ package com.threerings.presents.peer.server.persist;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import com.samskivert.io.PersistenceException;
@@ -38,15 +39,14 @@ import com.samskivert.jdbc.jora.Table;
*/
public class NodeRepository extends JORARepository
{
/** The database identifier used when establishing a database connection.
* This value being <code>nodedb</code>. */
/** The database identifier used when establishing a database connection. This value being
* <code>nodedb</code>. */
public static final String NODE_DB_IDENT = "nodedb";
/**
* Constructs a new repository with the specified connection provider.
*
* @param conprov the connection provider via which we will obtain our
* database connection.
* @param conprov the connection provider via which we will obtain our database connection.
*/
public NodeRepository (ConnectionProvider conprov)
throws PersistenceException
@@ -64,15 +64,28 @@ public class NodeRepository extends JORARepository
}
/**
* Updates the supplied node record, inserting it into the database if
* necessary.
* Updates the supplied node record, inserting it into the database if necessary.
*/
public void updateNode (NodeRecord record)
throws PersistenceException
{
record.lastUpdated = new Timestamp(System.currentTimeMillis());
store(_ntable, record);
}
/**
* Updates {@link NodeRecord#lastUpdated} for the specified node, indicating that the node is
* alive and well.
*/
public void heartbeatNode (String nodeName)
throws PersistenceException
{
NodeRecord record = new NodeRecord();
record.nodeName = nodeName;
record.lastUpdated = new Timestamp(System.currentTimeMillis());
updateField(_ntable, record, "lastUpdated");
}
/**
* Deletes the identified node record.
*/
@@ -104,8 +117,7 @@ public class NodeRepository extends JORARepository
@Override // documentation inherited
protected void createTables ()
{
_ntable = new Table<NodeRecord>(
NodeRecord.class, "NODES", "NODE_NAME", true);
_ntable = new Table<NodeRecord>(NodeRecord.class, "NODES", "NODE_NAME", true);
}
protected Table<NodeRecord> _ntable;