com.ibm.agletx.patterns
Class Notifier

java.lang.Object
  extended bycom.ibm.aglet.Aglet
      extended bycom.ibm.agletx.patterns.Notifier
All Implemented Interfaces:
java.io.Serializable

public abstract class Notifier
extends Aglet

Create a notifier by calling the static method create. The notifier will get dispatched automatically. The notifier performs successive checks (at its destination) within a specified time duration. Upon every successfull check (one the encounters a change in a local state), it notifies its master. The notifier can be defined (see

 create 
) to complete its job after the first successive check (although its time duration has not been reached yet). If a notifier cannot be dispatched or it encounters an error during a check, it notifies its master and disposed itself.

Version:
1.01 97/10/1
Author:
Danny B. Lange, Yariv Aridor
See Also:
Serialized Form

Field Summary
private  java.lang.String _destination
           
private  double _duration
           
private  double _interval
           
private  AgletID _master
           
private  long _startingTime
           
private  boolean _stay
           
protected  java.lang.Object ARGUMENT
          The protected variable that carries any arguments for the checks that this notifier performs.
static int EXCEPTION
           
static int EXPIRY
           
protected  java.lang.Object MESSAGE
          The protected variable that carries any messages that should go along with the notification back to the subscriber.
private static double MIN_TIME_OF_DEACTIVATION
           
static int NOTIFICATION
           
private  java.lang.String origin
           
 
Fields inherited from class com.ibm.aglet.Aglet
ACTIVE, INACTIVE, MAJOR_VERSION, MINOR_VERSION
 
Constructor Summary
Notifier()
           
 
Method Summary
private  boolean checkTimeout()
           
static AgletProxy create(java.net.URL url, java.lang.String source, AgletContext context, Aglet master, java.net.URL destination, double interval, double duration, boolean stay, java.lang.Object argument)
          Creates a notifier.
protected abstract  boolean doCheck()
          This method should be overridden to specify the check method for this notifier.
private  void gotoSleep(double hours)
           
 boolean handleMessage(Message msg)
          Handles the message form outside.
protected abstract  void initializeCheck()
          This method should be overridden to specify any intialization before the checks performed by this notifier.
private  java.lang.String makeExceptionMessage(java.lang.String phase, java.lang.Throwable ex)
           
private  void observeInit()
           
private  void observeRun()
           
 void onCreation(java.lang.Object object)
          Initializes the notifier.
private  void sendRemoteMessage(int type, java.lang.Object data)
           
private  void start()
           
private  void startTimer()
           
private  void waitInHours(double h)
           
 
Methods inherited from class com.ibm.aglet.Aglet
addCloneListener, addMobilityListener, addPersistencyListener, clone, deactivate, dispatch, dispatch, dispatchEvent, dispose, exitMonitor, getAgletContext, getAgletID, getAgletInfo, getAudioData, getCodeBase, getImage, getImage, getMessageManager, getProtections, getProxy, getText, notifyAllMessages, notifyMessage, onDisposing, processCloneEvent, processMobilityEvent, processPersistencyEvent, removeCloneListener, removeMobilityListener, removePersistencyListener, run, setProtections, setStub, setText, snapshot, subscribeMessage, suspend, unsubscribeAllMessages, unsubscribeMessage, waitMessage, waitMessage
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOTIFICATION

public static final int NOTIFICATION
See Also:
Constant Field Values

EXPIRY

public static final int EXPIRY
See Also:
Constant Field Values

EXCEPTION

public static final int EXCEPTION
See Also:
Constant Field Values

MIN_TIME_OF_DEACTIVATION

private static final double MIN_TIME_OF_DEACTIVATION
See Also:
Constant Field Values

origin

private java.lang.String origin

_master

private AgletID _master

_destination

private java.lang.String _destination

_interval

private double _interval

_duration

private double _duration

_startingTime

private long _startingTime

_stay

private boolean _stay

MESSAGE

protected java.lang.Object MESSAGE
The protected variable that carries any messages that should go along with the notification back to the subscriber.


ARGUMENT

protected java.lang.Object ARGUMENT
The protected variable that carries any arguments for the checks that this notifier performs.

Constructor Detail

Notifier

public Notifier()
Method Detail

checkTimeout

private boolean checkTimeout()

create

public static AgletProxy create(java.net.URL url,
                                java.lang.String source,
                                AgletContext context,
                                Aglet master,
                                java.net.URL destination,
                                double interval,
                                double duration,
                                boolean stay,
                                java.lang.Object argument)
                         throws java.io.IOException,
                                AgletException
Creates a notifier.

Parameters:
url - the URL of the aglet class.
source - the name of the aglet class.
context - the aglet context in which the notifier should be created.
master - the master aglet.
destination - the URL of the destination.
interval - the time in hours between to checks.
duration - the life time of the notifier.
stay - whether the notifier should remain after a notification.
argument - the
 argument 
object.
Returns:
an aglet proxy for the notifier.
Throws:
AgletException - if the creation fails.
java.io.IOException

doCheck

protected abstract boolean doCheck()
                            throws java.lang.Exception
This method should be overridden to specify the check method for this notifier.

Returns:
boolean result of the check.
Throws:
AgletException - if fails to complete.
java.lang.Exception

gotoSleep

private void gotoSleep(double hours)
                throws AgletException
Throws:
AgletException

handleMessage

public boolean handleMessage(Message msg)
Description copied from class: Aglet
Handles the message form outside.

Overrides:
handleMessage in class Aglet
Returns:
true if the message was handled. Returns false if the message was not handled. If false is returned, the MessageNotHandled exception is thrown in the FutureReply.getReply and AgletProxy.sendMessage methods.
See Also:
FutureReply.getReply(), Message.sendReply(), AgletProxy.sendMessage(com.ibm.aglet.Message)

initializeCheck

protected abstract void initializeCheck()
                                 throws java.lang.Exception
This method should be overridden to specify any intialization before the checks performed by this notifier.

Throws:
AgletException - if fails to complete.
java.lang.Exception

makeExceptionMessage

private java.lang.String makeExceptionMessage(java.lang.String phase,
                                              java.lang.Throwable ex)

observeInit

private void observeInit()
                  throws java.lang.Exception
Throws:
java.lang.Exception

observeRun

private void observeRun()
                 throws java.lang.Exception
Throws:
java.lang.Exception

onCreation

public void onCreation(java.lang.Object object)
Initializes the notifier. Called only the first time this notifier is created. The initialization argument includes the needed parameters for the checks as defined in
 create 
.

Overrides:
onCreation in class Aglet
Parameters:
object - the argument with which the aglet is initialized.
Throws:
AgletException - if the initialization fails.
See Also:
AgletContext.createAglet(java.net.URL, java.lang.String, java.lang.Object)

sendRemoteMessage

private void sendRemoteMessage(int type,
                               java.lang.Object data)
                        throws java.io.IOException,
                               AgletException
Throws:
java.io.IOException
AgletException

start

private void start()

startTimer

private void startTimer()

waitInHours

private void waitInHours(double h)