You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/12/07 13:24:58 UTC
svn commit: r1211412 - in
/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb:
base/file/ChannelManager.java base/file/FileBase.java
transaction/NodeTableTrans.java
Author: andy
Date: Wed Dec 7 12:24:57 2011
New Revision: 1211412
URL: http://svn.apache.org/viewvc?rev=1211412&view=rev
Log:
Tidy up.
Modified:
incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java
incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileBase.java
incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java
Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java?rev=1211412&r1=1211411&r2=1211412&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java Wed Dec 7 12:24:57 2011
@@ -20,29 +20,31 @@ package com.hp.hpl.jena.tdb.base.file;
import java.io.IOException ;
import java.io.RandomAccessFile ;
-import java.nio.channels.Channel ;
import java.nio.channels.FileChannel ;
+import java.util.ArrayList ;
import java.util.HashMap ;
+import java.util.List ;
import java.util.Map ;
import org.openjena.atlas.io.IO ;
public class ChannelManager
{
+ // Make per "location"?
+
// Because "FileManager" is already in use
// ChannelManager
- // Filebase ==> OpenFileRef
- // ChannelRef
+ // FileBase ==> OpenFileRef, ChannelRef
- public static FileChannel open(String filename)
+ public static FileChannel acquire(String filename)
{
- return open(filename, "rw") ;
+ return acquire(filename, "rw") ;
}
- public static FileChannel open(String filename, String mode)
+ public static FileChannel acquire(String filename, String mode)
{
- return openref$(filename, "rw") ;
+ return openref$(filename, mode) ;
}
static private Map<String, FileChannel> name2channel = new HashMap<String, FileChannel>() ;
@@ -50,13 +52,17 @@ public class ChannelManager
private static FileChannel openref$(String filename, String mode)
{
+ // Temp - for now, only journal files are tracked.
+ if ( ! filename.endsWith(".jrnl") )
+ {
+ return open$(filename, mode) ;
+ }
+
FileChannel chan = name2channel.get(filename) ;
if ( chan != null )
{
- // Temp - for now, only journal files.
- if ( filename.endsWith(".jrnl") )
- // Scream - it's currently open.
- throw new FileException("Already open: "+filename) ;
+ // Scream - it's currently open.
+ throw new FileException("Already open: "+filename) ;
}
chan = open$(filename, mode) ;
name2channel.put(filename, chan) ;
@@ -77,11 +83,32 @@ public class ChannelManager
} catch (IOException ex) { throw new FileException("Failed to open: "+filename+" (mode="+mode+")", ex) ; }
}
- public static void close(Channel chan)
+ public static void release(FileChannel chan)
{
+ // Always close even if not managed.
IO.close(chan) ;
String name = channel2name.remove(chan) ;
- name2channel.remove(name) ;
+ if ( name != null )
+ name2channel.remove(name) ;
+ }
+
+ /** Shutdown all the files matching the prefix (typically a directory) */
+ public static void shutdown(String prefix)
+ {
+ // Use an iterator explicitly so we can remove from the map.
+ List<FileChannel> x = new ArrayList<FileChannel>() ;
+ for ( String fn : name2channel.keySet() )
+ {
+ if ( fn.startsWith(prefix) )
+ {
+ x.add(name2channel.get(fn)) ;
+ // Don't call release here - potential CME problems.
+ // Could use an explicit iterator on teh keySet and .remove from that but
+ // then we nearly duplicate the code in release.
+ }
+ }
+ for ( FileChannel chan : x )
+ release(chan) ;
}
}
Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileBase.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileBase.java?rev=1211412&r1=1211411&r2=1211412&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileBase.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileBase.java Wed Dec 7 12:24:57 2011
@@ -54,15 +54,7 @@ public final class FileBase implements S
if ( DebugThis )
log.debug("open: ["+id+"]"+filename) ;
this.filename = filename ;
- channel = ChannelManager.open(filename, mode) ;
-// try {
-// // "rwd" - Syncs only the file contents
-// // "rws" - Syncs the file contents and metadata
-// // "rw" - OS write behind possible
-// // "r" - read only
-// RandomAccessFile out = new RandomAccessFile(filename, mode) ;
-// channel = out.getChannel() ;
-// } catch (IOException ex) { throw new BlockException("Failed to create FileBase", ex) ; }
+ channel = ChannelManager.acquire(filename, mode) ;
}
public final FileChannel channel() { return channel ; }
@@ -86,7 +78,7 @@ public final class FileBase implements S
{
if ( DebugThis )
log.debug("close: ["+id+"]: "+filename) ;
- ChannelManager.close(channel) ;
+ ChannelManager.release(channel) ;
channel = null ;
// try {
// channel.close() ;
Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java?rev=1211412&r1=1211411&r2=1211412&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java Wed Dec 7 12:24:57 2011
@@ -159,10 +159,7 @@ public class NodeTableTrans implements N
passthrough = false ;
offset = base.allocOffset().getId() ;
- // Any outstanding transactions
- //long journalOffset = journal.length() ;
- //offset += journalOffset ;
-
+
journalObjFileStartOffset = journalObjFile.length() ;
if ( journalObjFileStartOffset != 0 )
{
@@ -176,7 +173,7 @@ public class NodeTableTrans implements N
{
// TEMP : if you see this code active in SVN, set it to false immediately.
// The question is how come the journal position was non-zero in the first place.
- System.err.printf("journalStartOffset reset to zero") ;
+ System.err.println("journalStartOffset reset to zero") ;
journalObjFileStartOffset = 0 ;
journalObjFile.truncate(0) ;
journalObjFile.sync() ;