Screw backwards compatibility. We're all about the future.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4786 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-07-26 20:49:13 +00:00
parent 81044c6512
commit 7a8bb7389a
5 changed files with 32 additions and 72 deletions
@@ -24,7 +24,7 @@ package com.threerings.admin.server;
import java.util.HashMap; import java.util.HashMap;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider; import com.samskivert.jdbc.depot.PersistenceContext;
import com.samskivert.util.Invoker; import com.samskivert.util.Invoker;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
@@ -34,43 +34,40 @@ import com.threerings.admin.Log;
import com.threerings.admin.server.persist.ConfigRepository; import com.threerings.admin.server.persist.ConfigRepository;
/** /**
* Implements the {@link ConfigRegistry} using a JDBC database as a persistent * Implements the {@link ConfigRegistry} using a JDBC database as a persistent store for the
* store for the configuration information. <em>Note:</em> config objects * configuration information. <em>Note:</em> config objects should only be created during server
* should only be created during server startup because they will result in * startup because they will result in synchronous requests to load up the initial configuration
* synchronous requests to load up the initial configuration data from the * data from the database. This ensures that systems initialized after the config registry can
* database. This ensures that systems initialized after the config registry * safely make use of configuration information.
* can safely make use of configuration information.
*/ */
public class DatabaseConfigRegistry extends ConfigRegistry public class DatabaseConfigRegistry extends ConfigRegistry
{ {
/** /**
* Creates a configuration registry and prepares it for operation. * Creates a configuration registry and prepares it for operation.
* *
* @param conprov will provide access to our JDBC database. * @param ctx will provide access to our database.
* @param invoker this will be used to perform all database activity * @param invoker this will be used to perform all database activity (except first time
* (except first time initialization) so as to avoid blocking the * initialization) so as to avoid blocking the distributed object thread.
* distributed object thread.
*/ */
public DatabaseConfigRegistry (ConnectionProvider conprov, Invoker invoker) public DatabaseConfigRegistry (PersistenceContext ctx, Invoker invoker)
throws PersistenceException throws PersistenceException
{ {
this(conprov, invoker, ""); this(ctx, invoker, "");
} }
/** /**
* Creates a configuration registry and prepares it for operation. * Creates a configuration registry and prepares it for operation.
* *
* @param conprov will provide access to our JDBC database. * @param ctx will provide access to our database.
* @param invoker this will be used to perform all database activity * @param invoker this will be used to perform all database activity (except first time
* (except first time initialization) so as to avoid blocking the * initialization) so as to avoid blocking the distributed object thread.
* distributed object thread. * @param node if this config registry is accessed by multiple servers which wish to maintain
* @param node if this config registry is accessed by multiple servers which * seperate configs, then specificy a node for each server
* wish to maintain seperate configs, then specificy a node for each server
*/ */
public DatabaseConfigRegistry (ConnectionProvider conprov, Invoker invoker, String node) public DatabaseConfigRegistry (PersistenceContext ctx, Invoker invoker, String node)
throws PersistenceException throws PersistenceException
{ {
_repo = new ConfigRepository(conprov); _repo = new ConfigRepository(ctx);
_invoker = invoker; _invoker = invoker;
_node = StringUtil.isBlank(node) ? "" : node; _node = StringUtil.isBlank(node) ? "" : node;
} }
@@ -91,17 +88,14 @@ public class DatabaseConfigRegistry extends ConfigRegistry
public void init () public void init ()
{ {
// load up our persistent data synchronously because we should be // load up our persistent data synchronously because we should be in the middle of
// in the middle of server startup when it's OK to do database // server startup when it's OK to do database access on the main thread and we need to
// access on the main thread and we need to be completely // be completely initialized when we return from this call so that subsequent systems
// initialized when we return from this call so that subsequent // can predictably make use of the configuration information that we load
// systems can predictably make use of the configuration
// information that we load
try { try {
_data = _repo.loadConfig(_node, _path); _data = _repo.loadConfig(_node, _path);
} catch (PersistenceException pe) { } catch (PersistenceException pe) {
Log.warning("Failed to load object configuration " + Log.warning("Failed to load object configuration [path=" + _path + "].");
"[path=" + _path + "].");
Log.logStackTrace(pe); Log.logStackTrace(pe);
_data = new HashMap<String,String>(); _data = new HashMap<String,String>();
} }
@@ -265,9 +259,8 @@ public class DatabaseConfigRegistry extends ConfigRegistry
try { try {
_repo.updateConfig(_node, _path, field, value); _repo.updateConfig(_node, _path, field, value);
} catch (PersistenceException pe) { } catch (PersistenceException pe) {
Log.warning("Failed to update object configuration " + Log.warning("Failed to update object configuration [path=" + _path +
"[path=" + _path + ", field=" + field + ", field=" + field + ", value=" + value + "].");
", value=" + value + "].");
Log.logStackTrace(pe); Log.logStackTrace(pe);
} }
return false; return false;
@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.Set; import java.util.Set;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider;
import com.samskivert.jdbc.depot.DepotRepository; import com.samskivert.jdbc.depot.DepotRepository;
import com.samskivert.jdbc.depot.PersistenceContext; import com.samskivert.jdbc.depot.PersistenceContext;
import com.samskivert.jdbc.depot.PersistentRecord; import com.samskivert.jdbc.depot.PersistentRecord;
@@ -36,18 +35,6 @@ import com.samskivert.jdbc.depot.clause.Where;
*/ */
public class ConfigRepository extends DepotRepository public class ConfigRepository extends DepotRepository
{ {
/** The identifier used when establishing a database connection. */
public static final String CONFIG_DB_IDENT = "configdb";
/**
* Constructs a new config repository with the specified connection provider.
*/
public ConfigRepository (ConnectionProvider conprov)
throws PersistenceException
{
this(new PersistenceContext(CONFIG_DB_IDENT, conprov));
}
/** /**
* Constructs a new config repository with the specified persistence context. * Constructs a new config repository with the specified persistence context.
*/ */
@@ -59,8 +46,7 @@ public class ConfigRepository extends DepotRepository
/** /**
* Loads up the configuration data for the specified object. * Loads up the configuration data for the specified object.
* *
* @return a map containing field/value pairs for all stored configuration * @return a map containing field/value pairs for all stored configuration data.
* data.
*/ */
public HashMap<String,String> loadConfig (String node, String object) public HashMap<String,String> loadConfig (String node, String object)
throws PersistenceException throws PersistenceException
@@ -21,8 +21,7 @@
package com.threerings.crowd.peer.server; package com.threerings.crowd.peer.server;
import com.samskivert.io.PersistenceException; import com.samskivert.jdbc.depot.PersistenceContext;
import com.samskivert.jdbc.ConnectionProvider;
import com.samskivert.util.Invoker; import com.samskivert.util.Invoker;
import com.threerings.util.Name; import com.threerings.util.Name;
@@ -57,10 +56,9 @@ public class CrowdPeerManager extends PeerManager
* Creates a peer manager that integrates Crowd services across a cluster * Creates a peer manager that integrates Crowd services across a cluster
* of servers. * of servers.
*/ */
public CrowdPeerManager (ConnectionProvider conprov, Invoker invoker) public CrowdPeerManager (PersistenceContext ctx, Invoker invoker)
throws PersistenceException
{ {
super(conprov, invoker); super(ctx, invoker);
} }
// documentation inherited from interface CrowdPeerProvider // documentation inherited from interface CrowdPeerProvider
@@ -28,7 +28,7 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider; import com.samskivert.jdbc.depot.PersistenceContext;
import com.samskivert.util.ArrayIntSet; import com.samskivert.util.ArrayIntSet;
import com.samskivert.util.ChainedResultListener; import com.samskivert.util.ChainedResultListener;
import com.samskivert.util.Interval; import com.samskivert.util.Interval;
@@ -132,11 +132,10 @@ public class PeerManager
* Creates a peer manager which will create a {@link NodeRepository} which will be used to * Creates a peer manager which will create a {@link NodeRepository} which will be used to
* publish our existence and discover the other nodes. * publish our existence and discover the other nodes.
*/ */
public PeerManager (ConnectionProvider conprov, Invoker invoker) public PeerManager (PersistenceContext ctx, Invoker invoker)
throws PersistenceException
{ {
_invoker = invoker; _invoker = invoker;
_noderepo = new NodeRepository(conprov); _noderepo = new NodeRepository(ctx);
} }
/** /**
@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import com.samskivert.io.PersistenceException; import com.samskivert.io.PersistenceException;
import com.samskivert.jdbc.ConnectionProvider;
import com.samskivert.jdbc.depot.DepotRepository; import com.samskivert.jdbc.depot.DepotRepository;
import com.samskivert.jdbc.depot.PersistenceContext; import com.samskivert.jdbc.depot.PersistenceContext;
import com.samskivert.jdbc.depot.PersistentRecord; import com.samskivert.jdbc.depot.PersistentRecord;
@@ -36,21 +35,6 @@ import com.samskivert.jdbc.depot.PersistentRecord;
*/ */
public class NodeRepository extends DepotRepository public class NodeRepository extends DepotRepository
{ {
/** 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.
*/
public NodeRepository (ConnectionProvider conprov)
throws PersistenceException
{
this(new PersistenceContext(NODE_DB_IDENT, conprov));
}
/** /**
* Constructs a new repository with the specified persistence context. * Constructs a new repository with the specified persistence context.
*/ */