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:
@@ -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
|
||||||
@@ -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
|
# Configuration for the Whirled server
|
||||||
|
|
||||||
|
#
|
||||||
# These invocation service providers will be registered with the
|
# These invocation service providers will be registered with the
|
||||||
# invocation manager during the server init process
|
# invocation manager during the server init process.
|
||||||
|
#
|
||||||
providers = \
|
providers = \
|
||||||
whirled!scene = com.threerings.whirled.server.SceneProvider
|
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;
|
package com.threerings.whirled.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.cocktail.party.server.PartyServer;
|
||||||
|
|
||||||
import com.threerings.whirled.Log;
|
import com.threerings.whirled.Log;
|
||||||
@@ -20,6 +24,9 @@ public class WhirledServer extends PartyServer
|
|||||||
/** The namespace used for server config properties. */
|
/** The namespace used for server config properties. */
|
||||||
public static final String CONFIG_KEY = "whirled";
|
public static final String CONFIG_KEY = "whirled";
|
||||||
|
|
||||||
|
/** The database connection provider in use by this server. */
|
||||||
|
public static ConnectionProvider conprov;
|
||||||
|
|
||||||
/** The scene registry. */
|
/** The scene registry. */
|
||||||
public static SceneRegistry screg;
|
public static SceneRegistry screg;
|
||||||
|
|
||||||
@@ -35,19 +42,14 @@ public class WhirledServer extends PartyServer
|
|||||||
// bind the whirled server config into the namespace
|
// bind the whirled server config into the namespace
|
||||||
config.bindProperties(CONFIG_KEY, CONFIG_PATH, true);
|
config.bindProperties(CONFIG_KEY, CONFIG_PATH, true);
|
||||||
|
|
||||||
// instantiate the scene repository
|
// create our connection provider
|
||||||
SceneRepository screp = null;
|
conprov = createConnectionProvider(config);
|
||||||
try {
|
|
||||||
screp = (SceneRepository)config.instantiateValue(
|
// create the scene repository
|
||||||
SCENEREP_KEY, DEF_SCENEREP);
|
_screp = createSceneRepository(conprov);
|
||||||
} catch (Exception e) {
|
|
||||||
Log.warning("Unable to instantiate scene repository " +
|
|
||||||
"[error=" + e + "].");
|
|
||||||
throw new IOException("Fatal init failure");
|
|
||||||
}
|
|
||||||
|
|
||||||
// create our scene registry
|
// create our scene registry
|
||||||
screg = new SceneRegistry(screp);
|
screg = new SceneRegistry(_screp);
|
||||||
|
|
||||||
// register our invocation service providers
|
// register our invocation service providers
|
||||||
registerProviders(config.getValue(PROVIDERS_KEY, (String[])null));
|
registerProviders(config.getValue(PROVIDERS_KEY, (String[])null));
|
||||||
@@ -55,6 +57,40 @@ public class WhirledServer extends PartyServer
|
|||||||
Log.info("Whirled server initialized.");
|
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)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
WhirledServer server = new WhirledServer();
|
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
|
// the path to the config file
|
||||||
protected final static String CONFIG_PATH =
|
protected final static String CONFIG_PATH =
|
||||||
"rsrc/config/whirled/server";
|
"rsrc/config/whirled/server";
|
||||||
@@ -74,8 +113,8 @@ public class WhirledServer extends PartyServer
|
|||||||
// the config key for our list of invocation provider mappings
|
// the config key for our list of invocation provider mappings
|
||||||
protected final static String PROVIDERS_KEY = CONFIG_KEY + ".providers";
|
protected final static String PROVIDERS_KEY = CONFIG_KEY + ".providers";
|
||||||
|
|
||||||
// scene repository related configuration info
|
// connection provider related configuration info
|
||||||
protected final static String SCENEREP_KEY = CONFIG_KEY + ".scene_rep";
|
protected final static String DBMAP_KEY = CONFIG_KEY + ".dbmap";
|
||||||
protected final static String DEF_SCENEREP =
|
protected final static String DEF_DBMAP =
|
||||||
DummySceneRepository.class.getName();
|
"rsrc/config/whirled/dbmap";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user