@Override
public Lock readFileLock( File file )
- throws FileLockException, FileNotFoundException
+ throws FileLockException, FileLockTimeoutException
{
if ( skipLocking )
{
StopWatch stopWatch = new StopWatch();
boolean acquired = false;
- Lock lock = new Lock( file, false );
+ try
+ {
+ Lock lock = new Lock( file, false );
- stopWatch.start();
+ stopWatch.start();
- while ( !acquired )
- {
- if ( timeout > 0 )
+ while ( !acquired )
{
- long delta = stopWatch.getTotalTimeMillis();
- if ( delta > timeout )
+ if ( timeout > 0 )
{
- log.warn( "Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file );
- // we could not get the lock within the timeout period, so return null
- return null;
+ long delta = stopWatch.getTotalTimeMillis();
+ if ( delta > timeout )
+ {
+ log.warn( "Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file );
+ // we could not get the lock within the timeout period, so throw FileLockTimeoutException
+ throw new FileLockTimeoutException();
+ }
+ }
+ try
+ {
+ lock.openLock( false, timeout > 0 );
+ acquired = true;
+ }
+ catch ( IOException e )
+ {
+ throw new FileLockException( e.getMessage(), e );
+ }
+ catch ( IllegalStateException e )
+ {
+ log.debug( "openLock {}:{}", e.getClass(), e.getMessage() );
}
}
- try
- {
- lock.openLock( false, timeout > 0 );
- acquired = true;
- }
- catch ( IOException e )
- {
- throw new FileLockException( e.getMessage(), e );
- }
- catch ( IllegalStateException e )
- {
- log.debug( "openLock {}:{}", e.getClass(), e.getMessage() );
- }
+ return lock;
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new FileLockException( e.getMessage(), e );
}
- return lock;
}
@Override
public Lock writeFileLock( File file )
- throws FileLockException, FileNotFoundException
+ throws FileLockException, FileLockTimeoutException
{
if ( skipLocking )
{
StopWatch stopWatch = new StopWatch();
boolean acquired = false;
- Lock lock = new Lock( file, true );
+ try
+ {
+ Lock lock = new Lock( file, true );
- stopWatch.start();
+ stopWatch.start();
- while ( !acquired )
- {
- if ( timeout > 0 )
+ while ( !acquired )
{
- long delta = stopWatch.getTotalTimeMillis();
- if ( delta > timeout )
+ if ( timeout > 0 )
{
- log.warn( "Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file );
- // we could not get the lock within the timeout period, so return null
- return null;
+ long delta = stopWatch.getTotalTimeMillis();
+ if ( delta > timeout )
+ {
+ log.warn( "Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file );
+ // we could not get the lock within the timeout period, so throw FileLockTimeoutException
+ throw new FileLockTimeoutException();
+ }
+ }
+ try
+ {
+ lock.openLock( true, timeout > 0 );
+ acquired = true;
+ }
+ catch ( IOException e )
+ {
+ throw new FileLockException( e.getMessage(), e );
+ }
+ catch ( IllegalStateException e )
+ {
+ log.debug( "openLock {}:{}", e.getClass(), e.getMessage() );
}
}
- try
- {
- lock.openLock( true, timeout > 0 );
- acquired = true;
- }
- catch ( IOException e )
- {
- throw new FileLockException( e.getMessage(), e );
- }
- catch ( IllegalStateException e )
- {
- log.debug( "openLock {}:{}", e.getClass(), e.getMessage() );
- }
+ return lock;
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new FileLockException( e.getMessage(), e );
}
- return lock;
}
}
public void thread1()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread1" );
Lock lock = fileLockManager.writeFileLock( this.file );
}
public void thread2()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread2" );
Lock lock = fileLockManager.writeFileLock( this.file );
}
public void thread3()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread3" );
Lock lock = fileLockManager.readFileLock( this.file );
}
public void thread4()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread4" );
Lock lock = fileLockManager.writeFileLock( this.file );
}
public void thread5()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread5" );
Lock lock = fileLockManager.writeFileLock( this.file );
}
public void thread6()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread6" );
Lock lock = fileLockManager.readFileLock( this.file );
}
public void thread7()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread7" );
Lock lock = fileLockManager.writeFileLock( this.file );
}
public void thread8()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread8" );
Lock lock = fileLockManager.readFileLock( this.file );
}
public void thread9()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread7" );
Lock lock = fileLockManager.writeFileLock( this.file );
}
public void thread10()
- throws FileLockException, IOException
+ throws FileLockException, FileLockTimeoutException, IOException
{
logger.info( "thread10" );
Lock lock = fileLockManager.readFileLock( this.file );