com.ibm.agletx.patterns
Class Slave

java.lang.Object
  |
  +--com.ibm.aglet.Aglet
        |
        +--com.ibm.agletx.patterns.Slave
All Implemented Interfaces:
java.io.Serializable

public abstract class Slave
extends Aglet

Create a slave by calling the static method create. The slave will get dispatched automatically.
Given an itinerary, the slave is travelled from one destination to another while repeating a local computation in every destination. Then, a final result is delivered to the slave's Master (the creator of the slave). During its tour the slave aglet skips destinations which are not available.
When a slave:
1) completes its tour.
2) encounters an error during a local computation.
3) cannot be further dispatched to yet unvisited destinations.
it immediately returns to its origin host and submits the intermediate result.

Version:
1.0 96/08/18
Author:
Danny B. Lange, Yariv Aridor
See Also:
Serialized Form

Field Summary
protected  java.lang.Object ARGUMENT
          The protected variable that carries an argument for the local task performed in every destination.
protected  java.lang.Object RESULT
          The protected variable that accumulates the results of the local task performed in every destination.
 
Fields inherited from class com.ibm.aglet.Aglet
ACTIVE, INACTIVE, MAJOR_VERSION, MINOR_VERSION
 
Constructor Summary
Slave()
           
 
Method Summary
static AgletProxy create(java.net.URL url, java.lang.String name, AgletContext context, Aglet master, java.util.Vector itinerary, java.lang.Object argument)
          Create a slave.
protected abstract  void doJob()
          This method should be overridden to specify the local task of the slave.
 AgletID getMaster()
           
 java.lang.String getOrigin()
          Return the address of origin of the Slave (i.e.
 boolean handleMessage(Message msg)
          Handles the message form outside.
protected abstract  void initializeJob()
          This method should be overridden to specify initialization part for the job of the slave.
 void onCreation(java.lang.Object object)
          Initialize the slave.
 
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

RESULT

protected java.lang.Object RESULT
The protected variable that accumulates the results of the local task performed in every destination.

ARGUMENT

protected java.lang.Object ARGUMENT
The protected variable that carries an argument for the local task performed in every destination.
Constructor Detail

Slave

public Slave()
Method Detail

create

public static AgletProxy create(java.net.URL url,
                                java.lang.String name,
                                AgletContext context,
                                Aglet master,
                                java.util.Vector itinerary,
                                java.lang.Object argument)
                         throws java.io.IOException,
                                AgletException
Create a slave.
Parameters:
url - the url of the aglet class.
name - the name of the aglet class.
context - the aglet context in which the slave should be created.
master - the master aglet.
itinerary - A vector of addresses of destinations
argument - the
 argument 
object.
Returns:
an aglet proxy for the slave.
Throws:
AgletException - if initialization fails.

doJob

protected abstract void doJob()
                       throws java.lang.Exception
This method should be overridden to specify the local task of the slave.
Throws:
AgletException - if fails to complete.

getMaster

public AgletID getMaster()

getOrigin

public java.lang.String getOrigin()
Return the address of origin of the Slave (i.e. the host from which it started its tour).
Returns:
the address of the origin.

handleMessage

public boolean handleMessage(Message msg)
Description copied from class: Aglet
Handles the message form outside.
Overrides:
handleMessage in class Aglet
Following copied from class: com.ibm.aglet.Aglet
Parameters:
msg - the message sent to the 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)

initializeJob

protected abstract void initializeJob()
                               throws java.lang.Exception
This method should be overridden to specify initialization part for the job of the slave.
Throws:
AgletException - if fails to complete.

onCreation

public void onCreation(java.lang.Object object)
Initialize the slave. It is called only the first time the slave is created. The initialization argument includes three elements: (1) the master aglet and (2) the Slave's itinerary, and (3) an argument for the local task.
Overrides:
onCreation in class Aglet
Parameters:
obj - the initialization argument
Throws:
AgletException - if the initialization fails.