antsim.nestor
Class LocalNest

java.lang.Object
  |
  +--antsim.nestor.LocalNest
All Implemented Interfaces:
AntListener, Clearable, Nest, Remote, SimulatedNest
Direct Known Subclasses:
LocalGeneticNest

public class LocalNest
extends Object
implements SimulatedNest, AntListener

A Nest class collects the components of a Nest site: (i) a AntView object, which is the view of a Nest for an Ant; (ii) a Gate object, which manage the communication between nests; (iii) an Manager, i.e. the object which manage the activities performed by different agents.

Implementation note: this implementation is supposed to be used as simple implementation of Nest in the off-line environment. Here, we assume that the Manager object used is single-threaded; in this way, we avoid the costs of synchronized methods.

Version:
$Revision: 1.5 $
Author:
Alberto Montresor

Field Summary
static String PAR_TTL
          String name of the parameter used to determine the ttl used by these nests.
 
Fields inherited from interface anthill.nest.Nest
NAME
 
Constructor Summary
LocalNest(Factory factory, String name)
          Constructs a new nest.
 
Method Summary
 void addAntNeighbour(NestId aid)
          Add the identifier of a new neighbour nest to the set of neighbours known to this Nest, on behalf of an ant.
 void addClientNeighbour(NestId aid)
          Add the identifier of a new neighbour nest to the set of neighbours known to this Nest, on behalf of an Nest client.
 void clear()
          Restores the object to its initial state.
 ResourceManager createResourceManager(String name, String species)
          Returns a reference to the resource manager identified by the given name.
 void deliver(AntDescriptor desc)
          Receive an agent from outside and deliver it to the to the activity manager.
 Manager getManager()
          Return the Manager associated to this Nest
 Neighbour[] getNeighbours()
          Return the neighbours known to this Nest
 NestId getNestId()
          Return the identifier of this Nest
 ResourceManager getResourceManager(String name, String species)
          Returns a reference to the resource manager identified by the given name.
 void leave()
          Forces the nest to exit.
 void removeNeighbour(NestId aid)
          Remove a neighbour identifier from the set of neighbour
 void request(RequestId rid, Object request, ResponseListener listener)
          Accepts a request from the nest user.
 String toString()
          FIXME ....
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PAR_TTL

public static final String PAR_TTL
String name of the parameter used to determine the ttl used by these nests.

See Also:
Constant Field Values
Constructor Detail

LocalNest

public LocalNest(Factory factory,
                 String name)
Constructs a new nest.

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

clear

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

Specified by:
clear in interface Clearable

deliver

public void deliver(AntDescriptor desc)
Receive an agent from outside and deliver it to the to the activity manager.

Specified by:
deliver in interface AntListener
Parameters:
desc - the ant descriptor of the received ant

leave

public void leave()
Forces the nest to exit.

Specified by:
leave in interface SimulatedNest

getNestId

public NestId getNestId()
Return the identifier of this Nest

Specified by:
getNestId in interface Nest

getManager

public Manager getManager()
Return the Manager associated to this Nest

Specified by:
getManager in interface SimulatedNest

request

public void request(RequestId rid,
                    Object request,
                    ResponseListener listener)
Accepts a request from the nest user. Possible responses will be returned to the specified listener. One or more ants are generated and assigned to the request. Accept a resource request originated by an anthill client. The resource to be searched is identified by name. The method returns immediately. When the resource is found, a Resource object will be returned to the specified resource listener.

Implementation note: If the resource can be found locally, the listener is immediately contacted. Otherwise, a new Ant is generated and is delivered to the ant manager.

Specified by:
request in interface Nest
Parameters:
request - the request to be performed
listener - The listener object which will be notified when the request is completed.
rid - the request identifier, created and managed by the invoker of this method.

getResourceManager

public ResourceManager getResourceManager(String name,
                                          String species)
Returns a reference to the resource manager identified by the given name.

Specified by:
getResourceManager in interface Nest
Parameters:
name - the name of the manager to obtain a reference to
species - the name of the ant species to which the manager is associated
Returns:
a reference to the requested resource manager, or null if no such resource manager is found.

createResourceManager

public ResourceManager createResourceManager(String name,
                                             String species)
                                      throws ResourceManagerException
Returns a reference to the resource manager identified by the given name.

Specified by:
createResourceManager in interface Nest
Parameters:
name - the name of the manager to obtain a reference to
species - the name of the ant species to which the manager is associated
Returns:
a reference to the requested resource manager, or null if no such resource manager is found.
ResourceManagerException

addClientNeighbour

public void addClientNeighbour(NestId aid)
Add the identifier of a new neighbour nest to the set of neighbours known to this Nest, on behalf of an Nest client.

Specified by:
addClientNeighbour in interface Nest
Parameters:
aid - neighbour identifier

addAntNeighbour

public void addAntNeighbour(NestId aid)
Add the identifier of a new neighbour nest to the set of neighbours known to this Nest, on behalf of an ant.

Specified by:
addAntNeighbour in interface Nest
Parameters:
aid - neighbour identifier

removeNeighbour

public void removeNeighbour(NestId aid)
Remove a neighbour identifier from the set of neighbour

Specified by:
removeNeighbour in interface Nest
Parameters:
aid - neighbour identifier

getNeighbours

public Neighbour[] getNeighbours()
Return the neighbours known to this Nest

Specified by:
getNeighbours in interface Nest

toString

public String toString()
FIXME ....

Overrides:
toString in class Object