antsim.nestor
Class LocalGate

java.lang.Object
  |
  +--antsim.nestor.LocalGate
All Implemented Interfaces:
Clearable, Gate

public class LocalGate
extends Object
implements Gate

Class LocalGate is the implementation of Gate to be used during off-line simulations. Communication among different LocalGates is based on local method invocations.

Version:
$Revision: 1.3 $
Author:
Alberto Montresor

Field Summary
 
Fields inherited from interface anthill.nest.Gate
NAME
 
Constructor Summary
LocalGate(Factory factory, String name)
          Initializes a new LocalGate by creating a new local nest identifier.
 
Method Summary
 void clear()
          Restores the object to its initial state.
 NestId getNestId()
          Returns the identifier of the Nest to which this gate is associated.
 void send(NestId dest, Ant ant, int ttl)
          Sends an ant to the specified nest.
 void setAntListener(AntListener listener)
          Sets the ant listener, i.e. the object that will accept the ants coming from other nests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalGate

public LocalGate(Factory factory,
                 String name)
Initializes a new LocalGate by creating a new local nest identifier.

Parameters:
factory - the factory to be used to read configuration arguments and to create other configurable objects
name - the name that is associated to this instance in the configuration file
Method Detail

getNestId

public NestId getNestId()
Returns the identifier of the Nest to which this gate is associated.

Specified by:
getNestId in interface Gate

setAntListener

public void setAntListener(AntListener listener)
Sets the ant listener, i.e. the object that will accept the ants coming from other nests.

Specified by:
setAntListener in interface Gate
Parameters:
listener - the listener object that will accepts the ants coming from other nests

send

public void send(NestId dest,
                 Ant ant,
                 int ttl)
          throws ClassCastException,
                 IOException
Sends an ant to the specified nest. Both the nest identifier and the ant must be serializable or externalizable.

Specified by:
send in interface Gate
Throws:
ClassCastException - raised if the nest identifier does not belong to the expected class
IOException - raised if problems have occurred during serialization and sending

clear

public void clear()
Restores the object to its initial state.

Specified by:
clear in interface Clearable