infoservice.agreement.multicast
Class InfoserviceEMCAdapter

java.lang.Object
  extended by infoservice.agreement.multicast.AbstractEMCAdapter
      extended by infoservice.agreement.multicast.InfoserviceEMCAdapter
All Implemented Interfaces:
IInfoServiceAgreementAdapter, IInfoService

public class InfoserviceEMCAdapter
extends AbstractEMCAdapter
implements IInfoServiceAgreementAdapter

Author:
LERNGRUPPE An adapter for the infoservice to give them the ability to handle the agreement protocol.

Field Summary
protected  java.lang.Thread m_agreementStarter
          A thread which executes the agreement logic.
private  DynamicCascadeConfigurator m_dynamicMixConfigurator
          A cascade configurator which holds logic for wireing mixes to cascades.
(package private)  java.util.Hashtable m_infoServiceSnapshot
          Holds an freeze the infoservice object which are current existing as long as the agreement runs.
private  MessageHandlerThread m_messageHandler
          A thread which handles messages for performance reasons.
protected  int m_numberOfAllActiveInfoservices
          Holds the number of all infoservices and freeze it as long as the agreement runs.
private  FifoQueue m_queue
          A data stack which implements fifo logic used for holding messages.
(package private)  InfoServiceDBEntry m_self
          The database entry representation for this infoservice.
 
Fields inherited from class infoservice.agreement.multicast.AbstractEMCAdapter
m_activeAgreementStarted, m_agreementHandler, m_log
 
Constructor Summary
InfoserviceEMCAdapter()
          Creates a new InfoserviceAgreementAdapter.
 
Method Summary
protected  void buildCascades(long l)
          Starts the cascade building process.
protected  void evangelizeThisInfoservice()
          Takes care that all infoservices know each other.
(package private)  InfoServiceDBEntry generateInfoServiceSelf()
          Generates an InfoServiceDBEntry for this InfoService
 java.lang.String getIdentifier()
          Returns a unique identifer for this infoservice.
 int getNumberOfAllInfoservices()
          Returns the freezed number of all infoservices which take part on the agreement protocol.
 HttpResponseStructure handleMessage(byte[] a_postData)
          Handles the messages coming in through the /agreement-command.
 void multicastMessage(IAgreementMessage a_message)
          Sends a message to all known infoservices.
protected  void prepareStart()
          Make sure we have "real" information about our neighbours (and they about us) once.
 void sendMessageTo(java.lang.String a_id, IAgreementMessage a_message)
          Sends a message to a specified infoservice.
(package private)  boolean sendToInfoService(InfoServiceDBEntry a_infoservice, IDistributable a_message)
          Encapsulates logic for sending a message to a infoservice.
private  boolean sendToInterface(ListenerInterface a_listener, IDistributable a_message)
          Encapsulates logic for sending a message to a specified listenere interface.
 void startListening()
          Stops the running message handler if necessary and creates a new one.
 
Methods inherited from class infoservice.agreement.multicast.AbstractEMCAdapter
debug, error, fatal, getLog, handleMessage, info, notifyAgreement, setIAgreementHandler, setLog, startAdapter, startAgreementCommitmentProtocol, startListeningMode, startProtocolByOperator, tryToStartAgreementHour, tryToStartAgreementMinute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface infoservice.agreement.IInfoServiceAgreementAdapter
startProtocolByOperator
 

Field Detail

m_dynamicMixConfigurator

private DynamicCascadeConfigurator m_dynamicMixConfigurator
A cascade configurator which holds logic for wireing mixes to cascades. He uses the agreement result, the common random number, to do that.


m_numberOfAllActiveInfoservices

protected int m_numberOfAllActiveInfoservices
Holds the number of all infoservices and freeze it as long as the agreement runs.


m_infoServiceSnapshot

java.util.Hashtable m_infoServiceSnapshot
Holds an freeze the infoservice object which are current existing as long as the agreement runs.


m_queue

private FifoQueue m_queue
A data stack which implements fifo logic used for holding messages.


m_self

InfoServiceDBEntry m_self
The database entry representation for this infoservice.


m_agreementStarter

protected java.lang.Thread m_agreementStarter
A thread which executes the agreement logic.


m_messageHandler

private MessageHandlerThread m_messageHandler
A thread which handles messages for performance reasons.

Constructor Detail

InfoserviceEMCAdapter

public InfoserviceEMCAdapter()
Creates a new InfoserviceAgreementAdapter. This adapter is used to connect the real InfoService to the agreement extension.

Parameters:
a_cmds - The connection object to serve network and communication.
Method Detail

generateInfoServiceSelf

InfoServiceDBEntry generateInfoServiceSelf()
Generates an InfoServiceDBEntry for this InfoService

Returns:
The InfoServiceDBEntry

evangelizeThisInfoservice

protected void evangelizeThisInfoservice()
Takes care that all infoservices know each other.


handleMessage

public HttpResponseStructure handleMessage(byte[] a_postData)
Handles the messages coming in through the /agreement-command. The a_postData is parsed to an IAgreementMessage and then put into the message queue. Messages are only accepted if an agreement is currently running or we are in the timeframe to start an new one

Specified by:
handleMessage in interface IInfoServiceAgreementAdapter
Parameters:
a_postData - The post data of the request containing an XML encoded IAgreementMessage
Returns:
HTTP_RETURN_INTERNAL_SERVER_ERROR if the message could not be parsed or the time was not right, HTTP_RETURN_OK otherwise

buildCascades

protected void buildCascades(long l)
Starts the cascade building process.

Specified by:
buildCascades in class AbstractEMCAdapter
Parameters:
l - A long value which represents the common random number.

prepareStart

protected void prepareStart()
Make sure we have "real" information about our neighbours (and they about us) once. Might not be needed in real world, but overcomes some problems at concurrent startup of multiple InfoServices (InfoServicePropagandist is too fast then and we don't want to wait 10 minutes)

Specified by:
prepareStart in class AbstractEMCAdapter

startListening

public void startListening()
Stops the running message handler if necessary and creates a new one.

Specified by:
startListening in class AbstractEMCAdapter

getNumberOfAllInfoservices

public int getNumberOfAllInfoservices()
Returns the freezed number of all infoservices which take part on the agreement protocol.

Specified by:
getNumberOfAllInfoservices in interface IInfoService
Specified by:
getNumberOfAllInfoservices in class AbstractEMCAdapter
Returns:
The number of known InfoServices

getIdentifier

public java.lang.String getIdentifier()
Returns a unique identifer for this infoservice.

Specified by:
getIdentifier in interface IInfoService
Specified by:
getIdentifier in class AbstractEMCAdapter
Returns:
An unique identifier for this IInfoService

sendMessageTo

public void sendMessageTo(java.lang.String a_id,
                          IAgreementMessage a_message)
Sends a message to a specified infoservice.

Specified by:
sendMessageTo in interface IInfoService
Specified by:
sendMessageTo in class AbstractEMCAdapter
Parameters:
a_id - The id of the receiver.
a_message - The message to send.

multicastMessage

public void multicastMessage(IAgreementMessage a_message)
Sends a message to all known infoservices.

Specified by:
multicastMessage in interface IInfoService
Specified by:
multicastMessage in class AbstractEMCAdapter
Parameters:
a_message - The message to send.

sendToInfoService

boolean sendToInfoService(InfoServiceDBEntry a_infoservice,
                          IDistributable a_message)
Encapsulates logic for sending a message to a infoservice.

Parameters:
a_infoservice - The target infoservice.
postFile -
postData -
Returns:
Success if true.

sendToInterface

private boolean sendToInterface(ListenerInterface a_listener,
                                IDistributable a_message)
Encapsulates logic for sending a message to a specified listenere interface.

Parameters:
a_listener - The network interface.
postFile -
postData -
Returns:
Success if true.