springs.agent
Class SpringsAgent_RMIImpl

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--springs.agent.SpringsAgent_RMIImpl
All Implemented Interfaces:
ISpringsAgent_RMIImpl, java.rmi.Remote, java.io.Serializable, SpringsAgent
Direct Known Subclasses:
MovingSpringsAgentDynamicRefs, MovingSpringsHelloAgent, SpringsHelloAgent, StaticSpringsAgentDynamicRefs

public class SpringsAgent_RMIImpl
extends java.rmi.server.UnicastRemoteObject
implements SpringsAgent, java.io.Serializable, ISpringsAgent_RMIImpl

A Springs agent. Base class that any Springs agent must extend.

Author:
Sergio Ilarri Artigas
See Also:
Serialized Form

Field Summary
private  boolean _agentMoving
          A boolean indicating whether the agent is moving or not.
private  java.lang.Object[] _argsCallbackMethod
          The arguments callback method to execute when arriving at a destination (null if any).
private  boolean _cacheRefs
          A boolean indicating whether references to agents should be cached (and automatically updated) by the context.
private  java.lang.String _callbackMethod
          The callback method to execute when arriving at a destination (null if any).
private  java.lang.String _codebase
          A codebase for the agent.
private  springs.context.ContextAddress _homeAddress
          The home address of the agent.
private  long _initializationTime
          Millis elapsed initialization the agent (for debugging and statistics).
private  springs.context.ContextInterfaceForAgents _interfaceToLocalContext
          An interface to the local context.
private  boolean _justCreatedForTheFirstTime
          A boolean indicating whether the agent has just been created for the first time.
private  long[] _lastMillisStays
           
private  java.util.Vector _locationServers
           
private  java.lang.Boolean _lockAgentMoving
           
private  long _millisAtCreation
          A timestamp to identify the time instant when the agent was created.
private  long _millisStartStay
          The milliseconds when the agent starts its stay in a certain context.
private  java.lang.String _name
          The name of the agent.
protected  int _numberOfJumps
          The number of jumps performed by the agent.
private  int _numStays
           
private  java.util.Set _observers
          The observers and locationServers of the agent.
private  java.util.Vector _observersAddresses
          The addresses of the contexts that "observe" this agent.
private  boolean _registered
          A boolean indicating whether the agent has already register or not.
private  springs.agent.Schedule _schedule
          The agent's schedule.
 
Fields inherited from class java.rmi.server.UnicastRemoteObject
 
Fields inherited from class java.rmi.server.RemoteServer
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface springs.agent.SpringsAgent
METHOD_MESSAGE_RECEPTION
 
Fields inherited from interface springs.agent.ISpringsAgent_RMIImpl
ADD_OBSERVER_METHOD, REMOVE_OBSERVER_METHOD
 
Constructor Summary
SpringsAgent_RMIImpl()
          Constructor.
 
Method Summary
 void addObserver(java.lang.String observer)
          Adds a observer for the agent.
 void addTaskToSchedule(java.lang.String method)
          Add a task consisting of calling a certain method.
 void addTaskToSchedule(java.lang.String targetURL, int targetPort)
          Adds a task to travel to another context.
 void addTaskToSchedule(java.lang.String targetURL, int targetPort, java.lang.String callbackMethod)
          Adds a task to travel to another context.
 void addTaskToSchedule(java.lang.String targetURL, int targetPort, java.lang.String callbackMethod, java.lang.Object[] args)
          Adds a task to travel to another context.
 void addTaskToSchedule(java.lang.String method, java.lang.Object[] args)
          Add a task consisting of calling a certain method.
 void afterCreation()
          Method called just after creating the agent on a certain context.
 void afterRemoval()
          Method called just after removing the agent from a certain context.
 boolean atHome()
          Gets if the agent is at home.
 void beforeCreation()
          Method called just before creating the agent on a certain context.
 void beforeRemoval()
          Method called just before removing the agent from a certain context.
 java.lang.Object callAgentMethod(java.lang.String agentName, java.lang.String methodName)
          This method invokes a method of the agent.
 java.lang.Object callAgentMethod(java.lang.String agentName, java.lang.String methodName, java.lang.Object[] args)
          This method invokes a method of the agent.
 springs.communication.FutureResult callAgentMethodAsynchronously(java.lang.String agentName, java.lang.String methodName)
          This method invokes a method of the agent asynchronously.
 springs.communication.FutureResult callAgentMethodAsynchronously(java.lang.String agentName, java.lang.String methodName, java.lang.Object[] args)
          This method invokes a method of the agent asynchronously.
 void callback()
          It executes the callback method after a travel to a new computer.
 void checkpoint()
          Checkpoints the agent.
 springs.context.ContextAddress getAddress()
          Gets the address of the agent.
 long getAgentInitializationTime()
          Gets the millis elapsed in the initialization of the agent.
 boolean getAgentMoving()
          Gets whether the agent is moving.
protected  java.lang.Object[] getArgsCallbackMethod()
          Gets the arguments of the callback method.
protected  java.lang.String getCallbackMethod()
          Gets the name of the callback method.
 java.lang.String getCodebase()
          Gets the codebase for the agent, used if the agent travels to another context and some of the classes it uses there are not available.
 springs.context.ContextInterfaceForAgents getContextInterfaceForAgents()
          Gets an interface to the local context.
 java.lang.String getContextName()
          Gets the name of the agent's context.
 springs.context.ContextAddress getHomeAddress()
          Gets the home address of the agent.
 java.lang.String getHostname()
          Gets the hostname of the agent.
 java.util.Vector getLocationServers()
          Gets the locationServers for the agent.
 long getMillisStay()
           
 long getMillisWhenCreated()
           
 java.lang.String getName()
          Gets the name of the agent.
 java.lang.String getNameWithContext()
          Gets the name of the agent, with information about the context.
 int getNumObservers()
          Gets the number of observers of the agent.
 java.util.Vector getObservers()
          Gets the observers of the agent.
 java.util.Vector getObserversAddresses()
          Obtains the addresses of the observers of this agent.
 int getPort()
          Gets the port of the agent.
 springs.agent.Schedule getSchedule()
          Return the agent's schedule.
 int getSequenceNumberForAddressUpdateMessages()
          Obtains a relative indicator used to timestamp messages that update the address of the agent.
 java.lang.String getURL()
          Gets the URL of the agent.
 void goHome()
          Moves the agent to its home context (the context where it was created the first time).
 void goHome(java.lang.String callbackMethod)
          Moves the agent to its home context (the context where it was created the first time).
 void goHome(java.lang.String callbackMethod, java.lang.Object[] args)
          Moves the agent to its home context (the context where it was created the first time).
 java.lang.Object handleMessage(springs.communication.Message msg)
          By default, a message is ignored.
protected  boolean hasCallbackMethod()
          Checks if the agent has set a callback method to execute when arriving at a destination.
 void increaseSequenceNumberForAddressUpdateMessages(int increase)
          Increases the relative indicator used to timestamp messages that update the address of the agent.
 void initialization()
          This method is executed only the first time the agent is created.
 void initializationAfterMovement()
          This method is executed every time after a movement of the agent.
 boolean isSuspended()
          Obtains if the agent is suspended.
 boolean justCreatedForTheFirstTime()
          Checks if the agent has just been created for the first time.
 void main()
          Default callback method.
 boolean moreTasksInSchedule()
          Checks if the agent has more tasks in its schedule.
 void moveTo(springs.context.ContextAddress contextAddress)
          Moves the agent to another context.
 void moveTo(springs.context.ContextAddress contextAddress, java.lang.String callbackMethod)
          Moves the agent to another context.
 void moveTo(springs.context.ContextAddress contextAddress, java.lang.String callbackMethod, java.lang.Object[] args)
          Moves the agent to another context.
 void moveTo(java.lang.String contextName)
          Moves the agent to another context.
 void moveTo(java.lang.String contextName, java.lang.String callbackMethod)
          Moves the agent to another context.
 void moveTo(java.lang.String contextName, java.lang.String callbackMethod, java.lang.Object[] args)
          Moves the agent to another context.
 void moveToURL(java.lang.String url)
          Moves the agent to another context.
 void moveToURL(java.lang.String url, int port)
          Moves the agent to another context.
 void moveToURL(java.lang.String url, int port, java.lang.String callbackMethod)
          Moves the agent to another context.
 void moveToURL(java.lang.String url, int port, java.lang.String callbackMethod, java.lang.Object[] args)
          Moves the agent to another context.
 void postArrival()
          It executes after the agent has arrived at the destination.
 void postDeparture()
          It executes on the original stale object at the source, and is typically defined to perform activities such as removing the stale object from persistence.
 void preArrival()
          This method is executed on the copy of the object at the destination.
 void preDeparture(java.lang.String originContext, java.lang.String targetContext)
          This method is executed on the original object at the source.
 java.lang.Object receiveMethodCall(java.lang.String methodName, java.lang.Object[] args)
          Creates an agent.
 void recordEndStay()
           
 void recordStartStay()
           
 void remove()
          Removes the agent.
 void removeObserver(java.lang.String observer)
          Removes an observer for the agent.
 springs.communication.FutureResult sendAsynchronousMessage(java.lang.String agentName, springs.communication.Message message)
          This method sends a message to the agent, asynchronously.
 java.lang.Object sendMessage(java.lang.String agentName, springs.communication.Message message)
          This method sends a message to the agent, synchronously.
 java.lang.Object sendMessage(java.lang.String agentName, springs.communication.Message message, boolean asynchronous)
          This method sends a message to the agent.
 void setAgentInitializationTime(long millis)
          Sets the millis elapsed in the initialization of the agent.
 void setAgentMoving(boolean moving)
          Sets whether the agent is moving.
 void setCacheReferences(boolean cacheRefs)
          Sets whether references to agents should be cached.
protected  void setCallbackMethod(java.lang.String callbackMethod)
          Sets the name of the callback method.
 void setCodebase(java.lang.String codebase)
          Sets the codebase for the agent, that it will be used if the agent travels to another context and some of the classes it uses there are not available.
 void setContextInterfaceForAgents(springs.context.ContextInterfaceForAgents contextInterface)
          Sets the interface to the agent's context.
 void setHomeAddress(springs.context.ContextAddress homeAddress)
          Sets the home address of the agent.
 void setLocationServers(java.util.Vector locationServers)
          Sets the location servers for the agent.
 void setName(java.lang.String name)
          Sets the name of the agent.
 void start()
          Starts the agent execution.
 void suspend()
          Suspends the agent execution.
 springs.agent.Task takeNextTask()
          Obtains the next task to be executed by the agent, from the schedule.
private  void unknownContextException(java.lang.String contextName)
          Throws an exception saying that the given context is unknown.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_observers

private java.util.Set _observers
The observers and locationServers of the agent. For each agent in the current context, stores the addresses of the observer and the locationServer contexts. A context can appear in both lists and for the same agent at the same time, corresponding to a context that is both observer and locationServer for a certain agent.

See Also:
Set, Vector

_locationServers

private java.util.Vector _locationServers

_schedule

private springs.agent.Schedule _schedule
The agent's schedule.

See Also:
Schedule

_codebase

private java.lang.String _codebase
A codebase for the agent.

See Also:
String

_interfaceToLocalContext

private transient springs.context.ContextInterfaceForAgents _interfaceToLocalContext
An interface to the local context.

See Also:
ContextInterfaceForAgents

_name

private java.lang.String _name
The name of the agent.

See Also:
String

_homeAddress

private springs.context.ContextAddress _homeAddress
The home address of the agent.

See Also:
ContextAddress

_callbackMethod

private java.lang.String _callbackMethod
The callback method to execute when arriving at a destination (null if any).

See Also:
String

_argsCallbackMethod

private java.lang.Object[] _argsCallbackMethod
The arguments callback method to execute when arriving at a destination (null if any).

See Also:
Object

_observersAddresses

private java.util.Vector _observersAddresses
The addresses of the contexts that "observe" this agent.

See Also:
Vector, ContextAddress

_agentMoving

private boolean _agentMoving
A boolean indicating whether the agent is moving or not.


_lockAgentMoving

private java.lang.Boolean _lockAgentMoving

_justCreatedForTheFirstTime

private boolean _justCreatedForTheFirstTime
A boolean indicating whether the agent has just been created for the first time.


_registered

private boolean _registered
A boolean indicating whether the agent has already register or not.


_numberOfJumps

protected int _numberOfJumps
The number of jumps performed by the agent.


_cacheRefs

private boolean _cacheRefs
A boolean indicating whether references to agents should be cached (and automatically updated) by the context.


_initializationTime

private long _initializationTime
Millis elapsed initialization the agent (for debugging and statistics).


_millisAtCreation

private long _millisAtCreation
A timestamp to identify the time instant when the agent was created.


_millisStartStay

private long _millisStartStay
The milliseconds when the agent starts its stay in a certain context.


_lastMillisStays

private long[] _lastMillisStays

_numStays

private int _numStays
Constructor Detail

SpringsAgent_RMIImpl

public SpringsAgent_RMIImpl()
                     throws java.rmi.RemoteException
Constructor.

Throws:
java.rmi.RemoteException - if error.
See Also:
RemoteException
Method Detail

getMillisWhenCreated

public long getMillisWhenCreated()
Specified by:
getMillisWhenCreated in interface SpringsAgent

recordStartStay

public void recordStartStay()
Specified by:
recordStartStay in interface SpringsAgent

recordEndStay

public void recordEndStay()
Specified by:
recordEndStay in interface SpringsAgent

getMillisStay

public long getMillisStay()
Specified by:
getMillisStay in interface SpringsAgent

setAgentInitializationTime

public void setAgentInitializationTime(long millis)
Description copied from interface: SpringsAgent
Sets the millis elapsed in the initialization of the agent.

Specified by:
setAgentInitializationTime in interface SpringsAgent
Parameters:
millis - the millis.

getAgentInitializationTime

public long getAgentInitializationTime()
Description copied from interface: SpringsAgent
Gets the millis elapsed in the initialization of the agent.

Specified by:
getAgentInitializationTime in interface SpringsAgent
Returns:
the millis.

setLocationServers

public void setLocationServers(java.util.Vector locationServers)
Description copied from interface: SpringsAgent
Sets the location servers for the agent.

Specified by:
setLocationServers in interface SpringsAgent

getLocationServers

public java.util.Vector getLocationServers()
Description copied from interface: SpringsAgent
Gets the locationServers for the agent.

Specified by:
getLocationServers in interface SpringsAgent
Returns:
the names of the locationServer contexts.
See Also:
Vector

getObservers

public java.util.Vector getObservers()
Description copied from interface: SpringsAgent
Gets the observers of the agent.

Specified by:
getObservers in interface SpringsAgent
Returns:
the names of the observer contexts.
See Also:
Vector

getNumObservers

public int getNumObservers()
Description copied from interface: SpringsAgent
Gets the number of observers of the agent.

Specified by:
getNumObservers in interface SpringsAgent
Returns:
the number of observers.

setCacheReferences

public void setCacheReferences(boolean cacheRefs)
Description copied from interface: SpringsAgent
Sets whether references to agents should be cached.

Specified by:
setCacheReferences in interface SpringsAgent
Parameters:
cacheRefs - a boolean indicating that.

getSequenceNumberForAddressUpdateMessages

public int getSequenceNumberForAddressUpdateMessages()
Description copied from interface: SpringsAgent
Obtains a relative indicator used to timestamp messages that update the address of the agent.

Specified by:
getSequenceNumberForAddressUpdateMessages in interface SpringsAgent
Returns:
the indicator.

increaseSequenceNumberForAddressUpdateMessages

public void increaseSequenceNumberForAddressUpdateMessages(int increase)
Description copied from interface: SpringsAgent
Increases the relative indicator used to timestamp messages that update the address of the agent.

Specified by:
increaseSequenceNumberForAddressUpdateMessages in interface SpringsAgent
Parameters:
increase - the increase.

initialization

public void initialization()
                    throws java.lang.Exception
Description copied from interface: SpringsAgent
This method is executed only the first time the agent is created. The programmer can override this method to include initialization code. However, make sure to call first the method in the superclass!

Specified by:
initialization in interface SpringsAgent
Throws:
java.lang.Exception - if error.
See Also:
Exception

initializationAfterMovement

public void initializationAfterMovement()
                                 throws java.lang.Exception
Description copied from interface: SpringsAgent
This method is executed every time after a movement of the agent. The programmer can override this method to include initialization code required after a movement. However, make sure to call first the method in the superclass!

Specified by:
initializationAfterMovement in interface SpringsAgent
Throws:
java.lang.Exception - if error.
See Also:
Exception

justCreatedForTheFirstTime

public boolean justCreatedForTheFirstTime()
Description copied from interface: SpringsAgent
Checks if the agent has just been created for the first time.

Specified by:
justCreatedForTheFirstTime in interface SpringsAgent
Returns:
a boolean indicating that.

setCodebase

public void setCodebase(java.lang.String codebase)
Description copied from interface: SpringsAgent
Sets the codebase for the agent, that it will be used if the agent travels to another context and some of the classes it uses there are not available.

Specified by:
setCodebase in interface SpringsAgent
Parameters:
codebase - the codebase.
See Also:
MalformedURLException

getCodebase

public java.lang.String getCodebase()
Description copied from interface: SpringsAgent
Gets the codebase for the agent, used if the agent travels to another context and some of the classes it uses there are not available.

Specified by:
getCodebase in interface SpringsAgent
Returns:
codebase the codebase.
See Also:
String

getContextInterfaceForAgents

public springs.context.ContextInterfaceForAgents getContextInterfaceForAgents()
Description copied from interface: SpringsAgent
Gets an interface to the local context.

Specified by:
getContextInterfaceForAgents in interface SpringsAgent
Returns:
an interface to the context.
See Also:
ContextInterfaceForAgents

setContextInterfaceForAgents

public void setContextInterfaceForAgents(springs.context.ContextInterfaceForAgents contextInterface)
Description copied from interface: SpringsAgent
Sets the interface to the agent's context.

Specified by:
setContextInterfaceForAgents in interface SpringsAgent
Parameters:
contextInterface - an interface to the agent's context.
See Also:
ContextInterfaceForAgents

getHomeAddress

public springs.context.ContextAddress getHomeAddress()
Description copied from interface: SpringsAgent
Gets the home address of the agent.

Specified by:
getHomeAddress in interface SpringsAgent
Returns:
the home address of the agent.
See Also:
ContextAddress

setHomeAddress

public void setHomeAddress(springs.context.ContextAddress homeAddress)
Description copied from interface: SpringsAgent
Sets the home address of the agent.

Specified by:
setHomeAddress in interface SpringsAgent
Parameters:
homeAddress - the home address of the agent.
See Also:
ContextAddress

getAddress

public springs.context.ContextAddress getAddress()
Description copied from interface: SpringsAgent
Gets the address of the agent.

Specified by:
getAddress in interface SpringsAgent
Returns:
the address of the agent.
See Also:
ContextAddress

getHostname

public java.lang.String getHostname()
Description copied from interface: SpringsAgent
Gets the hostname of the agent.

Specified by:
getHostname in interface SpringsAgent
Returns:
the hostname of the agent.
See Also:
String

getContextName

public java.lang.String getContextName()
Description copied from interface: SpringsAgent
Gets the name of the agent's context.

Specified by:
getContextName in interface SpringsAgent
Returns:
the name of the agent's context.
See Also:
String

getURL

public java.lang.String getURL()
Description copied from interface: SpringsAgent
Gets the URL of the agent.

Specified by:
getURL in interface SpringsAgent
Returns:
the URL of the agent.
See Also:
String

getPort

public int getPort()
Description copied from interface: SpringsAgent
Gets the port of the agent.

Specified by:
getPort in interface SpringsAgent
Returns:
the port of the agent's context.
See Also:
ContextAddress

atHome

public boolean atHome()
Description copied from interface: SpringsAgent
Gets if the agent is at home.

Specified by:
atHome in interface SpringsAgent
Returns:
a boolean that indicates whether the agent is at its home context or not.

getName

public java.lang.String getName()
Description copied from interface: SpringsAgent
Gets the name of the agent.

Specified by:
getName in interface SpringsAgent
Returns:
the name of the agent.
See Also:
String

getNameWithContext

public java.lang.String getNameWithContext()
Description copied from interface: SpringsAgent
Gets the name of the agent, with information about the context.

Specified by:
getNameWithContext in interface SpringsAgent
Returns:
the name of the agent, with information about the context.
See Also:
String

setName

public void setName(java.lang.String name)
Description copied from interface: SpringsAgent
Sets the name of the agent.

Specified by:
setName in interface SpringsAgent
Parameters:
name - the name.
See Also:
String

setAgentMoving

public void setAgentMoving(boolean moving)
Description copied from interface: SpringsAgent
Sets whether the agent is moving.

Specified by:
setAgentMoving in interface SpringsAgent
Parameters:
moving - a boolean indicating whether the agent is moving or not.

getAgentMoving

public boolean getAgentMoving()
Description copied from interface: SpringsAgent
Gets whether the agent is moving.

Specified by:
getAgentMoving in interface SpringsAgent
Returns:
a boolean indicating whether the agent is moving or not.

moveTo

public void moveTo(springs.context.ContextAddress contextAddress)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context. After the movement, the callback method main() will be called.

Specified by:
moveTo in interface SpringsAgent
Parameters:
contextAddress - the address of the target context.
Throws:
AgentMovementException - if the agent cannot be moved to the target address.
See Also:
ContextAddress, AgentMovementException

moveTo

public void moveTo(springs.context.ContextAddress contextAddress,
                   java.lang.String callbackMethod)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context.

Specified by:
moveTo in interface SpringsAgent
Parameters:
contextAddress - the address of the target context.
callbackMethod - the method to execute on arrival.
Throws:
AgentMovementException - if the agent cannot be moved to the target address.
See Also:
ContextAddress, AgentMovementException, String

moveTo

public void moveTo(springs.context.ContextAddress contextAddress,
                   java.lang.String callbackMethod,
                   java.lang.Object[] args)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context.

Specified by:
moveTo in interface SpringsAgent
Parameters:
contextAddress - the address of the target context.
callbackMethod - the method to execute on arrival.
args - the arguments of the callback method.
Throws:
AgentMovementException - if the agent cannot be moved to the target address.
See Also:
ContextAddress, AgentMovementException, String, Object

moveToURL

public void moveToURL(java.lang.String url)
               throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context. After the movement, the callback method main() will be called.

Specified by:
moveToURL in interface SpringsAgent
Parameters:
url - the URL of the target context, including the port number.
Throws:
AgentMovementException - if the agent cannot move to the target address.
See Also:
ContextAddress, AgentMovementException

moveToURL

public void moveToURL(java.lang.String url,
                      int port)
               throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context. After the movement, the callback method main() will be called.

Specified by:
moveToURL in interface SpringsAgent
Parameters:
url - the URL of the target context.
port - the port of the target context.
Throws:
AgentMovementException - if the agent cannot move to the target address.
See Also:
ContextAddress, AgentMovementException

moveToURL

public void moveToURL(java.lang.String url,
                      int port,
                      java.lang.String callbackMethod)
               throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context.

Specified by:
moveToURL in interface SpringsAgent
Parameters:
url - the URL of the target context.
port - the port of the target context.
callbackMethod - the method to execute on arrival.
Throws:
AgentMovementException - if the agent cannot move to the target address.
See Also:
ContextAddress, AgentMovementException, String

moveToURL

public void moveToURL(java.lang.String url,
                      int port,
                      java.lang.String callbackMethod,
                      java.lang.Object[] args)
               throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context.

Specified by:
moveToURL in interface SpringsAgent
Parameters:
url - the URL of the target context.
port - the port of the target context.
callbackMethod - the method to execute on arrival.
args - the arguments of the callback method.
Throws:
AgentMovementException - if the agent cannot move to the target address.
See Also:
ContextAddress, AgentMovementException, String, Object

moveTo

public void moveTo(java.lang.String contextName)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context. After the movement, the callback method main() will be called.

Specified by:
moveTo in interface SpringsAgent
Parameters:
contextName - the name of the context.
Throws:
AgentMovementException - if the agent cannot move to the target context.
See Also:
String, AgentMovementException

moveTo

public void moveTo(java.lang.String contextName,
                   java.lang.String callbackMethod)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context.

Specified by:
moveTo in interface SpringsAgent
Parameters:
contextName - the name of the context.
callbackMethod - the method to execute on arrival.
Throws:
AgentMovementException - if the agent cannot move to the target context.
See Also:
String, AgentMovementException

moveTo

public void moveTo(java.lang.String contextName,
                   java.lang.String callbackMethod,
                   java.lang.Object[] args)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to another context.

Specified by:
moveTo in interface SpringsAgent
Parameters:
contextName - the name of the context.
callbackMethod - the method to execute on arrival.
args - the arguments of the callback method.
Throws:
AgentMovementException - if the agent cannot move to the target context.
See Also:
String, AgentMovementException

goHome

public void goHome()
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to its home context (the context where it was created the first time). After the movement, the callback method main() will be called.

Specified by:
goHome in interface SpringsAgent
Throws:
AgentMovementException - if the agent cannot move to the target address.
See Also:
AgentMovementException

goHome

public void goHome(java.lang.String callbackMethod)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to its home context (the context where it was created the first time).

Specified by:
goHome in interface SpringsAgent
Parameters:
callbackMethod - the method to execute on arrival.
Throws:
AgentMovementException - if the agent cannot move to the target address.
See Also:
String, AgentMovementException

goHome

public void goHome(java.lang.String callbackMethod,
                   java.lang.Object[] args)
            throws AgentMovementException
Description copied from interface: SpringsAgent
Moves the agent to its home context (the context where it was created the first time).

Specified by:
goHome in interface SpringsAgent
Parameters:
callbackMethod - the method to execute on arrival.
args - the arguments of the callback method.
Throws:
AgentMovementException - if the agent cannot move to the target address.
See Also:
String, Object, AgentMovementException

callback

public void callback()
              throws MethodCallException
Description copied from interface: SpringsAgent
It executes the callback method after a travel to a new computer. If no callback method has been set, the method main() will be called.

Specified by:
callback in interface SpringsAgent
Throws:
MethodCallException - if the callback method cannot be invoked.
See Also:
MethodCallException

suspend

public void suspend()
Description copied from interface: SpringsAgent
Suspends the agent execution.

Specified by:
suspend in interface SpringsAgent

isSuspended

public boolean isSuspended()
Description copied from interface: SpringsAgent
Obtains if the agent is suspended.

Specified by:
isSuspended in interface SpringsAgent
Returns:
a boolean indicating whether the agent is suspended.

checkpoint

public void checkpoint()
Description copied from interface: SpringsAgent
Checkpoints the agent.

Specified by:
checkpoint in interface SpringsAgent

addTaskToSchedule

public void addTaskToSchedule(java.lang.String targetURL,
                              int targetPort)
Description copied from interface: SpringsAgent
Adds a task to travel to another context.

Specified by:
addTaskToSchedule in interface SpringsAgent
Parameters:
targetURL - the target URL.
targetPort - the target port.
See Also:
String

addTaskToSchedule

public void addTaskToSchedule(java.lang.String targetURL,
                              int targetPort,
                              java.lang.String callbackMethod)
Description copied from interface: SpringsAgent
Adds a task to travel to another context.

Specified by:
addTaskToSchedule in interface SpringsAgent
Parameters:
targetURL - the target URL.
targetPort - the target port.
callbackMethod - the callback method.
See Also:
String

addTaskToSchedule

public void addTaskToSchedule(java.lang.String targetURL,
                              int targetPort,
                              java.lang.String callbackMethod,
                              java.lang.Object[] args)
Description copied from interface: SpringsAgent
Adds a task to travel to another context.

Specified by:
addTaskToSchedule in interface SpringsAgent
Parameters:
targetURL - the target URL.
targetPort - the target port.
callbackMethod - the callback method.
args - the arguments for the callback method.
See Also:
String, Object

addTaskToSchedule

public void addTaskToSchedule(java.lang.String method)
Description copied from interface: SpringsAgent
Add a task consisting of calling a certain method.

Specified by:
addTaskToSchedule in interface SpringsAgent
Parameters:
method - the method.
See Also:
String

addTaskToSchedule

public void addTaskToSchedule(java.lang.String method,
                              java.lang.Object[] args)
Description copied from interface: SpringsAgent
Add a task consisting of calling a certain method.

Specified by:
addTaskToSchedule in interface SpringsAgent
Parameters:
method - the method.
args - the arguments for the method.
See Also:
String, Object

takeNextTask

public springs.agent.Task takeNextTask()
Description copied from interface: SpringsAgent
Obtains the next task to be executed by the agent, from the schedule.

Specified by:
takeNextTask in interface SpringsAgent
Returns:
the next task.
See Also:
Task

moreTasksInSchedule

public boolean moreTasksInSchedule()
Description copied from interface: SpringsAgent
Checks if the agent has more tasks in its schedule.

Specified by:
moreTasksInSchedule in interface SpringsAgent
Returns:
a boolean indicating that.

getSchedule

public springs.agent.Schedule getSchedule()
Description copied from interface: SpringsAgent
Return the agent's schedule.

Specified by:
getSchedule in interface SpringsAgent
Returns:
the schedule.
See Also:
Schedule

handleMessage

public java.lang.Object handleMessage(springs.communication.Message msg)
By default, a message is ignored. Any other behaviour should be implemented in the appropriate subclass.

Specified by:
handleMessage in interface SpringsAgent
Parameters:
msg - the message.
Returns:
the result of handling the message.
See Also:
Object, Message

removeObserver

public void removeObserver(java.lang.String observer)
Description copied from interface: ISpringsAgent_RMIImpl
Removes an observer for the agent.

Specified by:
removeObserver in interface SpringsAgent
Parameters:
observer - the observer.
See Also:
String

addObserver

public void addObserver(java.lang.String observer)
Description copied from interface: ISpringsAgent_RMIImpl
Adds a observer for the agent.

Specified by:
addObserver in interface ISpringsAgent_RMIImpl
Parameters:
observer - the observer.
See Also:
String

receiveMethodCall

public java.lang.Object receiveMethodCall(java.lang.String methodName,
                                          java.lang.Object[] args)
                                   throws MethodCallException
Description copied from interface: ISpringsAgent_RMIImpl
Creates an agent.

Specified by:
receiveMethodCall in interface SpringsAgent
Parameters:
methodName - the name of the method.
args - the arguments.
Returns:
the result.
MethodCallException
See Also:
Object, String, MethodCallException, RemoteException

main

public void main()
Description copied from interface: SpringsAgent
Default callback method.

Specified by:
main in interface SpringsAgent

start

public void start()
Description copied from interface: SpringsAgent
Starts the agent execution.

Specified by:
start in interface SpringsAgent

remove

public void remove()
            throws RemovalException
Description copied from interface: SpringsAgent
Removes the agent.

Specified by:
remove in interface SpringsAgent
Throws:
RemovalException - if error.
See Also:
RemovalException

getObserversAddresses

public java.util.Vector getObserversAddresses()
Description copied from interface: SpringsAgent
Obtains the addresses of the observers of this agent.

Specified by:
getObserversAddresses in interface SpringsAgent
Returns:
the addresses of the observers.
See Also:
Vector

beforeCreation

public void beforeCreation()
Description copied from interface: SpringsAgent
Method called just before creating the agent on a certain context.

Specified by:
beforeCreation in interface SpringsAgent

afterCreation

public void afterCreation()
Description copied from interface: SpringsAgent
Method called just after creating the agent on a certain context.

Specified by:
afterCreation in interface SpringsAgent

beforeRemoval

public void beforeRemoval()
Description copied from interface: SpringsAgent
Method called just before removing the agent from a certain context.

Specified by:
beforeRemoval in interface SpringsAgent

afterRemoval

public void afterRemoval()
Description copied from interface: SpringsAgent
Method called just after removing the agent from a certain context.

Specified by:
afterRemoval in interface SpringsAgent

postArrival

public void postArrival()
Description copied from interface: SpringsAgent
It executes after the agent has arrived at the destination. At this point the movement is deemed successful.

Specified by:
postArrival in interface SpringsAgent

postDeparture

public void postDeparture()
Description copied from interface: SpringsAgent
It executes on the original stale object at the source, and is typically defined to perform activities such as removing the stale object from persistence.

Specified by:
postDeparture in interface SpringsAgent

preArrival

public void preArrival()
Description copied from interface: SpringsAgent
This method is executed on the copy of the object at the destination.

Specified by:
preArrival in interface SpringsAgent

preDeparture

public void preDeparture(java.lang.String originContext,
                         java.lang.String targetContext)
Description copied from interface: SpringsAgent
This method is executed on the original object at the source.

Specified by:
preDeparture in interface SpringsAgent
Parameters:
originContext - the origin context.
targetContext - the target context.
See Also:
String

hasCallbackMethod

protected boolean hasCallbackMethod()
Checks if the agent has set a callback method to execute when arriving at a destination.

Returns:
a boolean indicating that.

getCallbackMethod

protected java.lang.String getCallbackMethod()
Gets the name of the callback method.

Returns:
the name of the callback method (null if any).
See Also:
String

setCallbackMethod

protected void setCallbackMethod(java.lang.String callbackMethod)
Sets the name of the callback method.

Returns:
the name of the callback method (null if any).
See Also:
String

getArgsCallbackMethod

protected java.lang.Object[] getArgsCallbackMethod()
Gets the arguments of the callback method.

Returns:
the arguments of the callback method (null if any).
See Also:
Object

callAgentMethod

public java.lang.Object callAgentMethod(java.lang.String agentName,
                                        java.lang.String methodName,
                                        java.lang.Object[] args)
                                 throws MethodCallException,
                                        CommunicationException
Description copied from interface: SpringsAgent
This method invokes a method of the agent.

Specified by:
callAgentMethod in interface SpringsAgent
Parameters:
agentName - the name of the target agent.
methodName - the name of the method.
args - the arguments to the method.
Returns:
the result of the method invocation.
Throws:
MethodCallException - if the invocation fails.
CommunicationException - if there is a communication error.
See Also:
MethodCallException, CommunicationException, String, Object

callAgentMethod

public java.lang.Object callAgentMethod(java.lang.String agentName,
                                        java.lang.String methodName)
                                 throws MethodCallException,
                                        CommunicationException
Description copied from interface: SpringsAgent
This method invokes a method of the agent.

Specified by:
callAgentMethod in interface SpringsAgent
Parameters:
agentName - the name of the target agent.
methodName - the name of the method.
Returns:
the result of the method invocation.
Throws:
MethodCallException - if the invocation fails.
CommunicationException - if there is a communication error.
See Also:
CommunicationException, MethodCallException, String, Object

callAgentMethodAsynchronously

public springs.communication.FutureResult callAgentMethodAsynchronously(java.lang.String agentName,
                                                                        java.lang.String methodName,
                                                                        java.lang.Object[] args)
                                                                 throws AgentReferenceException
Description copied from interface: SpringsAgent
This method invokes a method of the agent asynchronously.

Specified by:
callAgentMethodAsynchronously in interface SpringsAgent
Parameters:
agentName - the name of the target agent.
methodName - the name of the method.
args - the arguments to the method.
Returns:
a placeholder for the future result of the invocation.
Throws:
AgentReferenceException - if error.
See Also:
FutureResult, AgentReferenceException, String, Object

callAgentMethodAsynchronously

public springs.communication.FutureResult callAgentMethodAsynchronously(java.lang.String agentName,
                                                                        java.lang.String methodName)
                                                                 throws AgentReferenceException
Description copied from interface: SpringsAgent
This method invokes a method of the agent asynchronously.

Specified by:
callAgentMethodAsynchronously in interface SpringsAgent
Parameters:
agentName - the name of the target agent.
methodName - the name of the method.
Returns:
a placeholder for the future result of the invocation.
Throws:
AgentReferenceException - if error.
See Also:
FutureResult, AgentReferenceException, String, Object

sendMessage

public java.lang.Object sendMessage(java.lang.String agentName,
                                    springs.communication.Message message)
                             throws CommunicationException
Description copied from interface: SpringsAgent
This method sends a message to the agent, synchronously.

Specified by:
sendMessage in interface SpringsAgent
Parameters:
agentName - the name of the target agent.
message - the message.
Returns:
a possible result from the target agent.
Throws:
CommunicationException - if there is a communication error.
See Also:
Message, if there is a communication error.

sendAsynchronousMessage

public springs.communication.FutureResult sendAsynchronousMessage(java.lang.String agentName,
                                                                  springs.communication.Message message)
                                                           throws CommunicationException
Description copied from interface: SpringsAgent
This method sends a message to the agent, asynchronously.

Specified by:
sendAsynchronousMessage in interface SpringsAgent
Parameters:
agentName - the name of the target agent.
message - the message.
Returns:
a placeholder for the future result from the target agent.
Throws:
CommunicationException - if there is a communication error.
See Also:
FutureResult, Message

sendMessage

public java.lang.Object sendMessage(java.lang.String agentName,
                                    springs.communication.Message message,
                                    boolean asynchronous)
                             throws CommunicationException
Description copied from interface: SpringsAgent
This method sends a message to the agent.

Specified by:
sendMessage in interface SpringsAgent
Parameters:
agentName - the name of the target agent.
message - the message.
asynchronous - a boolean indicating whether the message should be sent asynchronously or not.
Returns:
a possible result from the target agent if the message is sent synchronously; a placeholder for the future result if it is sent asynchronously.
Throws:
CommunicationException - if there is a communication error.
See Also:
Message

unknownContextException

private void unknownContextException(java.lang.String contextName)
                              throws AgentMovementException
Throws an exception saying that the given context is unknown.

Parameters:
contextName - the name of the context.
Throws:
AgentMovementException.
AgentMovementException
See Also:
String, AgentMovementException