anthill.nestor
Class LocalNest

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

public class LocalNest
extends java.lang.Object
implements Nest, 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.


Constructor Summary
LocalNest(Factory factory, int ttl)
          Constructs a new nest, by putting together a Storage (a resource database), a Gate (i.e. the basic API for communicating with other nests) and an Manager (i.e., a thread handler managing the agent execution).
 
Method Summary
 void addAntNeighbour(NestId aid)
          Add the identifier of a new neighbour anthill 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 anthill to the set of neighbours known to this Nest, on behalf of an Nest client.
 void clear()
          Restores the object to its initial state.
 void deliver(AntDescriptor desc)
          Receive an agent from outside and deliver it to the to the activity manager.
 NestId getId()
          Return the identifier of this Nest
 Manager getManager()
          Return the Manager associated to this Nest
 Neighbour[] getNeighbours()
          Return the neighbours known to this Nest
 java.lang.Object getPheromone(java.lang.Class cl)
          Return the pheromone associated to the link to this neighbour.
 void insert(Resource resource)
          Insert a new resource in this anthill.
 void removeNeighbour(NestId aid)
          Remove a neighbour identifier from the set of neighbour
 void request(java.lang.Object request, ResponseListener listener)
          Accepts a request from the nest user.
 void setPheromone(java.lang.Object pheromone, java.lang.Class cl)
          Return the pheromone associated to the link to this neighbour.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalNest

public LocalNest(Factory factory,
                 int ttl)
Constructs a new nest, by putting together a Storage (a resource database), a Gate (i.e. the basic API for communicating with other nests) and an Manager (i.e., a thread handler managing the agent execution).
Method Detail

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
Following copied from interface: anthill.nest.AntListener
Parameters:
sender - the identifier of the nest from which this ant has been received
desc - the ant descriptor of the received ant
Throws:
java.rmi.RemoteException - added to the throw clause to respect the conventions for remote interfaces.

getId

public NestId getId()
Return the identifier of this Nest
Specified by:
getId in interface Nest

getManager

public Manager getManager()
Return the Manager associated to this Nest
Specified by:
getManager in interface Nest

request

public void request(java.lang.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.

insert

public void insert(Resource resource)
Insert a new resource in this anthill. Delagates the insertion to the storage.
Specified by:
insert in interface Nest
Parameters:
resource - the resource to be inserted.

addClientNeighbour

public void addClientNeighbour(NestId aid)
Add the identifier of a new neighbour anthill 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 anthill 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

getPheromone

public java.lang.Object getPheromone(java.lang.Class cl)
Return the pheromone associated to the link to this neighbour. The class of the pheromone is left unspecified.

setPheromone

public void setPheromone(java.lang.Object pheromone,
                         java.lang.Class cl)
Return the pheromone associated to the link to this neighbour. The class of the pheromone is left unspecified.

clear

public void clear()
Restores the object to its initial state.
Specified by:
clear in interface Clearable