From 0c448bc92d888f924bc7f18b6ba73810c4f61017 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 13 Jun 2007 23:36:25 +0000 Subject: [PATCH] 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 --- .../presents/peer/server/PeerManager.java | 3 ++ .../peer/server/persist/NodeRecord.java | 3 +- .../peer/server/persist/NodeRepository.java | 28 +++++++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/java/com/threerings/presents/peer/server/PeerManager.java b/src/java/com/threerings/presents/peer/server/PeerManager.java index 6f461292c..5633ee52a 100644 --- a/src/java/com/threerings/presents/peer/server/PeerManager.java +++ b/src/java/com/threerings/presents/peer/server/PeerManager.java @@ -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) { diff --git a/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java b/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java index a38da3e14..88ed8a9bd 100644 --- a/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java +++ b/src/java/com/threerings/presents/peer/server/persist/NodeRecord.java @@ -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; diff --git a/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java b/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java index a63fc9e5a..603d46953 100644 --- a/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java +++ b/src/java/com/threerings/presents/peer/server/persist/NodeRepository.java @@ -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 nodedb. */ + /** The database identifier used when establishing a database connection. This value being + * nodedb. */ 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.class, "NODES", "NODE_NAME", true); + _ntable = new Table(NodeRecord.class, "NODES", "NODE_NAME", true); } protected Table _ntable;