antsim.nestor
Class LocalAntView

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

public class LocalAntView
extends 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: 1.6 $
Author:
Alberto Montresor

Method Summary
 void addAnt(Ant ant)
          FIXME: comment.
 void addNeighbour(NestId id)
          Add the new neighbor information to the Gate object contained in the current nest.
 AntId createAntId()
          Creates a new ant identifier.
 ResourceManager createResourceManager(String name)
          Returns a reference to the resource manager identified by the given name, if present.
 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 current nest hosting the ant using this AntView.
 ResourceManager getResourceManager(String name)
          Returns a reference to the resource manager identified by the given name.
 int getTTL()
           
 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.
 
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 current 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: comment.

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
Parameters:
ant - the ant to be added to the current nest

move

public void move(NestId id)
          throws 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:
IOException - if the ant cannot move to the destination nest for communication problems.

addNeighbour

public void addNeighbour(NestId id)
                  throws 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
Throws:
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

getResourceManager

public ResourceManager getResourceManager(String name)
Returns a reference to the resource manager identified by the given name. Returns null if no resource manager is associated with the given name to this ant.

Specified by:
getResourceManager in interface AntView

createResourceManager

public ResourceManager createResourceManager(String name)
                                      throws ResourceManagerException
Returns a reference to the resource manager identified by the given name, if present. Otherwise, creates a new resource manager, using name as lookup identifier in the factory object to obtain the current configuration.

Specified by:
createResourceManager in interface AntView
ResourceManagerException

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:
resources - the resources satisfying the query