Added code to create a connection provider and use that when creating the

scene repository. Also added example config for the static connection
provider that's used by default.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@359 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-09-28 22:23:48 +00:00
parent c7dfb31972
commit c847e468e5
3 changed files with 79 additions and 18 deletions
+13
View File
@@ -0,0 +1,13 @@
#
# $Id: dbmap.properties,v 1.1 2001/09/28 22:23:48 mdb Exp $
#
# Database map for the Whirled server. This provides information on the
# JDBC connections that are used by Whirled server services.
#
# A sample database mapping for a database identified as "scenedb".
#
scenedb.driver = org.gjt.mm.mysql.Driver
scenedb.url = jdbc:mysql://DBHOSTNAME:3306/DBNAME
scenedb.username = MYUSERNAME
scenedb.password = MYPASSWORD
+11 -2
View File
@@ -1,9 +1,18 @@
#
# $Id: server.properties,v 1.1 2001/08/14 06:51:07 mdb Exp $
# $Id: server.properties,v 1.2 2001/09/28 22:23:48 mdb Exp $
#
# Configuration for the Whirled server
#
# These invocation service providers will be registered with the
# invocation manager during the server init process
# invocation manager during the server init process.
#
providers = \
whirled!scene = com.threerings.whirled.server.SceneProvider
#
# This specifies the path (in the classpath) to a properties file which
# configures the StaticConnectionProvider that is used to provide database
# connections to the Whirled server.
#
dbmap = rsrc/config/whirled/dbmap.properties
@@ -1,10 +1,14 @@
//
// $Id: WhirledServer.java,v 1.2 2001/08/14 06:51:07 mdb Exp $
// $Id: WhirledServer.java,v 1.3 2001/09/28 22:23:48 mdb Exp $
package com.threerings.whirled.server;
import java.io.IOException;
import com.samskivert.jdbc.ConnectionProvider;
import com.samskivert.jdbc.StaticConnectionProvider;
import com.samskivert.util.Config;
import com.threerings.cocktail.party.server.PartyServer;
import com.threerings.whirled.Log;
@@ -20,6 +24,9 @@ public class WhirledServer extends PartyServer
/** The namespace used for server config properties. */
public static final String CONFIG_KEY = "whirled";
/** The database connection provider in use by this server. */
public static ConnectionProvider conprov;
/** The scene registry. */
public static SceneRegistry screg;
@@ -35,19 +42,14 @@ public class WhirledServer extends PartyServer
// bind the whirled server config into the namespace
config.bindProperties(CONFIG_KEY, CONFIG_PATH, true);
// instantiate the scene repository
SceneRepository screp = null;
try {
screp = (SceneRepository)config.instantiateValue(
SCENEREP_KEY, DEF_SCENEREP);
} catch (Exception e) {
Log.warning("Unable to instantiate scene repository " +
"[error=" + e + "].");
throw new IOException("Fatal init failure");
}
// create our connection provider
conprov = createConnectionProvider(config);
// create the scene repository
_screp = createSceneRepository(conprov);
// create our scene registry
screg = new SceneRegistry(screp);
screg = new SceneRegistry(_screp);
// register our invocation service providers
registerProviders(config.getValue(PROVIDERS_KEY, (String[])null));
@@ -55,6 +57,40 @@ public class WhirledServer extends PartyServer
Log.info("Whirled server initialized.");
}
/**
* Creates the connection provider that will be used by this server.
* If a derived class wishes to use a particular kind of connection
* provider, it can override this method. The default mechanism is to
* load a properties file referenced by <code>dbmap</code> in the
* whirled server configuration and use those properties to create a
* {@link com.samskivert.jdbc.StaticConnectionProvider}.
*
* @exception IOException thrown if an error occurs creating the
* connection provider.
*/
protected ConnectionProvider createConnectionProvider (Config config)
throws IOException
{
String dbmap = config.getValue(DBMAP_KEY, DEF_DBMAP);
return new StaticConnectionProvider(dbmap);
}
/**
* Creates the scene repository that will be used by this server. If a
* derived class wishes to use a particular kind of scene repository
* (which they most likely will), they should override this method and
* instantiate the scene repository of their choosing.
*
* @exception IOException thrown if any error occurs while
* instantiating or initializing the scene repository.
*/
protected SceneRepository createSceneRepository (
ConnectionProvider conprov)
throws IOException
{
return new DummySceneRepository();
}
public static void main (String[] args)
{
WhirledServer server = new WhirledServer();
@@ -67,6 +103,9 @@ public class WhirledServer extends PartyServer
}
}
/** The scene repository in use by this server. */
protected SceneRepository _screp;
// the path to the config file
protected final static String CONFIG_PATH =
"rsrc/config/whirled/server";
@@ -74,8 +113,8 @@ public class WhirledServer extends PartyServer
// the config key for our list of invocation provider mappings
protected final static String PROVIDERS_KEY = CONFIG_KEY + ".providers";
// scene repository related configuration info
protected final static String SCENEREP_KEY = CONFIG_KEY + ".scene_rep";
protected final static String DEF_SCENEREP =
DummySceneRepository.class.getName();
// connection provider related configuration info
protected final static String DBMAP_KEY = CONFIG_KEY + ".dbmap";
protected final static String DEF_DBMAP =
"rsrc/config/whirled/dbmap";
}