infoservice
Class InfoServiceDistributor

java.lang.Object
  extended by infoservice.InfoServiceDistributor
All Implemented Interfaces:
IDistributor

public class InfoServiceDistributor
extends java.lang.Object
implements IDistributor

This is the implementation of the forwarding code. Every information which to send to the other infoservices is processed by this class.


Field Summary
private  java.util.Vector m_defaultJobQueue
          Stores all jobs we have to send to the other infoservices.
private  java.util.Vector m_initialNeighboursJobQueue
          Stores all jobs we have to send to the initial neighbours of our infoservice.
private static InfoServiceDistributor ms_isdInstance
          Stores the instance of InfoServiceDatabase (Singleton).
private static long TIMEOUT_QUEUE
           
 
Constructor Summary
private InfoServiceDistributor()
          Creates a new instance of an InfoServiceDistributor.
 
Method Summary
 void addJob(IDistributable a_newJob)
          Adds a new job to the default job queue.
 void addJobToInititalNeighboursQueue(IDistributable a_newJob)
          Adds a new job to the initial neighbours job queue.
static InfoServiceDistributor getInstance()
          Returns the instance of InfoServiceDistributor (Singleton).
private  java.util.Vector getNeighbourList()
          Creates a list of all known infoservices (from the InfoServiceDatabase), which are neighbours of our one.
private  boolean sendToInfoService(InfoServiceDBEntry a_infoservice, IDistributable a_information)
          Sends the information about the DatabaseEntry to a remote infoservice.
private  boolean sendToInterface(ListenerInterface a_listener, IDistributable a_information)
          Sends the information to listener (remote ListenerInterface).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT_QUEUE

private static final long TIMEOUT_QUEUE
See Also:
Constant Field Values

ms_isdInstance

private static InfoServiceDistributor ms_isdInstance
Stores the instance of InfoServiceDatabase (Singleton).


m_defaultJobQueue

private java.util.Vector m_defaultJobQueue
Stores all jobs we have to send to the other infoservices. This is the default job queue, which means, that every entry is sent to all known and running infoservices stored in the InfoServiceDatabase.


m_initialNeighboursJobQueue

private java.util.Vector m_initialNeighboursJobQueue
Stores all jobs we have to send to the initial neighbours of our infoservice. This job queue should only be used for the propaganda of the own infoservice entry.

Constructor Detail

InfoServiceDistributor

private InfoServiceDistributor()
Creates a new instance of an InfoServiceDistributor. Some initialization is done here. Also the internal queue processing threads are started.

Method Detail

getInstance

public static InfoServiceDistributor getInstance()
Returns the instance of InfoServiceDistributor (Singleton). If there is no instance, there is a new one created. Also the included threads are started.

Returns:
The InfoServiceDistributor instance.

addJob

public void addJob(IDistributable a_newJob)
Adds a new job to the default job queue. So it is forwarded to all known and running neighbour infoservices, stored in the InfoServiceDatabase.

Specified by:
addJob in interface IDistributor
Parameters:
a_newJob - The information to forward.

addJobToInititalNeighboursQueue

public void addJobToInititalNeighboursQueue(IDistributable a_newJob)
Adds a new job to the initial neighbours job queue. So it is forwarded to all initial neighbour infoservices (specified in the config file). This should only be used for the propaganda of the own infoservice entry.

Parameters:
a_newJob - The information to forward.

getNeighbourList

private java.util.Vector getNeighbourList()
Creates a list of all known infoservices (from the InfoServiceDatabase), which are neighbours of our one.

Returns:
List of all neighbour infoservices we know.

sendToInfoService

private boolean sendToInfoService(InfoServiceDBEntry a_infoservice,
                                  IDistributable a_information)
Sends the information about the DatabaseEntry to a remote infoservice. TODO: if an infoservice entry is updated, we loose information about invalid interfaces and so we try them again (very time intensive) --> better: take always the last working interface until it is not working any more

Parameters:
a_infoservice - The remote infoservice.
a_information - The information to send to the infoservice.
Returns:
Whether we could reach the remote infoservice or not.

sendToInterface

private boolean sendToInterface(ListenerInterface a_listener,
                                IDistributable a_information)
Sends the information to listener (remote ListenerInterface).

Parameters:
a_listener - The representation of a host address and port to send to.
a_information - The information to send to the listener interface.
Returns:
Whether the connection was successful or not.