anthill.nestor
Class LocalAntView

java.lang.Object
  |
  +--anthill.nestor.LocalAntView
All Implemented Interfaces:
AntView

public class LocalAntView
extends java.lang.Object
implements AntView

Class LocalAntView is a simple implementation of interface AntView, which implements methods included in it by invoking the opportune methods on the local nest.

Version:
$Revision$
Author:
Alberto Montresor

Method Summary
 void addAnt(Ant ant)
          FIXME: Implement.
 void addNeighbour(NestId id)
          Add the new neighbor information to the Gate object contained in the current nest.
 void addResource(Resource resource)
          Add a resource to the nest.
 AntId createAntId()
          Creates a new ant identifier.
 Ant getAnt()
          Returns the ant which is associated to this AntView.
 NestId getLastVisited()
          Returns the identifier of the last nest visisted by this ant.
 Neighbour[] getNeighbours()
          Ants invoke this method to obtain the list of nest neighbors known to the current nest.
 NestId getNestId()
          Returns the identifier of the nest hosting the ant using this AntView.
 java.lang.Object getPheromone()
          Get the pheromone information object related to the species of the ant associated to this AntView object.
 Resource getResource(java.lang.Object key)
          Performs the specified request on the local resource storage and returns the resources satisfying the request.
 Resource[] getResources(java.lang.Object request)
          Performs the specified request on the local resource storage and returns the resources satisfying the request.
 NestId getReturnNest(AntId aid, boolean remove)
          Lookup trail information on the Trail object stored in the nest and move to the obtained nest.
 Storage getStorage(java.lang.String name)
          Return a storage object identified by the given name.
 int getTTL()
           
 int intValue(java.lang.String name)
          Read from statistics
 void move(NestId id)
          Moves an ant to the specified nest.
 void removeNeighbour(NestId id)
          FIXME: Implement.
 boolean returnResources(RequestId rid, Resource[] resources)
          This method is invoked by ants to notify the nest that the ant associated to this AntView, created to satisfy a request, is returning the specified set of resources.
 void setPheromone(java.lang.Object pheromone)
          Set the pheromone information object related to the species of the ant associated to this AntView object.
 boolean storeReturnNest(AntId aid, NestId nid)
          Leave trail information on the Trail object stored in the nest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNestId

public NestId getNestId()
Description copied from interface: AntView
Returns the identifier of the nest hosting the ant using this AntView.
Specified by:
getNestId in interface AntView

getLastVisited

public NestId getLastVisited()
Description copied from interface: AntView
Returns the identifier of the last nest visisted by this ant.
Specified by:
getLastVisited in interface AntView

getTTL

public int getTTL()
Specified by:
getTTL in interface AntView

getAnt

public Ant getAnt()
Description copied from interface: AntView
Returns the ant which is associated to this AntView. Normally not used by ants, as they may access the same information using this.
Specified by:
getAnt in interface AntView

createAntId

public AntId createAntId()
Creates a new ant identifier.
Specified by:
createAntId in interface AntView

addAnt

public void addAnt(Ant ant)
FIXME: Implement.

The exact behavior of this method depends on the class implementing the Manager interface currently used in the current nest. Please refer to the implementation documentation for more details.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
addAnt in interface AntView
Following copied from interface: anthill.AntView
Parameters:
ant - the ant to be added to the current nest

move

public void move(NestId id)
          throws java.io.IOException
Moves an ant to the specified nest. In this particular implementation, an ant can perform at most one move operation when in a nest. This restriction is imposed in order to avoid unbounded ant replication.

The exact behavior of this method depends on the class implementing the Gate interface currently used in the current nest. Please refer to the implementation documentation for more details.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
move in interface AntView
Parameters:
id - the id of the destination nest
Throws:
java.io.IOException - if the ant cannot move to the destination nest for communication problems.

storeReturnNest

public boolean storeReturnNest(AntId aid,
                               NestId nid)
Leave trail information on the Trail object stored in the nest. If absent, the trail is created. Return true if the the information is left

The exact behavior of this method depends on the class implementing the Trail interface currently used in the current nest. Please refer to the implementation documentation for more details.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
storeReturnNest in interface AntView
Following copied from interface: anthill.AntView
Returns:
true if this is the first visit of this ant to this nest (and thus, the information about the previous nest has been stored successfully), or false if this ant has already visited the nest (and thus, the inforamtion about the previous nest could not be stored).

getReturnNest

public NestId getReturnNest(AntId aid,
                            boolean remove)
Lookup trail information on the Trail object stored in the nest and move to the obtained nest. If the trail is absent, IllegalStateException is raised.

The exact behavior of this method depends on the class implementing the Trail interface currently used in the current nest. Please refer to the implementation documentation for more details.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
getReturnNest in interface AntView
Parameters:
remove - true if the association (ant id, nest id) should be removed after retrieval

addNeighbour

public void addNeighbour(NestId id)
                  throws java.io.IOException
Add the new neighbor information to the Gate object contained in the current nest. FIXME: correct implementation by removing addAntNeighbour and adding the method to Gate.

The exact behavior of this method depends on the class implementing the Gate interface currently used in the current nest. Please refer to the implementation documentation for more details.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
addNeighbour in interface AntView
Following copied from interface: anthill.AntView
Throws:
java.io.IOException - if a connection with the nest cannot be established.

removeNeighbour

public void removeNeighbour(NestId id)
FIXME: Implement.

The exact behavior of this method depends on the class implementing the Gate interface currently used in the current nest. Please refer to the class documentation for more details.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
removeNeighbour in interface AntView

getNeighbours

public Neighbour[] getNeighbours()
Ants invoke this method to obtain the list of nest neighbors known to the current nest. FIXME: correct implementation to refer to Gate

The exact behavior of this method depends on the class implementing the Gate interface currently used in the current nest. Please refer to the implementation documentation for more details.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
getNeighbours in interface AntView

getStorage

public Storage getStorage(java.lang.String name)
                   throws StorageNotFoundException
Return a storage object identified by the given name.
Specified by:
getStorage in interface AntView

getResources

public Resource[] getResources(java.lang.Object request)
                        throws StorageNotFoundException
Performs the specified request on the local resource storage and returns the resources satisfying the request.

The exact behavior of this method depends on the implementation of the current nest hosting the ant. Please refer to the documentation of the nest implementation for more details.

Specified by:
getResources in interface AntView
Parameters:
request - The request to be performed

getResource

public Resource getResource(java.lang.Object key)
                     throws StorageNotFoundException
Performs the specified request on the local resource storage and returns the resources satisfying the request.

The exact behavior of this method depends on the implementation of the current nest hosting the ant. Please refer to the documentation of the nest implementation for more details.

Specified by:
getResource in interface AntView
Parameters:
request - The request to be performed

addResource

public void addResource(Resource resource)
                 throws CapacityException,
                        StorageNotFoundException
Add a resource to the nest. This method enables ants to move resources from one nest to another.

Depending on the implementation of Resource and Nest, adding a resource to a nest through an AntView may result to actual copy the content of the resource, or to simply insert a reference to the actual position of the resource itself.

This method may be invoked more than once from an ant, in order to insert more resources. Nevertheless, the actual insertion of a resource in a nest depends on the policies of the particular Nest implementation. For example, a nest may limit the number of resources originated by another nest, in order to avoid "spamming".

The exact behavior of this method depends on the implementation of the current nest hosting the ant. Please refer to the documentation of the nest implementation for more details.

Specified by:
addResource in interface AntView
Parameters:
resource - resource to be added

getPheromone

public java.lang.Object getPheromone()
Get the pheromone information object related to the species of the ant associated to this AntView object. Different ant species are associated to different pheromone objects.

Please see the corresponding method comment in interface AntView for additional information.

Specified by:
getPheromone in interface AntView

setPheromone

public void setPheromone(java.lang.Object pheromone)
Set the pheromone information object related to the species of the ant associated to this AntView object. Different ant species are associated to different pheromone objects.
Specified by:
setPheromone in interface AntView
Parameters:
pheromone - the pheromone object to be set.

Please see the corresponding method comment in interface AntView for additional information.


returnResources

public boolean returnResources(RequestId rid,
                               Resource[] resources)
This method is invoked by ants to notify the nest that the ant associated to this AntView, created to satisfy a request, is returning the specified set of resources.
Specified by:
returnResources in interface AntView
Parameters:
request - the request to be performed
resources - the resources satisfying the query

intValue

public int intValue(java.lang.String name)
Read from statistics
Specified by:
intValue in interface AntView