net.jini.lookup
Class JoinManager.ProxyRegTask

java.lang.Object
  extended by com.sun.jini.thread.RetryTask
      extended by net.jini.lookup.JoinManager.ProxyRegTask
All Implemented Interfaces:
TimeConstants, TaskManager.Task, Runnable
Enclosing class:
JoinManager

private class JoinManager.ProxyRegTask
extends RetryTask

Abstract base class from which all of the task classes are derived.


Field Summary
protected  int nRetries
           
protected  JoinManager.ProxyReg proxyReg
           
protected  int seqN
           
private  long[] sleepTime
           
protected  int tryIndx
           
 
Fields inherited from interface com.sun.jini.constants.TimeConstants
DAYS, HOURS, MINUTES, SECONDS
 
Constructor Summary
JoinManager.ProxyRegTask(JoinManager.ProxyReg proxyReg, int seqN)
          Basic constructor; simply stores the input parameters
 
Method Summary
 JoinManager.ProxyReg getProxyReg()
          Accessor method that returns the instance of ProxyReg (the lookup service) associated with the task represented by the current instance of this class.
 int getSeqN()
          Accessor method that returns the unique sequence number associated with the task represented by the current instance of this class.
 long retryTime()
          Returns the next absolute time (in milliseconds) at which another execution of this task should be made (after the previous attempt has failed).
 boolean runAfter(List tasks, int size)
          Returns true if the current instance of this task must be run after any task already in the task manager queue.
protected  boolean stopTrying(Exception e)
          Convenience method called by the child tasks when they encounter an exception.
 boolean tryOnce()
          Executes the current instance of this task once, queuing it for retry at a later time and returning false upon failure.
 
Methods inherited from class com.sun.jini.thread.RetryTask
attempt, cancel, cancelled, complete, reset, run, startTime, waitFor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sleepTime

private final long[] sleepTime

tryIndx

protected int tryIndx

nRetries

protected int nRetries

proxyReg

protected JoinManager.ProxyReg proxyReg

seqN

protected int seqN
Constructor Detail

JoinManager.ProxyRegTask

JoinManager.ProxyRegTask(JoinManager.ProxyReg proxyReg,
                         int seqN)
Basic constructor; simply stores the input parameters

Method Detail

tryOnce

public boolean tryOnce()
Executes the current instance of this task once, queuing it for retry at a later time and returning false upon failure. This method attempts to execute all of the tasks associated with the lookup service referenced in this task's proxyReg field. Order of execution is important, and this method executes the tasks in the proxyReg's taskList in a FIFO order. Note that tasks may be added to the taskList of the proxyReg during the execution of this method. Upon successfully executing all of the tasks in the taskList, this method returns true and the current instance of this task is not executed again. For each unsuccessful execution of a task in the taskList, this method returns false, which causes the task to be scheduled by the WakeupManager to be executed again at a later time, as indicated by the value returned by retryTime.

Specified by:
tryOnce in class RetryTask

retryTime

public long retryTime()
Returns the next absolute time (in milliseconds) at which another execution of this task should be made (after the previous attempt has failed).

Overrides:
retryTime in class RetryTask

runAfter

public boolean runAfter(List tasks,
                        int size)
Returns true if the current instance of this task must be run after any task already in the task manager queue. It is important that when the join manager is constructed with a null service ID (where it is desired that a unique service ID be generated on the service's behalf), that only the first task in the task manager's queue be run; no other tasks in the queue should be run while that first task is running. This is because the first sub-task executed by the first main task in the task manager's queue will always be a RegisterTask. And during the execution of that first sub-task (if the service ID has not yet been set), the service ID generated by the associated lookup service is retrieved and stored for use in all future lookup service registration tasks, Once the service ID is set by that first registration sub-task, all future main tasks (and their associated registration sub-tasks) can be run in parallel; each using the same service ID. If this is not done, then the registration sub-tasks would be run in parallel, each assigning a different ID to the service. This method guarantees that until the service's ID is set, only one registration sub-task is run; that is, one task doesn't start until the currently running task has completed, and a non-null service ID is assigned to the service. Executing the main tasks sequentially until the service ID is retrieved and stored must also be guaranteed because the currently running registration task may fail to register the service (because of a RemoteException), and thus may fail to obtain an ID for the service. This method guarantees then that each main task (and thus, each registration sub-task) will run in sequence until one of those tasks completes successfully; and from that point on, this method guarantees that all other queued tasks will run in parallel.

Parameters:
tasks - the tasks with which to compare the current task
size - elements with index less than size are considered

getProxyReg

public JoinManager.ProxyReg getProxyReg()
Accessor method that returns the instance of ProxyReg (the lookup service) associated with the task represented by the current instance of this class.


getSeqN

public int getSeqN()
Accessor method that returns the unique sequence number associated with the task represented by the current instance of this class.


stopTrying

protected boolean stopTrying(Exception e)
Convenience method called by the child tasks when they encounter an exception. If the given exception indicates that retrying the task would definitely fail, or if the maximum allowable number of retries of the task has been exceeded, then this method will do the following: - remove all pending tasks that are to be run after this task - cancel this task - discard the look service associated with this task - return true (which stops the wakeup manager from retrying this task otherwise, this method returns false, which indicates that the wakeup manager should not stop trying to successfully execute the task.



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