jxtaimpl
Class AnthillPeerWS

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--jxtaimpl.AnthillPeerWS
All Implemented Interfaces:
PeerFinder, Runnable

public class AnthillPeerWS
extends Thread
implements PeerFinder

This class implements the PeerFinder interface. So, after having initialized and started the Nest, its instance will periodically search for new advertisements.

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

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AnthillPeerWS(Factory factory)
          The constructor needs a Factory in order to instantiate all the other components of the Nest.
 
Method Summary
 void addKnownNest(NestId id)
          When a new nest has been found, a call to this method will just record the new NestId associated to the nest.
 void discoverNest()
          This method is used for discovering new Nest instances.
protected  void finalize()
          Method for cleaning up before being garbage collected
 NestId getDestNestId()
          This method should be invoked by a Nest instance in order to know to which Nest an ant wil be sent.
 Nest getNest()
          This method returns the Nest instance created by the AnthillPeerWorkSpace.
 NestId getNestId()
          This method returns the local nest ID
 NestId mkNestId(Advertisement adv)
          When a new PipeAdvertisement is found, it is handled to this method to extract a valid NestId from it, since that's the smallest information we need to get connected to other nests.
 void run()
          The run method will just periodically call the discoverNest() method and then go to sleep for a specified amount of time.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnthillPeerWS

public AnthillPeerWS(Factory factory)
The constructor needs a Factory in order to instantiate all the other components of the Nest.

Parameters:
factory - This is the factory instance used for reading in configuration parameters
Method Detail

getNest

public Nest getNest()
This method returns the Nest instance created by the AnthillPeerWorkSpace. This method should be used by an application developed on the top of this Anthill implementation in order to obtain a reference to the local Nest.


getNestId

public NestId getNestId()
This method returns the local nest ID


getDestNestId

public NestId getDestNestId()
This method should be invoked by a Nest instance in order to know to which Nest an ant wil be sent. The destination Nest will be choose randomly with a uniform distribution amongst the known neighbours. If there are no neighbours or if something goes wrong, a null value will be returned.

Specified by:
getDestNestId in interface PeerFinder

run

public void run()
The run method will just periodically call the discoverNest() method and then go to sleep for a specified amount of time. The "sleeping time" is set via the constructor of the class implementing this interface.

Specified by:
run in interface PeerFinder
Overrides:
run in class Thread

addKnownNest

public void addKnownNest(NestId id)
When a new nest has been found, a call to this method will just record the new NestId associated to the nest.

Specified by:
addKnownNest in interface PeerFinder
Parameters:
id - The id of the nest we want to add to the set of known neighbours

discoverNest

public void discoverNest()
This method is used for discovering new Nest instances.

Specified by:
discoverNest in interface PeerFinder

mkNestId

public NestId mkNestId(Advertisement adv)
When a new PipeAdvertisement is found, it is handled to this method to extract a valid NestId from it, since that's the smallest information we need to get connected to other nests.

Specified by:
mkNestId in interface PeerFinder
Parameters:
adv - The pipe advertisement from which we derive a valid jxtaimpl.ids.NestId instance

finalize

protected void finalize()
Method for cleaning up before being garbage collected

Overrides:
finalize in class Object