[Mulgara-svn] r1964 - trunk/src/jar/util/java/org/mulgara/util/io
pag at mulgara.org
pag at mulgara.org
Sat Jul 3 02:14:25 UTC 2010
Author: pag
Date: 2010-07-03 02:14:25 +0000 (Sat, 03 Jul 2010)
New Revision: 1964
Modified:
trunk/src/jar/util/java/org/mulgara/util/io/LBufferedFile.java
Log:
Add a factory method that detects the system settings to determine the file access mode
Modified: trunk/src/jar/util/java/org/mulgara/util/io/LBufferedFile.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/io/LBufferedFile.java 2010-07-03 01:22:24 UTC (rev 1963)
+++ trunk/src/jar/util/java/org/mulgara/util/io/LBufferedFile.java 2010-07-03 02:14:25 UTC (rev 1964)
@@ -35,9 +35,15 @@
/** The property for the block type. May be "direct" or "javaHeap" */
public static final String MEM_TYPE_PROP = "mulgara.xa.memoryType";
+ /** The property for the io type. May be "mapped" or "explicit" */
+ public static final String IO_TYPE_PROP = "mulgara.xa.forceIOType";
+
/** Enumeration of the different memory types for blocks */
enum BlockMemoryType { DIRECT, HEAP };
+ /** Enumeration of the different io types */
+ enum IOType { MAPPED, EXPLICIT };
+
/** Native ordering of the bytes */
ByteOrder NATIVE_ORDER = ByteOrder.nativeOrder();
@@ -47,6 +53,8 @@
/** The configured type of block type to use. */
private static final BlockMemoryType BLOCK_TYPE;
+ private static final IOType ioType;
+
static {
String defBlockType = System.getProperty(MEM_TYPE_PROP, DEFAULT.name());
if (defBlockType.equalsIgnoreCase(BlockMemoryType.DIRECT.name())) {
@@ -57,6 +65,18 @@
logger.warn("Invalid value for property " + MEM_TYPE_PROP + ": " + defBlockType);
BLOCK_TYPE = DEFAULT;
}
+
+ String forceIOTypeProp = System.getProperty("mulgara.xa.forceIOType", "mapped");
+
+ if (forceIOTypeProp.equalsIgnoreCase(IOType.MAPPED.name())) {
+ ioType = IOType.MAPPED;
+ } else if (forceIOTypeProp.equalsIgnoreCase(IOType.EXPLICIT.name())) {
+ ioType = IOType.EXPLICIT;
+ } else {
+ logger.warn("Invalid value for property mulgara.xa.forceIOType: " + forceIOTypeProp);
+ ioType = IOType.MAPPED;
+ }
+
}
@@ -101,6 +121,13 @@
public abstract void seek(long offset) throws IOException;
/**
+ * Closes the file resource.
+ */
+ public void close() throws IOException {
+ file.close();
+ }
+
+ /**
* Ensures that all data written to this file is forced to disk.
* @throws IOException If there is an IO error accessing the disk.
*/
@@ -109,6 +136,32 @@
}
/**
+ * Create a buffered file using a filename.
+ * @param fileName The name of the file to provide buffered access to.
+ * @return The readonly buffered file.
+ * @throws IOException An error opening the file.
+ */
+ public static LBufferedFile createReadOnlyLBufferedFile(String fileName) throws IOException {
+ return createReadOnlyLBufferedFile(new RandomAccessFile(fileName, "r"));
+ }
+
+ /**
+ * Create a buffered file, taking over the RandomAccessFile that is provided.
+ * @param f The file to provide buffered access to.
+ * @return The readonly buffered file.
+ * @throws IOException An error opening the file.
+ */
+ public static LBufferedFile createReadOnlyLBufferedFile(RandomAccessFile f) throws IOException {
+ if (ioType == IOType.MAPPED) {
+ return new LMappedBufferedFile(f);
+ } else if (ioType == IOType.EXPLICIT) {
+ return new LReadOnlyIOBufferedFile(f);
+ } else {
+ throw new IllegalArgumentException("Invalid BlockFile ioType.");
+ }
+ }
+
+ /**
* Allocates data according to the system configured memory model.
* @param size The number of bytes in the allocated buffer.
* @return the allocated buffer.
More information about the Mulgara-svn
mailing list