es.iac.ing.codeso.publisher.client
Class SubscriberLinkCheckerTask

java.lang.Object
  extended by java.util.Observable
      extended by es.iac.ing.codeso.publisher.client.SubscriberLinkCheckerTask

 class SubscriberLinkCheckerTask
extends java.util.Observable

Provides a means of periodically verifying the link to the subscriber.

The scheduling of link verifications is determined by the initialDelay and retryInterval parameters passed in the class constructor.

Once created this task runs indefinitely until either a) it is cancelled by the user via the cancel method or b) an attempt to verify the subscription results in failure.

The termination of this task and the reason for its termination may be detected via the isTerminated and getTerminationReason methods respectively.

This task extends the java.util.Observable class to provide a single notifiable event generated when (or if) the task unexpectedly terminates. Notification is sent to interested parties who implement the java.util.Observer interface. The notification includes details of the source of the event (this class) and the reason the task terminated as described by the SubscriberLinkCheckerTask.TerminationReason enumeration.

Note: the termination event is NOT generated if the task is cancelled by the user.

This class is thread-safe.


Nested Class Summary
static class SubscriberLinkCheckerTask.TerminationReason
          An enumeration describing the possible reasons why the link checker task terminated.
 
Field Summary
private  java.util.Timer executionTimer
          Reference to a timer which will be used to schedule periodic execution of the link checking operation.
private  int initialDelay
          Interval in milliseconds before the first attempt to verify the link.
private  PublisherProxyDataModel publisherProxyDataModel
          Reference to the object which will be informed of the results if the lease renewer fails.
private  int retryInterval
          Interval in milliseconds between subsequent attempts to verify the link.
private  es.iac.ing.codeso.idl.publisher.IdlSubscribable subscribable
          Reference to the CORBA object to whom the link verification requests should be made.
private  SubscriberId subscriberId
          Id of the subscriber whose link is to be checked.
private  SubscriberLinkCheckerTask.TerminationReason terminationReason
          Holds the reason why the task terminated.
 
Constructor Summary
private SubscriberLinkCheckerTask(es.iac.ing.codeso.idl.publisher.IdlSubscribable subscribable, PublisherProxyDataModel publisherProxyDataModel, SubscriberId subscriberId, int initialDelay, int retryInterval)
          Constructs a new SubscriberLinkCheckerTask which will periodically attempt tocheck a subscriber's link.
 
Method Summary
 void cancel()
          Cancels this task, if it is still running.
private  void checkSubscriberLink()
          Checks the subscribers link.
 SubscriberLinkCheckerTask.TerminationReason getTerminationReason()
          Returns the reason why the task has terminated (if it has).
 boolean isTerminated()
          Returns a boolean indicating whether the task has terminated.
static SubscriberLinkCheckerTask newInstance(es.iac.ing.codeso.idl.publisher.IdlSubscribable subscribable, PublisherProxyDataModel publisherProxyDataModel, SubscriberId subscriberId, int initialDelay, int retryInterval)
          Returns a new instance of a SubscriberLinkCheckerTask.
private  void setAndNotifyTerminated(SubscriberLinkCheckerTask.TerminationReason reason, java.lang.String additionalInformation)
          Terminates this task storing the reason why and notifying observers of this class.
private  void start()
          Starts the task.
private  void stop()
          Stops the task.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subscriberId

private final SubscriberId subscriberId
Id of the subscriber whose link is to be checked.


subscribable

private final es.iac.ing.codeso.idl.publisher.IdlSubscribable subscribable
Reference to the CORBA object to whom the link verification requests should be made.


publisherProxyDataModel

private final PublisherProxyDataModel publisherProxyDataModel
Reference to the object which will be informed of the results if the lease renewer fails.


initialDelay

private final int initialDelay
Interval in milliseconds before the first attempt to verify the link.


retryInterval

private final int retryInterval
Interval in milliseconds between subsequent attempts to verify the link.


executionTimer

private java.util.Timer executionTimer
Reference to a timer which will be used to schedule periodic execution of the link checking operation.


terminationReason

private SubscriberLinkCheckerTask.TerminationReason terminationReason
Holds the reason why the task terminated.

Constructor Detail

SubscriberLinkCheckerTask

private SubscriberLinkCheckerTask(es.iac.ing.codeso.idl.publisher.IdlSubscribable subscribable,
                                  PublisherProxyDataModel publisherProxyDataModel,
                                  SubscriberId subscriberId,
                                  int initialDelay,
                                  int retryInterval)
Constructs a new SubscriberLinkCheckerTask which will periodically attempt tocheck a subscriber's link.

This constructor should not be used directly. Instead please use the newInstance method which will safely construct the object before starting the internal thread which will perform the link checking operation.

Parameters:
subscribable - CORBA reference to the object to whom the link verification requests should be made.
publisherProxyDataModel - reference to the data model which is to be informed of failure if the link checker fails.
subscriberId - the id of the subscriber whose status is to be checked.
initialDelay - delay in milliseconds which will be applied after the construction of a new instance of this class before the first attempt to verify the subscriber link.
retryInterval - delay in milliseconds which will be applied between subsequent attempts to verify the subscriber link.
Throws:
java.lang.NullPointerException - if either of the reference parameters were null.
java.lang.IllegalArgumentException - if the initialDelay parameter was negative.
java.lang.IllegalArgumentException - if the retryInterval parameter was less than or equal to zero.
Method Detail

newInstance

public static SubscriberLinkCheckerTask newInstance(es.iac.ing.codeso.idl.publisher.IdlSubscribable subscribable,
                                                    PublisherProxyDataModel publisherProxyDataModel,
                                                    SubscriberId subscriberId,
                                                    int initialDelay,
                                                    int retryInterval)
Returns a new instance of a SubscriberLinkCheckerTask.

Parameters:
subscribable - CORBA reference to the object to whom the link verification requests should be made.
publisherProxyDataModel - reference to the data model which is to be informed of failure if the link checker fails.
subscriberId - the id of the subscriber whose status is to be checked.
initialDelay - delay in milliseconds which will be applied after the construction of a new instance of this class before the first attempt to verify the subscriber link.
retryInterval - delay in milliseconds which will be applied between subsequent attempts to verify the subscriber link.
Returns:
reference to the new instance.
Throws:
java.lang.NullPointerException - if either of the reference parameters were null.
java.lang.IllegalArgumentException - if the initialDelay parameter was negative.
java.lang.IllegalArgumentException - if the retryInterval parameter was less than or equal to zero.

cancel

public void cancel()
Cancels this task, if it is still running.

Sets the reason for termination to TerminationReason.TASK_CANCELLED_BY_USER but does NOT notify the user. This method may be called repeatedly; the second and subsequent calls have no effect.


isTerminated

public boolean isTerminated()
Returns a boolean indicating whether the task has terminated.

Returns:
true if it has; otherwise false

getTerminationReason

public SubscriberLinkCheckerTask.TerminationReason getTerminationReason()
Returns the reason why the task has terminated (if it has). If the has NOT terminated the TerminationReason.NOT_TERMINATED value will be returned.

Returns:
TerminationReason enumeration specifying the reason for task termination.

start

private void start()
Starts the task.


setAndNotifyTerminated

private void setAndNotifyTerminated(SubscriberLinkCheckerTask.TerminationReason reason,
                                    java.lang.String additionalInformation)
Terminates this task storing the reason why and notifying observers of this class.

Parameters:
reason - the reason why.
additionalInformation - optional field providing additional information about the cause of the error. Typically, this information will be acquired at runtime. This field may be set to null or an empty string if not required.

checkSubscriberLink

private void checkSubscriberLink()
Checks the subscribers link. Terminates task on failure.


stop

private void stop()
Stops the task. This method may be called repeatedly; the second and subsequent calls have no effect.