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:
@@ -161,6 +161,8 @@
|
|||||||
source="1.5" target="1.5">
|
source="1.5" target="1.5">
|
||||||
<classpath refid="classpath"/>
|
<classpath refid="classpath"/>
|
||||||
<exclude name="com/threerings/parlor/rating/server/**" unless="depot.present"/>
|
<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"/>
|
||||||
<compilerarg value="-Xlint:-serial"/>
|
<compilerarg value="-Xlint:-serial"/>
|
||||||
</javac>
|
</javac>
|
||||||
|
|||||||
@@ -23,26 +23,76 @@ package com.threerings.presents.peer.server.persist;
|
|||||||
|
|
||||||
import java.sql.Timestamp;
|
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;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains information on an active node in a Presents server cluster.
|
* 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. */
|
/** The unique name assigned to this node. */
|
||||||
|
@Id
|
||||||
|
@Column(name="NODE_NAME", length=64)
|
||||||
public String nodeName;
|
public String nodeName;
|
||||||
|
|
||||||
/** The DNS name used to connect to this node by other peers. */
|
/** The DNS name used to connect to this node by other peers. */
|
||||||
|
@Column(name="HOST_NAME", length=64)
|
||||||
public String hostName;
|
public String hostName;
|
||||||
|
|
||||||
/** The DNS name used to connect to this node by normal clients. */
|
/** The DNS name used to connect to this node by normal clients. */
|
||||||
|
@Column(name="PUBLIC_HOST_NAME", length=64)
|
||||||
public String publicHostName;
|
public String publicHostName;
|
||||||
|
|
||||||
/** The port on which to connect to this node. */
|
/** The port on which to connect to this node. */
|
||||||
|
@Column(name="PORT")
|
||||||
public int port;
|
public int port;
|
||||||
|
|
||||||
/** The last time this node has reported in. */
|
/** The last time this node has reported in. */
|
||||||
|
@Column(name="LAST_UPDATED")
|
||||||
public Timestamp lastUpdated;
|
public Timestamp lastUpdated;
|
||||||
|
|
||||||
/** Used to create a blank instance when loading from the database. */
|
/** Used to create a blank instance when loading from the database. */
|
||||||
@@ -72,4 +122,18 @@ public class NodeRecord
|
|||||||
{
|
{
|
||||||
return StringUtil.fieldsToString(this);
|
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;
|
package com.threerings.presents.peer.server.persist;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
import com.samskivert.io.PersistenceException;
|
import com.samskivert.io.PersistenceException;
|
||||||
|
|
||||||
import com.samskivert.jdbc.ConnectionProvider;
|
import com.samskivert.jdbc.ConnectionProvider;
|
||||||
import com.samskivert.jdbc.DatabaseLiaison;
|
import com.samskivert.jdbc.depot.DepotRepository;
|
||||||
import com.samskivert.jdbc.JDBCUtil;
|
import com.samskivert.jdbc.depot.PersistenceContext;
|
||||||
import com.samskivert.jdbc.JORARepository;
|
|
||||||
import com.samskivert.jdbc.jora.Table;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to share information on active nodes in a Presents server cluster.
|
* 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
|
/** The database identifier used when establishing a database connection. This value being
|
||||||
* <code>nodedb</code>. */
|
* <code>nodedb</code>. */
|
||||||
@@ -51,16 +46,16 @@ public class NodeRepository extends JORARepository
|
|||||||
public NodeRepository (ConnectionProvider conprov)
|
public NodeRepository (ConnectionProvider conprov)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
super(conprov, NODE_DB_IDENT);
|
super(new PersistenceContext(NODE_DB_IDENT, conprov));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all nodes registered in the repository.
|
* Returns a list of all nodes registered in the repository.
|
||||||
*/
|
*/
|
||||||
public ArrayList<NodeRecord> loadNodes ()
|
public List<NodeRecord> loadNodes ()
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
return loadAll(_ntable, "");
|
return findAll(NodeRecord.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +65,7 @@ public class NodeRepository extends JORARepository
|
|||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
record.lastUpdated = new Timestamp(System.currentTimeMillis());
|
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)
|
public void heartbeatNode (String nodeName)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
NodeRecord record = new NodeRecord();
|
updatePartial(NodeRecord.class, nodeName, new Object[] {
|
||||||
record.nodeName = nodeName;
|
NodeRecord.LAST_UPDATED, new Timestamp(System.currentTimeMillis())
|
||||||
record.lastUpdated = new Timestamp(System.currentTimeMillis());
|
});
|
||||||
updateField(_ntable, record, "lastUpdated");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,33 +86,6 @@ public class NodeRepository extends JORARepository
|
|||||||
public void deleteNode (String nodeName)
|
public void deleteNode (String nodeName)
|
||||||
throws PersistenceException
|
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user