import java.nio.channels.ClosedChannelException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* @author Olivier Lamy
private int timeout = 0;
+
@Override
public Lock readFileLock( File file )
throws FileLockException, FileLockTimeoutException
}
}
+ Lock current = lockFiles.get( file );
+
try
{
- Lock current = lockFiles.get( file );
+
if ( current != null )
{
log.debug( "write lock file exist continue wait" );
continue;
}
- lock = new Lock(file, true);
- createNewFileQuietly(file);
- lock.openLock(true, timeout > 0);
+ lock = new Lock( file, true );
+ createNewFileQuietly( file );
+ lock.openLock( true, timeout > 0 );
acquired = true;
}
catch ( FileNotFoundException e )
}
catch ( IOException e )
{
- if (lock!=null && lock.isValid()) {
- try {
- lock.close();
- } catch (IOException ex) {
- // Ignore
- }
- }
throw new FileLockException( e.getMessage(), e );
}
catch ( IllegalStateException e )
{
- // Ignore this
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 );
- if (lock!=null && lock != current) {
- try {
- lock.close();
- } catch (IOException e) {
- // ignore
- }
-
- }
if ( current != null )
{
lock = current;
}
-
return lock;