jxtaimpl
Class GateService

java.lang.Object
  |
  +--jxtaimpl.GateService
All Implemented Interfaces:
Clearable, Gate

public class GateService
extends Object
implements Gate

This is a Jxta-Enabled-Service. This class implements the Gate interface and is meant for receiving ants coming from other nests.

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

Field Summary
 
Fields inherited from interface anthill.nest.Gate
NAME
 
Constructor Summary
GateService()
           
 
Method Summary
 void clear()
          Restores the object to its initial state.
 Advertisement getImplAdvertisement()
          This method returns the GateService ModImplAdvertisement
 Service getInterface()
          This method returns the Service interface
 NestId getNestId()
          Returns the id associated with the nest this Gate belongs to
 void init(PeerGroup grp, ID id, Advertisement adv)
          The init method will be invoked by the Jxta platform during the AnthillGroup initialization process.
 void send(NestId dest, Ant ant, int ttl)
          This is the method which allows ants to be moved from nest to nest.
 void setAntListener(AntListener antListnr)
          This method sets a reference to the instance which is willing to accept ants coming from other nests.
 int startApp(String[] args)
          The startApp method will start the GateServiceServer and the GateServiceReceiver threads.
 void stopApp()
          Method for shutting the service down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GateService

public GateService()
Method Detail

init

public void init(PeerGroup grp,
                 ID id,
                 Advertisement adv)
The init method will be invoked by the Jxta platform during the AnthillGroup initialization process. PeerGroup grp refers to the AnthillGroup instance, while Advertisement adv refers to the GateService Module Impl Adv. The steps taken here are decribed in the "GateService StartUp" sequence diagram provided with the javadocs. The GateServiceServer and the GateServiceReceiver threads are started in the startApp method. All the gsReceiver and gsServer settings concerning priorities and other thread related things (i.e. is a deamon or not) are performed here.


startApp

public int startApp(String[] args)
The startApp method will start the GateServiceServer and the GateServiceReceiver threads. This method does not need to be invoked, the Jxta platform will do that.


stopApp

public void stopApp()
Method for shutting the service down.


getInterface

public Service getInterface()
This method returns the Service interface


getImplAdvertisement

public Advertisement getImplAdvertisement()
This method returns the GateService ModImplAdvertisement


getNestId

public NestId getNestId()
Returns the id associated with the nest this Gate belongs to

Specified by:
getNestId in interface Gate

send

public void send(NestId dest,
                 Ant ant,
                 int ttl)
          throws IOException
This is the method which allows ants to be moved from nest to nest. Its arguments are the destination nest id, the ant to be sent, and a Time To Live value (number of max hops). The ant is sent just if the TTL value will be > 0

Specified by:
send in interface Gate
Parameters:
dest - The jxtaimpl.ids.NestId ID of the destination nest
ant - The Ant to be sent
ttl - This ant's TTL value
Throws:
IOException - raised if problems have occurred during serialization and sending

setAntListener

public void setAntListener(AntListener antListnr)
This method sets a reference to the instance which is willing to accept ants coming from other nests. In the "jxtaimpl" implementation the Nest class implements the AntListener interface, so the AntListener is the Nest instance itself. The GateServiceServer instance has to get this reference. IMPORTANT: with this implementation this method is not useful anymore since the AntListener is set in the init() method using the reference to the Nest instance.

Specified by:
setAntListener in interface Gate
Parameters:
antListnr - the listener object that will accepts the ants coming from other nests

clear

public void clear()
Description copied from interface: Clearable
Restores the object to its initial state.

Specified by:
clear in interface Clearable