infoservice.agreement.multicast
Class EchoMulticastAgreementHandlerImpl

java.lang.Object
  extended by infoservice.agreement.multicast.EchoMulticastAgreementHandlerImpl
All Implemented Interfaces:
TimeoutListener, IAgreementHandler

public class EchoMulticastAgreementHandlerImpl
extends java.lang.Object
implements IAgreementHandler

Author:
LERNGRUPPE This class represents a dealer witch takes care about all things around the agreement for generating a common random number used as input for the wireing-algorithm.

Field Summary
private  TimeoutThread m_agreementTimeOutThread
          A thread used for giving time out signal.
private  boolean m_agreementTimeoutThreadIsStarted
          Determines whether the agreement time out thrtead is just started.
private  CommitmentMessage m_commitmentMessage
          The CommitmentMessage is not a part of the reliable broadcast protocol.
private  java.util.Hashtable m_currentAgreementResults
          Contains the reached agreement results (from infoservice1, infoservice2 ...) of the current phase.
protected  java.lang.String m_currentMessage
          This is the current massage (proposal) which is actual performed by the agreement protocol.
private  int m_currentPhase
          Indicates the current phase of the commitment scheme.
private  IInfoService m_infoService
          The infoservice we are bundled.
private  java.lang.String m_lastCommonRandom
          Holds the last agreed random number or an init value at start up.
private  IAgreementLog m_logger
          A little logger to write out log informations to filesystem.
private  java.util.Hashtable m_logHashTable
          Saves the log entries which hold the checked messages.
private  java.util.Hashtable m_phaseOneAgreemetResults
          Contains the reached agreement results of agreement phase one.
 
Constructor Summary
EchoMulticastAgreementHandlerImpl(IInfoService a_infoService)
          Creates an agereement handler witch runs the multycast-agreement-protocol.
 
Method Summary
private  java.lang.Long checkTheResults()
          Evaluate the results, combine the random numbers of all infoservices and return this new common random value or null.
private  void debug(java.lang.String a_message)
          Logs debug messages
private  ConsensusLogEchoMulticast getConsensusLog(AMessage a_msg)
          Gets the appropriate consensus log entry by consensus id or, if not yet in the store, creates a new one and adds is to the store.
 IInfoService getInfoService()
          Gets the infoservice which belongs to this agreement handler.
 java.lang.String getLastCommonRandom()
          Gets he value which holds the last agreed random number or an init value at start up.
private  void handleCommitMessage(CommitMessage a_message)
          Check and add a CommitMessage.
private  void handleConfirmationMessage(ConfirmationMessage a_message)
          This method handles all incomming confirmation-messages.
private  void handleEchoMessage(EchoMessage a_message)
          If an EchoMessage received, it will be handled by two steps.
private  void handleInitMessage(InitMessage a_message)
          If an InitMessage received, it will be handled by two steps.
 void handleMessage(IAgreementMessage a_msg)
          This is the main handle point for incomming messages according to this agreement protocol.
private  void handleRejectMessage(RejectMessage a_message)
          This method handles all incomming reject-messages.
(package private)  void info(java.lang.String a_message)
          Logs info messages
private  void notifyBabylonianConfusion()
          If something really really bad happens, that is if the InfoServices massively disagree, we need help
 void notifyConsensusLogTimeout(IConsensusLog consensus)
          This method is called by the ConsensusLogTimeoutThread at the moment of expiration.
 void reset()
          Initialize some variables and reset the time out thread.
protected  void sendReliableBroadcastMessage(java.lang.String a_message)
          Starts the reliable broadcast and performs the given message.
 void setLastCommonRandom(java.lang.String commonRandom)
          This is needes for testing purposes only.
 void setLog(IAgreementLog a_log)
           
 void softReset()
          Initialize some variables and reset the time out thread.
 void startAgreementCommitmentProtocol()
          Call this methode to initialize the agreement protocol.
 void timeout(java.lang.Object a_value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_currentAgreementResults

private java.util.Hashtable m_currentAgreementResults
Contains the reached agreement results (from infoservice1, infoservice2 ...) of the current phase. Notize: ther are two phases.


m_phaseOneAgreemetResults

private java.util.Hashtable m_phaseOneAgreemetResults
Contains the reached agreement results of agreement phase one.


m_infoService

private IInfoService m_infoService
The infoservice we are bundled. Needed for communications etc.


m_logger

private IAgreementLog m_logger
A little logger to write out log informations to filesystem.


m_lastCommonRandom

private java.lang.String m_lastCommonRandom
Holds the last agreed random number or an init value at start up.


m_logHashTable

private java.util.Hashtable m_logHashTable
Saves the log entries which hold the checked messages.


m_agreementTimeOutThread

private TimeoutThread m_agreementTimeOutThread
A thread used for giving time out signal.


m_commitmentMessage

private CommitmentMessage m_commitmentMessage
The CommitmentMessage is not a part of the reliable broadcast protocol. It is used by the implicit commitment scheme. It holds a commitment message.


m_currentMessage

protected java.lang.String m_currentMessage
This is the current massage (proposal) which is actual performed by the agreement protocol. Is is not part of the reliable broadcast protocol itself. It's just the message.


m_agreementTimeoutThreadIsStarted

private boolean m_agreementTimeoutThreadIsStarted
Determines whether the agreement time out thrtead is just started.


m_currentPhase

private int m_currentPhase
Indicates the current phase of the commitment scheme.

Constructor Detail

EchoMulticastAgreementHandlerImpl

public EchoMulticastAgreementHandlerImpl(IInfoService a_infoService)
Creates an agereement handler witch runs the multycast-agreement-protocol.

Parameters:
a_infoService - The infoservice belongs to.
Method Detail

handleMessage

public void handleMessage(IAgreementMessage a_msg)
                   throws java.lang.IllegalArgumentException
This is the main handle point for incomming messages according to this agreement protocol.

Specified by:
handleMessage in interface IAgreementHandler
Parameters:
a_msg - The incomming message.
Throws:
java.lang.IllegalArgumentException

handleConfirmationMessage

private void handleConfirmationMessage(ConfirmationMessage a_message)
This method handles all incomming confirmation-messages. It maps the massage on a CommitMessage if no agreement is reached yet and perform handleCommitMessage(..).

Parameters:
a_message - The message.

handleRejectMessage

private void handleRejectMessage(RejectMessage a_message)
This method handles all incomming reject-messages. This messagetype will be sent by nodes for receiving invalid init-messages. Especially in the case of incorrect agreement-identifier lastCommonRandom.

Parameters:
a_message - The message.

handleInitMessage

private void handleInitMessage(InitMessage a_message)
If an InitMessage received, it will be handled by two steps. At first we start the agreement timeout thread, than we check whether the currend agreement id is part of this message. If so, we create a log entry an send a echo message, otherwise we send a reject message.

Parameters:
a_message - The InitMessage.

handleEchoMessage

private void handleEchoMessage(EchoMessage a_message)
If an EchoMessage received, it will be handled by two steps. At first we add it in the log-hashtable and at second there is to decide whether there are enough EchoMessages collected for executing a CommitMessage.

Parameters:
a_message - the EchoMessage

handleCommitMessage

private void handleCommitMessage(CommitMessage a_message)
Check and add a CommitMessage. If Ok, create and send a ConfirmationMessage to all.

Parameters:
a_message - The message

startAgreementCommitmentProtocol

public void startAgreementCommitmentProtocol()
Call this methode to initialize the agreement protocol.

Specified by:
startAgreementCommitmentProtocol in interface IAgreementHandler
Parameters:
lastRandom - Should be the common random number from the las agreement or an initial value shared by all infoservices.

sendReliableBroadcastMessage

protected void sendReliableBroadcastMessage(java.lang.String a_message)
Starts the reliable broadcast and performs the given message.

Parameters:
a_message - The message to send.

reset

public void reset()
Initialize some variables and reset the time out thread.

Specified by:
reset in interface IAgreementHandler

softReset

public void softReset()
Initialize some variables and reset the time out thread.


getConsensusLog

private ConsensusLogEchoMulticast getConsensusLog(AMessage a_msg)
Gets the appropriate consensus log entry by consensus id or, if not yet in the store, creates a new one and adds is to the store.

Parameters:
a_msg - The message, which contains all informations to construct a log id.
Returns:
The appropriate consensus log or a new one.

notifyConsensusLogTimeout

public void notifyConsensusLogTimeout(IConsensusLog consensus)
This method is called by the ConsensusLogTimeoutThread at the moment of expiration.

Specified by:
notifyConsensusLogTimeout in interface IAgreementHandler
Parameters:
consensus - The log entry.

notifyBabylonianConfusion

private void notifyBabylonianConfusion()
If something really really bad happens, that is if the InfoServices massively disagree, we need help


checkTheResults

private java.lang.Long checkTheResults()
Evaluate the results, combine the random numbers of all infoservices and return this new common random value or null.

Returns:
New common random value or null.

getLastCommonRandom

public java.lang.String getLastCommonRandom()
Gets he value which holds the last agreed random number or an init value at start up.

Returns:

setLastCommonRandom

public void setLastCommonRandom(java.lang.String commonRandom)
Description copied from interface: IAgreementHandler
This is needes for testing purposes only.

Specified by:
setLastCommonRandom in interface IAgreementHandler
Parameters:
commonRandom - The value of the current round number.

debug

private void debug(java.lang.String a_message)
Logs debug messages

Parameters:
a_message - The message to log.

info

void info(java.lang.String a_message)
Logs info messages

Parameters:
a_message -

getInfoService

public IInfoService getInfoService()
Description copied from interface: IAgreementHandler
Gets the infoservice which belongs to this agreement handler.

Specified by:
getInfoService in interface IAgreementHandler
Returns:

timeout

public void timeout(java.lang.Object a_value)
Specified by:
timeout in interface TimeoutListener

setLog

public void setLog(IAgreementLog a_log)
Specified by:
setLog in interface IAgreementHandler