From: Sasa M. <sa...@us...> - 2004-12-17 09:27:56
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20196/org/jrobin/core Modified Files: RrdFileBackend.java RrdNioBackend.java RrdSafeFileBackend.java Log Message: Bugfix #72 Index: RrdSafeFileBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdSafeFileBackend.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdSafeFileBackend.java 10 Nov 2004 13:38:48 -0000 1.2 --- RrdSafeFileBackend.java 17 Dec 2004 09:27:47 -0000 1.3 *************** *** 62,66 **** } for(int i = 0; i < LOCK_RETRY_COUNT; i++) { ! lock = channel.tryLock(); if(lock != null) { return; --- 62,66 ---- } for(int i = 0; i < LOCK_RETRY_COUNT; i++) { ! lock = file.getChannel().tryLock(); if(lock != null) { return; Index: RrdNioBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdNioBackend.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** RrdNioBackend.java 2 Nov 2004 09:06:05 -0000 1.20 --- RrdNioBackend.java 17 Dec 2004 09:27:47 -0000 1.21 *************** *** 57,68 **** super(path, readOnly, lockMode); this.syncMode = syncMode; ! mapFile(); ! if(syncMode == RrdNioBackendFactory.SYNC_BACKGROUND && !readOnly) { ! syncTask = new TimerTask() { ! public void run() { ! sync(); ! } ! }; ! fileSyncTimer.schedule(syncTask, syncPeriod * 1000L, syncPeriod * 1000L); } } --- 57,76 ---- super(path, readOnly, lockMode); this.syncMode = syncMode; ! // try-catch block suggested by jroth ! // http://www.jrobin.org/mantis/bug_view_page.php?bug_id=0000072 ! try { ! mapFile(); ! if(syncMode == RrdNioBackendFactory.SYNC_BACKGROUND && !readOnly) { ! syncTask = new TimerTask() { ! public void run() { ! sync(); ! } ! }; ! fileSyncTimer.schedule(syncTask, syncPeriod * 1000L, syncPeriod * 1000L); ! } ! } ! catch(IOException ioe) { ! super.close(); ! throw ioe; } } *************** *** 73,77 **** FileChannel.MapMode mapMode = readOnly? FileChannel.MapMode.READ_ONLY: FileChannel.MapMode.READ_WRITE; ! byteBuffer = channel.map(mapMode, 0, length); } } --- 81,85 ---- FileChannel.MapMode mapMode = readOnly? FileChannel.MapMode.READ_ONLY: FileChannel.MapMode.READ_WRITE; ! byteBuffer = file.getChannel().map(mapMode, 0, length); } } Index: RrdFileBackend.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFileBackend.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RrdFileBackend.java 22 Nov 2004 13:34:51 -0000 1.12 --- RrdFileBackend.java 17 Dec 2004 09:27:47 -0000 1.13 *************** *** 28,34 **** import java.io.IOException; import java.io.RandomAccessFile; - import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.HashSet; /** --- 28,34 ---- import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileLock; import java.util.HashSet; + import java.util.Set; /** *************** *** 41,45 **** private static final long LOCK_DELAY = 100; // 0.1sec ! private static HashSet openFiles = new HashSet(); /** read/write file status */ --- 41,45 ---- private static final long LOCK_DELAY = 100; // 0.1sec ! private static Set openFiles = new HashSet(); /** read/write file status */ *************** *** 50,55 **** /** radnom access file handle */ protected RandomAccessFile file; - /** file channel used to create locks */ - protected FileChannel channel; /** file lock */ protected FileLock fileLock; --- 50,53 ---- *************** *** 67,73 **** this.lockMode = lockMode; file = new RandomAccessFile(path, readOnly ? "r" : "rw"); ! channel = file.getChannel(); ! lockFile(); ! registerWriter(); } --- 65,76 ---- this.lockMode = lockMode; file = new RandomAccessFile(path, readOnly ? "r" : "rw"); ! try { ! lockFile(); ! registerWriter(); ! } ! catch(IOException ioe) { ! close(); ! throw ioe; ! } } *************** *** 75,79 **** switch (lockMode) { case RrdDb.EXCEPTION_IF_LOCKED: ! fileLock = channel.tryLock(); if (fileLock == null) { // could not obtain lock --- 78,82 ---- switch (lockMode) { case RrdDb.EXCEPTION_IF_LOCKED: ! fileLock = file.getChannel().tryLock(); if (fileLock == null) { // could not obtain lock *************** *** 83,87 **** case RrdDb.WAIT_IF_LOCKED: while (fileLock == null) { ! fileLock = channel.tryLock(); if (fileLock == null) { // could not obtain lock, wait a little, than try again --- 86,90 ---- case RrdDb.WAIT_IF_LOCKED: while (fileLock == null) { ! fileLock = file.getChannel().tryLock(); if (fileLock == null) { // could not obtain lock, wait a little, than try again *************** *** 123,129 **** public void close() throws IOException { unregisterWriter(); ! unlockFile(); ! channel.close(); ! file.close(); } --- 126,135 ---- public void close() throws IOException { unregisterWriter(); ! try { ! unlockFile(); ! } ! finally { ! file.close(); ! } } *************** *** 139,147 **** String canonicalPath = getCanonicalPath(path); synchronized (openFiles) { ! boolean removed = openFiles.remove(canonicalPath); ! if (!removed) { ! throw new IOException("File [" + file + "] could not be removed from the list of files " + ! "open for R/W access"); ! } } } --- 145,149 ---- String canonicalPath = getCanonicalPath(path); synchronized (openFiles) { ! openFiles.remove(canonicalPath); } } |