[Mulgara-svn] r1165 - trunk/src/jar/resolver/java/org/mulgara/resolver
pag at mulgara.org
pag at mulgara.org
Sat Aug 23 01:58:25 UTC 2008
Author: pag
Date: 2008-08-22 18:58:24 -0700 (Fri, 22 Aug 2008)
New Revision: 1165
Modified:
trunk/src/jar/resolver/java/org/mulgara/resolver/Database.java
trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactory.java
trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactoryInitializer.java
trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseUnitTest.java
Log:
Updated Databases to handle multiple directories for storing database files. This will be important for distributing the load across multiple disks
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/Database.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/Database.java 2008-08-23 01:56:39 UTC (rev 1164)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/Database.java 2008-08-23 01:58:24 UTC (rev 1165)
@@ -113,7 +113,7 @@
private final long NONE = NodePool.NONE;
/** The directory where persistence files are stored. */
- private final File directory;
+ private final File[] directories;
/**
* Session to use for the initialization of new resolvers.
@@ -433,27 +433,123 @@
NamingException, NodePoolException, QueryException,
ResolverException, ResolverFactoryException, StringPoolException,
SystemException, URISyntaxException {
+ this(uri,
+ new File[] {directory},
+ securityDomainURI,
+ transactionManagerFactory,
+ transactionTimeout,
+ idleTimeout,
+ persistentNodePoolFactoryClassName,
+ new File[] {persistentNodePoolDirectory},
+ persistentStringPoolFactoryClassName,
+ new File[] {persistentStringPoolDirectory},
+ systemResolverFactoryClassName,
+ new File[] {persistentResolverDirectory},
+ temporaryNodePoolFactoryClassName,
+ new File[] {temporaryNodePoolDirectory},
+ temporaryStringPoolFactoryClassName,
+ new File[] {temporaryStringPoolDirectory},
+ temporaryResolverFactoryClassName,
+ new File[] {temporaryResolverDirectory},
+ ruleLoaderClassName,
+ defaultContentHandlerClassName);
+ }
+ /**
+ * Construct a database.
+ *
+ * @param uri the unique {@link URI} naming this database, never
+ * <code>null</code>; this mustn't have a fragment part, because the
+ * fragment is used to represent models within the database
+ * @param directory an area on the filesystem for the database's use; if this
+ * is <code>null</code>, resolvers which require a filesystem can't be added
+ * @param securityDomainURI the {@link URI} of the security domain this
+ * database is within, or <code>null</code> if this database is unsecured
+ * @param transactionManagerFactory the source for the
+ * {@link TransactionManager}, never <code>null</code>
+ * @param transactionTimeout the default number of seconds before transactions
+ * time out, or zero to take the <var>transactionManagerFactory</var>'s default;
+ * never negative
+ * @param idleTimeout the default number of seconds a transaction may be idle before
+ * it is timed out, or zero to take the <var>transactionManagerFactory</var>'s
+ * default; never negative
+ * @param persistentNodePoolFactoryClassName the name of a
+ * {@link NodePoolFactory} implementation which will be used to generate
+ * persistent local nodes, never <code>null</code>
+ * @param persistentStringPoolFactoryClassName the name of a
+ * {@link StringPoolFactory} implementation which will be used to manage
+ * persistent RDF literals, never <code>null</code>
+ * @param systemResolverFactoryClassName the name of a
+ * {@link ResolverFactory} implementation which will be used to store
+ * system models; this class is required to register a model type
+ * @param temporaryNodePoolFactoryClassName the name of a
+ * {@link NodePoolFactory} implementation which will be used to generate
+ * temporary local nodes, never <code>null</code>
+ * @param temporaryStringPoolFactoryClassName the name of a
+ * {@link StringPoolFactory} implementation which will be used to manage
+ * temporary RDF literals, never <code>null</code>
+ * @param temporaryResolverFactoryClassName the name of a
+ * {@link ResolverFactory} implementation which will be used to store
+ * temporary statements, never <code>null</code>
+ * @param ruleLoaderClassName the name of a
+ * {@link RuleLoader} implementation which will be used for loading
+ * rule frameworks, never <code>null</code>
+ * @param defaultContentHandlerClassName the name of the class that should be
+ * used to parse external content of unknown MIME type, or
+ * <code>null</code> to disable blind parsing
+ * @throws IllegalArgumentException if <var>uri</var>,
+ * <var>systemResolverFactory</var> are <code>null</code>, or if the
+ * <var>uri</var> has a fragment part
+ * @throws InitializerException if the {@link NodePoolFactory},
+ * {@link ResolverFactory}, or {@link StringPoolFactory} instances
+ * generated from the various class names can't be initialized
+ * @throws SystemException if <var>transactionTimeout</var> is negative
+ */
+ public Database(URI uri,
+ File[] directories,
+ URI securityDomainURI,
+ TransactionManagerFactory transactionManagerFactory,
+ int transactionTimeout,
+ int idleTimeout,
+ String persistentNodePoolFactoryClassName,
+ File[] persistentNodePoolDirectories,
+ String persistentStringPoolFactoryClassName,
+ File[] persistentStringPoolDirectories,
+ String systemResolverFactoryClassName,
+ File[] persistentResolverDirectories,
+ String temporaryNodePoolFactoryClassName,
+ File[] temporaryNodePoolDirectories,
+ String temporaryStringPoolFactoryClassName,
+ File[] temporaryStringPoolDirectories,
+ String temporaryResolverFactoryClassName,
+ File[] temporaryResolverDirectories,
+ String ruleLoaderClassName,
+ String defaultContentHandlerClassName)
+ throws ConfigurationException, InitializerException, LocalizeException,
+ NamingException, NodePoolException, QueryException,
+ ResolverException, ResolverFactoryException, StringPoolException,
+ SystemException, URISyntaxException {
+
if (logger.isDebugEnabled()) {
logger.debug("Constructing database");
logger.debug("Persistent node pool factory: class=" +
persistentNodePoolFactoryClassName + " directory=" +
- persistentNodePoolDirectory);
+ persistentNodePoolDirectories);
logger.debug("Persistent string pool factory: class=" +
persistentStringPoolFactoryClassName + " directory=" +
- persistentStringPoolDirectory);
+ persistentStringPoolDirectories);
logger.debug("Persistent resolver factory: class=" +
systemResolverFactoryClassName + " directory=" +
- persistentResolverDirectory);
+ persistentResolverDirectories);
logger.debug("Temporary node pool factory: class=" +
temporaryNodePoolFactoryClassName + " directory=" +
- temporaryNodePoolDirectory);
+ temporaryNodePoolDirectories);
logger.debug("Temporary string pool factory: class=" +
temporaryStringPoolFactoryClassName + " directory=" +
- temporaryStringPoolDirectory);
+ temporaryStringPoolDirectories);
logger.debug("Temporary resolver factory: class=" +
temporaryResolverFactoryClassName + " directory=" +
- temporaryResolverDirectory);
+ temporaryResolverDirectories);
logger.debug("Rule loader: class=" +
ruleLoaderClassName);
}
@@ -492,7 +588,7 @@
// Initialize fields
this.uri = uri;
- this.directory = directory;
+ this.directories = directories;
this.securityDomainURI = securityDomainURI;
this.transactionManagerFactory = transactionManagerFactory;
@@ -563,22 +659,22 @@
DatabaseFactoryInitializer persistentStringPoolFactoryInitializer =
new DatabaseFactoryInitializer(uri,
hostnameAliases,
- persistentStringPoolDirectory);
+ persistentStringPoolDirectories);
DatabaseFactoryInitializer persistentNodePoolFactoryInitializer =
new DatabaseFactoryInitializer(uri,
hostnameAliases,
- persistentNodePoolDirectory);
+ persistentNodePoolDirectories);
DatabaseFactoryInitializer temporaryStringPoolFactoryInitializer =
new DatabaseFactoryInitializer(uri,
hostnameAliases,
- temporaryStringPoolDirectory);
+ temporaryStringPoolDirectories);
DatabaseFactoryInitializer temporaryNodePoolFactoryInitializer =
new DatabaseFactoryInitializer(uri,
hostnameAliases,
- temporaryNodePoolDirectory);
+ temporaryNodePoolDirectories);
spSessionFactory = new StringPoolSessionFactory(
uri,
@@ -600,7 +696,7 @@
temporaryNodePoolFactoryInitializer.close();
DatabaseFactoryInitializer initializer =
- new DatabaseFactoryInitializer(uri, hostnameAliases, directory);
+ new DatabaseFactoryInitializer(uri, hostnameAliases, directories);
jrdfSessionFactory = new JRDFResolverSessionFactory(initializer, spSessionFactory);
@@ -609,7 +705,7 @@
// Create the temporary resolver factory
initializer = new DatabaseFactoryInitializer(
- uri, hostnameAliases, temporaryResolverDirectory
+ uri, hostnameAliases, temporaryResolverDirectories
);
temporaryResolverFactory = ResolverFactoryFactory.newSystemResolverFactory(
temporaryResolverFactoryClassName, initializer, spSessionFactory
@@ -645,7 +741,7 @@
// Create the system resolver factory
initializer = new DatabaseFactoryInitializer(
- uri, hostnameAliases, persistentResolverDirectory
+ uri, hostnameAliases, persistentResolverDirectories
);
systemResolverFactory = ResolverFactoryFactory.newSystemResolverFactory(
systemResolverFactoryClassName, initializer, spSessionFactory
@@ -1029,10 +1125,15 @@
File getRootDirectory() {
- return directory;
+ return (directories != null && directories.length >= 1) ? directories[0] : null;
}
+ File[] getRootDirectories() {
+ return directories;
+ }
+
+
private void recoverDatabase(SimpleXARecoveryHandler[] handlers) throws SimpleXAResourceException {
assert handlers != null;
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactory.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactory.java 2008-08-23 01:56:39 UTC (rev 1164)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactory.java 2008-08-23 01:58:24 UTC (rev 1165)
@@ -96,23 +96,23 @@
Database database = new Database(
uri, // database name
- directory, // persistence directory
+ new File[] {directory}, // persistence directory
uri, // security domain
new JotmTransactionManagerFactory(),
config.getTransactionTimeout(),
config.getIdleTimeout(),
config.getPersistentNodePoolFactory().getType(),
- subdir(directory, config.getPersistentNodePoolFactory().getDir()),
+ subdirs(directory, config.getPersistentNodePoolFactory().getDir()),
config.getPersistentStringPoolFactory().getType(),
- subdir(directory, config.getPersistentStringPoolFactory().getDir()),
+ subdirs(directory, config.getPersistentStringPoolFactory().getDir()),
config.getPersistentResolverFactory().getType(),
- subdir(directory, config.getPersistentResolverFactory().getDir()),
+ subdirs(directory, config.getPersistentResolverFactory().getDir()),
config.getTemporaryNodePoolFactory().getType(),
- subdir(directory, config.getTemporaryNodePoolFactory().getDir()),
+ subdirs(directory, config.getTemporaryNodePoolFactory().getDir()),
config.getTemporaryStringPoolFactory().getType(),
- subdir(directory, config.getTemporaryStringPoolFactory().getDir()),
+ subdirs(directory, config.getTemporaryStringPoolFactory().getDir()),
config.getTemporaryResolverFactory().getType(),
- subdir(directory, config.getTemporaryResolverFactory().getDir()),
+ subdirs(directory, config.getTemporaryResolverFactory().getDir()),
config.getRuleLoader().getType(),
config.getDefaultContentHandler().getType());
@@ -126,12 +126,25 @@
}
+ static File[] subdirs(File parentDirectory, String childDirectory) throws ConfigurationException {
+ if (childDirectory == null) return null;
+ if (parentDirectory == null) {
+ throw new ConfigurationException("Can't configure directory " + childDirectory + "because there is no PersistencePath configured");
+ }
+ String[] children = childDirectory.split(File.pathSeparator);
+ File[] subdirs = new File[children.length];
+ for (int f = 0; f < children.length; f++) subdirs[f] = subdir(parentDirectory, children[f]);
+ return subdirs;
+ }
+
+
/**
* @param parentDirectory the absolute parent directory; this may be
- * <code>null</code> if <var>childDirectory</var> is also <code>null</code>
- * @param childDirectory the relative child directory
+ * <code>null</code> if <var>childDirectory</var> is also <code>null</code>.
+ * Ignored if the child directory is absolute.
+ * @param childDirectory If relative, then relative to the parentDirectory, otherwise absolute.
* @return if <var>childDirectory</var> is non-<code>null</code> then the
- * corresponding subdirectory, otherwise <code>null</code>
+ * corresponding directory, otherwise <code>null</code>
* @throws ConfigurationException if <var>childDirectory</var> is not
* <code>null</code> and <var>parentDirectory</var> is <code>null</code>
*/
@@ -142,6 +155,7 @@
if (parentDirectory == null) {
throw new ConfigurationException("Can't configure directory " + childDirectory + "because there is no PersistencePath configured");
}
+ if (childDirectory.startsWith("/")) return new File(childDirectory);
return new File(parentDirectory, childDirectory);
}
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactoryInitializer.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactoryInitializer.java 2008-08-23 01:56:39 UTC (rev 1164)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseFactoryInitializer.java 2008-08-23 01:58:24 UTC (rev 1165)
@@ -57,7 +57,7 @@
private static final Logger logger = Logger.getLogger(DatabaseFactoryInitializer.class.getName());
/** The databases toplevel directory */
- private File directory;
+ private File[] directories;
/** The unique {@link URI} naming this database. */
private final URI databaseURI;
@@ -66,7 +66,7 @@
private final Set<String> hostnameAliases;
/**
- * Sole constructor.
+ * Constructor based on individual directory startup.
*
* @param directory the persistence directory to offer this component; if
* <code>null</code>, no persistence directory will be offered
@@ -74,9 +74,21 @@
DatabaseFactoryInitializer(URI databaseURI, Set<String> hostnameAliases, File directory) {
this.databaseURI = databaseURI;
this.hostnameAliases = hostnameAliases;
- this.directory = directory;
+ this.directories = new File[] { directory };
}
+ /**
+ * Constructor based on staartup directory list.
+ *
+ * @param directories The persistence directories to offer this component; if
+ * <code>null</code>, no persistence directories will be offered
+ */
+ DatabaseFactoryInitializer(URI databaseURI, Set<String> hostnameAliases, File[] directories) {
+ this.databaseURI = databaseURI;
+ this.hostnameAliases = hostnameAliases;
+ this.directories = directories;
+ }
+
//
// Methods implementing FactoryInitializer
//
@@ -91,10 +103,13 @@
return hostnameAliases;
}
- public File getDirectory() throws InitializerException
- {
+ public File getDirectory() throws InitializerException {
checkState();
+ File directory = null;
+
+ if (directories != null && directories.length > 0) directory = directories[0];
+
if (directory != null) {
// Ensure that the directory exists
if (!directory.isDirectory()) {
@@ -105,4 +120,19 @@
return directory;
}
+
+ public File[] getDirectories() throws InitializerException {
+ checkState();
+
+ for (File directory: directories) {
+ if (directory == null) throw new InitializerException("Null directory entry in initializing list.");
+ // Ensure that the directory exists
+ if (!directory.isDirectory()) {
+ if (!directory.mkdirs()) throw new InitializerException("Couldn't create " + directory);
+ }
+ assert directory.isDirectory();
+ }
+
+ return directories;
+ }
}
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseUnitTest.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseUnitTest.java 2008-08-23 01:56:39 UTC (rev 1164)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseUnitTest.java 2008-08-23 01:58:24 UTC (rev 1165)
@@ -102,7 +102,7 @@
*/
public void test1Constructor() {
try {
- new Database(null, null, null, null, 0, 0, null, null, null, null, null,
+ new Database(null, (File)null, null, null, 0, 0, null, null, null, null, null,
null, null, null, null, null, null, null, null, null);
fail("Expected " + IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
More information about the Mulgara-svn
mailing list