net.sf.farrago.util
Class FarragoTimerAllocation

java.lang.Object
  extended by net.sf.farrago.util.FarragoTimerAllocation
All Implemented Interfaces:
FarragoAllocation, ClosableAllocation

public class FarragoTimerAllocation
extends Object
implements FarragoAllocation

FarragoTimerAllocation takes care of cancelling a Timer when it is closed. Cancellation is implemented synchronously and without any delay, making it easy to avoid shutdown races.

NOTE jvs 13-Aug-2007: The shutdown mechanism requires that cancellation not happen via any other means. If it does, the shutdown could result in an IllegalStateException or a hang. Use FarragoTimerTask to avoid the implicit cancellation which can occur when a timer task throws an exception.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/util/FarragoTimerAllocation.java#15 $
Author:
John V. Sichi

Nested Class Summary
private  class FarragoTimerAllocation.CancelTask
          Helper class implementing synchronous cancellation.
 
Field Summary
private  Object shutdownSynch
           
private  Timer timer
           
 
Constructor Summary
FarragoTimerAllocation(FarragoAllocationOwner owner, Timer timer)
          Creates a new FarragoTimerAllocation.
 
Method Summary
 void closeAllocation()
          Closes this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timer

private Timer timer

shutdownSynch

private final Object shutdownSynch
Constructor Detail

FarragoTimerAllocation

public FarragoTimerAllocation(FarragoAllocationOwner owner,
                              Timer timer)
Creates a new FarragoTimerAllocation.

Parameters:
owner - the owner for the timer
timer - the timer to be cancelled when this allocation is closed
Method Detail

closeAllocation

public void closeAllocation()
Description copied from interface: ClosableAllocation
Closes this object.

Specified by:
closeAllocation in interface ClosableAllocation