net.sf.asyncobjects.util.timer
Class TimerWrapper

java.lang.Object
  extended by net.sf.asyncobjects.AsyncUnicastServer<ATimer>
      extended by net.sf.asyncobjects.util.timer.TimerWrapper
All Implemented Interfaces:
ACloseable, AsyncObject, ExplicitSharing, ATimer

public class TimerWrapper
extends AsyncUnicastServer<ATimer>
implements ATimer

A timer wrapper. It uses Timer class to implement ATimer interface. Closing the timer has the same effect as Timer.cancel(). However the close() opertaion on the timer might be disabled by passing a false value to TimerWrapper(Timer, boolean, boolean) constructor. In that case it is still possible to use forceClose() method to close the timer.

Author:
const

Constructor Summary
TimerWrapper(Timer timer)
          A constructor
TimerWrapper(Timer timer, boolean isCloseable, boolean isPurgeable)
          A constructor
 
Method Summary
 Promise<Void> close()
          Close resource
 void forceClose()
          This method is intentionally not exported on the asynchronous facet interface.
 Promise<Integer> purge()
          Remove all tasks from the timer
 Promise<ACallable<Boolean>> schedule(Date time, ATimerTask task)
          Schedule task at specified time
 Promise<ACallable<Boolean>> schedule(Date firstTime, long period, ATimerTask task)
          Schedule task after specfied time with specified period
 Promise<ACallable<Boolean>> schedule(long delay, ATimerTask task)
          Schedule task after specified delay
 Promise<ACallable<Boolean>> schedule(long delay, long period, ATimerTask task)
          Schedule task after specfied delay with specified period
 Promise<ACallable<Boolean>> scheduleAtFixedRate(Date firstTime, long period, ATimerTask task)
          Schedule task after specfied time with fixed rage
 Promise<ACallable<Boolean>> scheduleAtFixedRate(long delay, long period, ATimerTask task)
          Schedule task after specfied delay with fixed rate
 
Methods inherited from class net.sf.asyncobjects.AsyncUnicastServer
dereference, export, isImmediate, myVat, promise
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.asyncobjects.AsyncObject
dereference, isImmediate
 

Constructor Detail

TimerWrapper

public TimerWrapper(Timer timer,
                    boolean isCloseable,
                    boolean isPurgeable)
A constructor

Parameters:
timer - a timer to use
isCloseable - if true, the timer might be closed
isPurgeable - if true, the timer might be purged

TimerWrapper

public TimerWrapper(Timer timer)
A constructor

Parameters:
timer - a timer to use
Method Detail

purge

public Promise<Integer> purge()
Description copied from interface: ATimer
Remove all tasks from the timer

Specified by:
purge in interface ATimer
Returns:
amount of purged tasks
See Also:
ATimer.purge()

schedule

public Promise<ACallable<Boolean>> schedule(long delay,
                                            ATimerTask task)
Description copied from interface: ATimer
Schedule task after specified delay

Specified by:
schedule in interface ATimer
Parameters:
delay - a delay
task - a taks to schedule.
Returns:
a promise for cancel action
See Also:
ATimer.schedule(long, net.sf.asyncobjects.util.timer.ATimerTask)

schedule

public Promise<ACallable<Boolean>> schedule(Date time,
                                            ATimerTask task)
Description copied from interface: ATimer
Schedule task at specified time

Specified by:
schedule in interface ATimer
Parameters:
time - a time to schedule at
task - a taks to schedule.
Returns:
a promise for cancel action
See Also:
ATimer.schedule(java.util.Date, net.sf.asyncobjects.util.timer.ATimerTask)

schedule

public Promise<ACallable<Boolean>> schedule(long delay,
                                            long period,
                                            ATimerTask task)
Description copied from interface: ATimer
Schedule task after specfied delay with specified period

Specified by:
schedule in interface ATimer
Parameters:
delay - a delay
period - a period
task - a taks to schedule.
Returns:
a promise for cancel action
See Also:
ATimer.schedule(long, long, net.sf.asyncobjects.util.timer.ATimerTask)

schedule

public Promise<ACallable<Boolean>> schedule(Date firstTime,
                                            long period,
                                            ATimerTask task)
Description copied from interface: ATimer
Schedule task after specfied time with specified period

Specified by:
schedule in interface ATimer
Parameters:
firstTime - a first time the task is executed
period - a period
task - a taks to schedule.
Returns:
a promise for cancel action
See Also:
ATimer.schedule(java.util.Date, long, net.sf.asyncobjects.util.timer.ATimerTask)

scheduleAtFixedRate

public Promise<ACallable<Boolean>> scheduleAtFixedRate(long delay,
                                                       long period,
                                                       ATimerTask task)
Description copied from interface: ATimer
Schedule task after specfied delay with fixed rate

Specified by:
scheduleAtFixedRate in interface ATimer
Parameters:
delay - a delay
period - a period
task - a taks to schedule.
Returns:
a promise for cancel action
See Also:
ATimer.scheduleAtFixedRate(long, long, net.sf.asyncobjects.util.timer.ATimerTask)

scheduleAtFixedRate

public Promise<ACallable<Boolean>> scheduleAtFixedRate(Date firstTime,
                                                       long period,
                                                       ATimerTask task)
Description copied from interface: ATimer
Schedule task after specfied time with fixed rage

Specified by:
scheduleAtFixedRate in interface ATimer
Parameters:
firstTime - a first time the task is executed
period - a period
task - a taks to schedule.
Returns:
a promise for cancel action
See Also:
ATimer.scheduleAtFixedRate(java.util.Date, long, net.sf.asyncobjects.util.timer.ATimerTask)

close

public Promise<Void> close()
Description copied from interface: ACloseable
Close resource

Specified by:
close in interface ACloseable
Returns:
a promise that resolves when object is closed.
See Also:
ACloseable.close(), Timer.cancel()

forceClose

public void forceClose()
This method is intentionally not exported on the asynchronous facet interface. So it is possible to use it only by creator of the object. This method forces closure of the timer, even if the timer is uncloseable.



Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.