com.sun.jini.thread
Class RetryTask

java.lang.Object
  extended by com.sun.jini.thread.RetryTask
All Implemented Interfaces:
TimeConstants, TaskManager.Task, Runnable
Direct Known Subclasses:
EventType.SendTask, JoinManager.ProxyRegTask, LookupLocatorDiscovery.DiscoveryTask, MailboxImpl.NotifyTask, Notifier.NotifyTask, ParticipantTask, SettlerTask, TxnMonitorTask

public abstract class RetryTask
extends Object
implements TaskManager.Task, TimeConstants


Nested Class Summary
private  class RetryTask.RetryTime
          This is the runnable class for the WakeupManager, since we need different implementations of WakeupManager.run and TaskManager.run.
 
Field Summary
private  int attempt
           
private  boolean cancelled
           
private  boolean complete
           
private static long[] delays
          Default delay backoff times.
private static Logger logger
          Logger for this class
private  TaskManager manager
           
private  RetryTask.RetryTime retry
           
private  long startTime
           
private  WakeupManager.Ticket ticket
           
private  WakeupManager wakeup
           
 
Fields inherited from interface com.sun.jini.constants.TimeConstants
DAYS, HOURS, MINUTES, SECONDS
 
Constructor Summary
RetryTask(TaskManager manager, WakeupManager wakeupManager)
          Create a new RetryTask that will be scheduled with the given task manager, and which will perform retry scheduling using the given wakeup manager.
 
Method Summary
 int attempt()
          Return the attempt number, starting with zero.
 void cancel()
          Cancel the retrying of the task.
 boolean cancelled()
          Return true if cancel has been invoked.
 boolean complete()
          Return true if tryOnce has returned successfully.
 void reset()
          Reset values for a new use of this task.
 long retryTime()
          Return the next time at which we should make another attempt.
 void run()
          The run method used as a TaskManager.Task.
 long startTime()
          Return the time this task was created, or the last time reset was called.
abstract  boolean tryOnce()
          Make a single attempt.
 boolean waitFor()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.jini.thread.TaskManager.Task
runAfter
 

Field Detail

manager

private TaskManager manager

retry

private RetryTask.RetryTime retry

cancelled

private boolean cancelled

complete

private boolean complete

ticket

private WakeupManager.Ticket ticket

startTime

private long startTime

attempt

private int attempt

wakeup

private WakeupManager wakeup

delays

private static final long[] delays
Default delay backoff times. These are converted from intervals to "time since start" by the static block below.

See Also:
retryTime()

logger

private static final Logger logger
Logger for this class

Constructor Detail

RetryTask

public RetryTask(TaskManager manager,
                 WakeupManager wakeupManager)
Create a new RetryTask that will be scheduled with the given task manager, and which will perform retry scheduling using the given wakeup manager.

Method Detail

tryOnce

public abstract boolean tryOnce()
Make a single attempt. Return true if the attempt was successful. If the attempt is not successful, the task will be scheduled for a future retry.


run

public void run()
The run method used as a TaskManager.Task. This invokes tryOnce. If it is not successful, it schedules the task for a future retry at the time it gets by invoking retryTime.

Specified by:
run in interface Runnable
See Also:
tryOnce(), startTime

retryTime

public long retryTime()
Return the next time at which we should make another attempt. This is not an interval, but the actual time.

The implementation is free to do as it pleases with the policy here. The default implementation is to delay using intervals of 1 second, 5 seconds, 10 seconds, 1 minute, and 1 minute between attempts, and then retrying every five minutes forever.

The default implementation assumes it is being called from the default run method and that the current thread holds the lock on this object. If the caller does not own the lock the result is undefined and could result in an exception.


startTime

public long startTime()
Return the time this task was created, or the last time reset was called.


attempt

public int attempt()
Return the attempt number, starting with zero.


cancel

public void cancel()
Cancel the retrying of the task. This ensures that there will be no further attempts to invoke tryOnce. It will not interfere with any ongoing invocation of tryOnce unless a subclass overrides this to do so. Any override of this method should invoke super.cancel().


cancelled

public boolean cancelled()
Return true if cancel has been invoked.


complete

public boolean complete()
Return true if tryOnce has returned successfully.


waitFor

public boolean waitFor()
                throws InterruptedException
Throws:
InterruptedException

reset

public void reset()
Reset values for a new use of this task.



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.