jxtaimpl
Class AntView

java.lang.Object
  |
  +--jxtaimpl.AntView
All Implemented Interfaces:
AntView

public class AntView
extends Object
implements AntView

This class is the enviroment where an Ant can operate.

Author:
Francesco Russo (frusso@cs.unibo.it)

Constructor Summary
AntView(Nest nest, AntDescriptor aDesc, Factory factory)
          Default constructor.
 
Method Summary
 void addAnt(Ant ant)
          Add a new ant to this nest.
 void addNeighbour(NestId id)
          Ants invoke this method to add the identifier of a new neighbour nest to the set of neighbours known to the current nest.
 void addResource(Resource resource)
          Add a resource to the nest.
 AntId createAntId()
          Creates a new ant identifier.
 ResourceManager createResourceManager(String name)
          Return a storage object identified by the given name.
 Ant getAnt()
          Return 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.
 Resource getResource(Object query)
          Performs the specified request on the local resource storage and returns the resources satisfying the request.
 ResourceManager getResourceManager(String name)
          Return a storage object identified by the given name.
 Resource[] getResources(Object query)
          Performs the specified request on the local resource storage and returns the resources satisfying the request.
 int getTTL()
          Returns this ant's TTL value
 int intValue(String name)
          Read the configuration parameter from its own Factory instance.
 void move(NestId id)
          Method invoked by an ant in order to be sent to another Nest.
 void removeNeighbour(NestId id)
          Ants invoke this method to remove a neighbor nest from the list of neighbors known to this nest.
 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, has found the specified set of resources.
 void updatePheromone(Object pheromone)
          This method should be invoked by ants in order to update the current nest's pheromone instance every time they modify it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AntView

public AntView(Nest nest,
               AntDescriptor aDesc,
               Factory factory)
Default constructor. The nest object is the Nest over which the Ant wrapped in the AntDescriptor will operate

Parameters:
nest - The Nest this AntView belongs to
aDesc - The AntDescriptor wrapping the Ant
factory - The Factory instance used for reading in configuration parameters
Method Detail

getNestId

public NestId getNestId()
Returns the identifier of the nest hosting the ant using this AntView.

Specified by:
getNestId in interface AntView

getLastVisited

public NestId getLastVisited()
Returns the identifier of the last nest visisted by this ant.

Specified by:
getLastVisited in interface AntView

getTTL

public int getTTL()
Returns this ant's TTL value

Specified by:
getTTL in interface AntView

getAnt

public Ant getAnt()
Return 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)
Add a new ant to this nest. For example, this method could be used to create a backward ant for returning information to the requestor nest.

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
Method invoked by an ant in order to be sent to another Nest. It is possible that particular AntView implementation limit the operations which can be performed after a move operation. For example, movement to more than one nest (i.e., duplication) may not be enabled.

Specified by:
move in interface AntView
Parameters:
id - the identifier of the destination nest
Throws:
IOException - raised if the move operation fails, for example due to the unreachability of the nest

addNeighbour

public void addNeighbour(NestId id)
                  throws IOException
Ants invoke this method to add the identifier of a new neighbour nest to the set of neighbours known to the current nest. Depending on the implementation, this operation may require the establishment of a connection to the new nest. In this case, an IOException may be raised in the case a connection cannot be established.

Specified by:
addNeighbour in interface AntView
Throws:
IOException - if a connection with the nest cannot be established.

removeNeighbour

public void removeNeighbour(NestId id)
Ants invoke this method to remove a neighbor nest from the list of neighbors known to this nest.

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.

Specified by:
getNeighbours in interface AntView

getResourceManager

public ResourceManager getResourceManager(String name)
Return a storage object identified by the given name. The storage we return with this method, has to be the storage associated with the invoking ant's species. Name is used for specifieing the storage type (i.e. Storage.DOC_STORAGE, Storage.PHR_STORAGE, Storage.URL_STORAGE)

Specified by:
getResourceManager in interface AntView

createResourceManager

public ResourceManager createResourceManager(String name)
                                      throws ResourceManagerException
Return a storage object identified by the given name. The storage we return with this method, has to be the storage associated with the invoking ant's species. Name is used for specifieing the storage type (i.e. Storage.DOC_STORAGE, Storage.PHR_STORAGE, Storage.URL_STORAGE).

Specified by:
createResourceManager in interface AntView
ResourceManagerException

updatePheromone

public void updatePheromone(Object pheromone)
This method should be invoked by ants in order to update the current nest's pheromone instance every time they modify it. Not invokig this method implies having inconsisten information stored in a nest's pheromone instance and so a wrong system behaviour.


getResources

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

StorageNotFoundException

getResource

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

StorageNotFoundException

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. This method will copy the resource into the local Storage associated with the invoking ant's species.

Parameters:
resource - resource to be added
CapacityException
StorageNotFoundException

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, has found the specified set of resources.

Specified by:
returnResources in interface AntView
Parameters:
resources - the resources satisfying the request

intValue

public int intValue(String name)
Read the configuration parameter from its own Factory instance.