Reverting locking modifications

This commit is contained in:
Martin Stockhammer 2016-10-27 17:36:27 +02:00
parent d380bc6779
commit 5780110b79
1 changed files with 7 additions and 32 deletions

View File

@ -31,7 +31,6 @@ import java.io.RandomAccessFile;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
@ -52,6 +51,7 @@ public class DefaultFileLockManager
private int timeout = 0; private int timeout = 0;
@Override @Override
public Lock readFileLock( File file ) public Lock readFileLock( File file )
throws FileLockException, FileLockTimeoutException throws FileLockException, FileLockTimeoutException
@ -162,18 +162,20 @@ public class DefaultFileLockManager
} }
} }
Lock current = lockFiles.get( file );
try try
{ {
Lock current = lockFiles.get( file );
if ( current != null ) if ( current != null )
{ {
log.debug( "write lock file exist continue wait" ); log.debug( "write lock file exist continue wait" );
continue; continue;
} }
lock = new Lock(file, true); lock = new Lock( file, true );
createNewFileQuietly(file); createNewFileQuietly( file );
lock.openLock(true, timeout > 0); lock.openLock( true, timeout > 0 );
acquired = true; acquired = true;
} }
catch ( FileNotFoundException e ) catch ( FileNotFoundException e )
@ -189,47 +191,20 @@ public class DefaultFileLockManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
if (lock!=null && lock.isValid()) {
try {
lock.close();
} catch (IOException ex) {
// Ignore
}
}
throw new FileLockException( e.getMessage(), e ); throw new FileLockException( e.getMessage(), e );
} }
catch ( IllegalStateException e ) catch ( IllegalStateException e )
{ {
// Ignore this
log.debug( "openLock {}:{}", e.getClass(), e.getMessage() ); log.debug( "openLock {}:{}", e.getClass(), e.getMessage() );
} catch (Throwable t) {
if (lock!=null && lock.isValid()) {
try {
lock.close();
} catch (IOException ex) {
// Ignore
}
}
throw t;
} }
} }
Lock current = lockFiles.putIfAbsent( file, lock ); Lock current = lockFiles.putIfAbsent( file, lock );
if (lock!=null && lock != current) {
try {
lock.close();
} catch (IOException e) {
// ignore
}
}
if ( current != null ) if ( current != null )
{ {
lock = current; lock = current;
} }
return lock; return lock;