Let's switch the peristent peer stuff over to a schema-comaptible Depot implementation. I think only Bang uses presents.peer and crowd.peer -- apart from Whirled -- and Bang already uses Depot.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4772 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Par Winzell
2007-07-18 18:08:11 +00:00
parent 7cf24684a7
commit 30a8179c5f
3 changed files with 79 additions and 46 deletions
+2
View File
@@ -161,6 +161,8 @@
source="1.5" target="1.5">
<classpath refid="classpath"/>
<exclude name="com/threerings/parlor/rating/server/**" unless="depot.present"/>
<exclude name="com/threerings/presents/peer/**" unless="depot.present"/>
<exclude name="com/threerings/crowd/peer/**" unless="depot.present"/>
<compilerarg value="-Xlint"/>
<compilerarg value="-Xlint:-serial"/>
</javac>
@@ -23,26 +23,76 @@ package com.threerings.presents.peer.server.persist;
import java.sql.Timestamp;
import com.samskivert.jdbc.depot.Key;
import com.samskivert.jdbc.depot.PersistentRecord;
import com.samskivert.jdbc.depot.annotation.Column;
import com.samskivert.jdbc.depot.annotation.Entity;
import com.samskivert.jdbc.depot.annotation.Id;
import com.samskivert.jdbc.depot.expression.ColumnExp;
import com.samskivert.util.StringUtil;
/**
* Contains information on an active node in a Presents server cluster.
*/
public class NodeRecord
@Entity
public class NodeRecord extends PersistentRecord
{
// AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #nodeName} field. */
public static final String NODE_NAME = "nodeName";
/** The qualified column identifier for the {@link #nodeName} field. */
public static final ColumnExp NODE_NAME_C =
new ColumnExp(NodeRecord.class, NODE_NAME);
/** The column identifier for the {@link #hostName} field. */
public static final String HOST_NAME = "hostName";
/** The qualified column identifier for the {@link #hostName} field. */
public static final ColumnExp HOST_NAME_C =
new ColumnExp(NodeRecord.class, HOST_NAME);
/** The column identifier for the {@link #publicHostName} field. */
public static final String PUBLIC_HOST_NAME = "publicHostName";
/** The qualified column identifier for the {@link #publicHostName} field. */
public static final ColumnExp PUBLIC_HOST_NAME_C =
new ColumnExp(NodeRecord.class, PUBLIC_HOST_NAME);
/** The column identifier for the {@link #port} field. */
public static final String PORT = "port";
/** The qualified column identifier for the {@link #port} field. */
public static final ColumnExp PORT_C =
new ColumnExp(NodeRecord.class, PORT);
/** The column identifier for the {@link #lastUpdated} field. */
public static final String LAST_UPDATED = "lastUpdated";
/** The qualified column identifier for the {@link #lastUpdated} field. */
public static final ColumnExp LAST_UPDATED_C =
new ColumnExp(NodeRecord.class, LAST_UPDATED);
// AUTO-GENERATED: FIELDS END
/** The unique name assigned to this node. */
@Id
@Column(name="NODE_NAME", length=64)
public String nodeName;
/** The DNS name used to connect to this node by other peers. */
@Column(name="HOST_NAME", length=64)
public String hostName;
/** The DNS name used to connect to this node by normal clients. */
@Column(name="PUBLIC_HOST_NAME", length=64)
public String publicHostName;
/** The port on which to connect to this node. */
@Column(name="PORT")
public int port;
/** The last time this node has reported in. */
@Column(name="LAST_UPDATED")
public Timestamp lastUpdated;
/** Used to create a blank instance when loading from the database. */
@@ -72,4 +122,18 @@ public class NodeRecord
{
return StringUtil.fieldsToString(this);
}
// AUTO-GENERATED: METHODS START
/**
* Create and return a primary {@link Key} to identify a {@link #NodeRecord}
* with the supplied key values.
*/
public static Key<NodeRecord> getKey (String nodeName)
{
return new Key<NodeRecord>(
NodeRecord.class,
new String[] { NODE_NAME },
new Comparable[] { nodeName });
}
// AUTO-GENERATED: METHODS END
}
@@ -21,23 +21,18 @@
package com.threerings.presents.peer.server.persist;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider;
import com.samskivert.jdbc.DatabaseLiaison;
import com.samskivert.jdbc.JDBCUtil;
import com.samskivert.jdbc.JORARepository;
import com.samskivert.jdbc.jora.Table;
import com.samskivert.jdbc.depot.DepotRepository;
import com.samskivert.jdbc.depot.PersistenceContext;
/**
* Used to share information on active nodes in a Presents server cluster.
*/
public class NodeRepository extends JORARepository
public class NodeRepository extends DepotRepository
{
/** The database identifier used when establishing a database connection. This value being
* <code>nodedb</code>. */
@@ -51,16 +46,16 @@ public class NodeRepository extends JORARepository
public NodeRepository (ConnectionProvider conprov)
throws PersistenceException
{
super(conprov, NODE_DB_IDENT);
super(new PersistenceContext(NODE_DB_IDENT, conprov));
}
/**
* Returns a list of all nodes registered in the repository.
*/
public ArrayList<NodeRecord> loadNodes ()
public List<NodeRecord> loadNodes ()
throws PersistenceException
{
return loadAll(_ntable, "");
return findAll(NodeRecord.class);
}
/**
@@ -70,7 +65,7 @@ public class NodeRepository extends JORARepository
throws PersistenceException
{
record.lastUpdated = new Timestamp(System.currentTimeMillis());
store(_ntable, record);
store(record);
}
/**
@@ -80,10 +75,9 @@ public class NodeRepository extends JORARepository
public void heartbeatNode (String nodeName)
throws PersistenceException
{
NodeRecord record = new NodeRecord();
record.nodeName = nodeName;
record.lastUpdated = new Timestamp(System.currentTimeMillis());
updateField(_ntable, record, "lastUpdated");
updatePartial(NodeRecord.class, nodeName, new Object[] {
NodeRecord.LAST_UPDATED, new Timestamp(System.currentTimeMillis())
});
}
/**
@@ -92,33 +86,6 @@ public class NodeRepository extends JORARepository
public void deleteNode (String nodeName)
throws PersistenceException
{
delete(_ntable, new NodeRecord(nodeName));
delete(NodeRecord.class, nodeName);
}
@Override // documentation inherited
protected void migrateSchema (Connection conn, DatabaseLiaison liaison)
throws SQLException, PersistenceException
{
JDBCUtil.createTableIfMissing(conn, "NODES", new String[] {
"NODE_NAME VARCHAR(64) NOT NULL",
"HOST_NAME VARCHAR(64) NOT NULL",
"PUBLIC_HOST_NAME VARCHAR(64) NOT NULL",
"PORT INTEGER NOT NULL",
"LAST_UPDATED TIMESTAMP NOT NULL",
"PRIMARY KEY (NODE_NAME)",
}, "");
// TEMP: add our new column
JDBCUtil.addColumn(conn, "NODES", "PUBLIC_HOST_NAME",
"VARCHAR(64) NOT NULL", "HOST_NAME");
// END TEMP
}
@Override // documentation inherited
protected void createTables ()
{
_ntable = new Table<NodeRecord>(NodeRecord.class, "NODES", "NODE_NAME", true);
}
protected Table<NodeRecord> _ntable;
}