infoservice.agreement.multicast
Class ConsensusLogEchoMulticast

java.lang.Object
  extended by infoservice.agreement.multicast.ConsensusLogEchoMulticast
All Implemented Interfaces:
TimeoutListener, IConsensusLog

public class ConsensusLogEchoMulticast
extends java.lang.Object
implements IConsensusLog

Author:
LERNGRUPPE A log entry for AMessages.

Field Summary
private  boolean m_agreed
          Indicates whether the agreement for this log entry is reached.
private  boolean m_comitted
          Indicates whether the a CommitMessage was send for this log entry.
private  java.util.Hashtable m_commitMessagesHashTable
          Holds the accepted CommitMessages.
private  java.lang.String m_consensusId
          The consensus log entry id.
private  int m_criticalMasses
          Holds a value which determines the lower bound of good infoservices.
private  java.util.Hashtable m_echoMessagesHashTable
          Holds the accepted EchoMessages.
private  IAgreementHandler m_handler
          An Instance of the agreement handler to get some information about the current infoservice and for notifying agreements.
private  java.lang.String m_initiatorId
          The id of the infoservice which send the InitMessag.
private  InitMessage m_initMessage
          Saves the accepted initial message according to this log entry.
private  java.lang.String m_lastCommonRandom
          The result of the last agreement or an initalized value at startup which is used as round number too.
private  IAgreementLog m_logger
          A logger.
private  boolean m_rejected
          Indicates whether the a RejectMessage was send for this log entry.
private  java.util.Hashtable m_rejectMessagesHashTable
          Holds the accepted RejectMessages.
private  boolean m_restarted
          Indicates whether the a log entry got enough RejectMessages to reset the lastCommonRandom and restart the protocol.
private  boolean m_timedOut
          Indicates whether the a lifecycle for this log entry is expired.
private  TimeoutThread timeoutThread
          Holds the timeout thread.
 
Constructor Summary
ConsensusLogEchoMulticast(EchoMulticastAgreementHandlerImpl a_handler, InitMessage a_initMessage)
          Constructor for creating a log entry.
ConsensusLogEchoMulticast(EchoMulticastAgreementHandlerImpl a_handler, InitMessage a_initMessage, IAgreementLog a_log)
          Constructor for creating a logentry.
ConsensusLogEchoMulticast(EchoMulticastAgreementHandlerImpl a_handler, java.lang.String a_consensusId, IAgreementLog a_log, java.lang.String a_initiatorsId)
          Constructor for creating a logentry.
 
Method Summary
 boolean addCommitMessage(CommitMessage a_msg)
          If checkCommitMessage(a_msg) is successful the messge will be added to the consensuslog, otherwise discarded.
 boolean addEchoMessage(EchoMessage a_msg)
          If checkEchoMessage(a_msg) is successful the messge will be added to the consensuslog, otherwise discarded.
 boolean addInitMessage(InitMessage a_msg)
          If checkInitMessage(a_msg) was successful the messge will be added to the consensuslog, otherwise discarded.
 void addRejectMessage(RejectMessage a_msg)
          If checkRejectMessage(a_msg) is successful the messge will be added to the consensuslog, otherwise discarded.
private  boolean checkCommitMessage(CommitMessage a_msg)
          Checks the given CommitMessage.
private  boolean checkEchoMessage(EchoMessage a_msg)
          Checks the given EchoMessage.
private  boolean checkGenericMessage(AMessage a_msg)
          Check the properties encapsulated in the AMessage super class.
private  boolean checkInitMessage(InitMessage a_msg)
          Checks the given InitMessage AND sets the ConsensusId.
private  void checkRejectMajority(RejectMessage a_msg)
          Count the number of received RejectMessage and sets this value to sm_lastCommonRandom if the amount reachs at least m_criticalMasses.
private  boolean checkRejectMessage(RejectMessage a_msg)
          Check the given reject-message and, if positive, extract and save the new value of lastCommonRandom
private  void debug(java.lang.String a_message)
           
 int getCommitMessageCount()
          Get the hashtable which holds the accepted CommitMessages.
 java.lang.String getConsensusID()
          Gets the consensus log entry id.
 int getEchoMessageCount()
          Count the EchoMessages.
 java.lang.String getInitiatorId()
          Gets the id of the infoservice which send the InitMessag.
 InitMessage getInitMessages()
          Gets the accepted initial message according to this log entry.
 java.lang.String getLastCommonRandom()
          Gets the result of the last agreement or an initalized value at start up which is used as round number too.
private  void initializeConsensusLog(EchoMulticastAgreementHandlerImpl a_handler, java.lang.String a_consensusId, IAgreementLog a_log, java.lang.String a_initiatorsId)
          Sets up the necessary start variables.
 boolean isAgreed()
          Indicates whether the agreement for this log entry is reached.
 boolean isComitted()
          Indicates whether the a CommitMessage was send for this log entry.
 boolean isRejected()
          Indicates whether the a RejectMessage was send for this log entry.
 boolean isRestarted()
          Indicates whether the a log entry got enough RejectMessages to reset the lastCommonRandom and restart the protocol.
private  void putter(java.util.Hashtable amounts, RejectMessage msg)
          Counts the received RejectMessages.
 void setAgreed(boolean agreed)
          Indicates whether the agreement for this log entry is reached.
 void setComitted(boolean comitted)
          Set a value which indicates whether the a CommitMessage was send for this log entry.
 void setRestarted(boolean a_restarted)
          Sets a value which indicates whether the a log entry got enough RejectMessages to reset the lastCommonRandom and restart the protocol.
 void stopTimeout()
          Stops the consensus log time out.
 void timeout(java.lang.Object a_value)
          On creating a consensuslog a timer will be set.
 CommitMessage tryToCreateACommitMessage()
          Check the criteria for creating a CommitMessage an do it if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_initMessage

private InitMessage m_initMessage
Saves the accepted initial message according to this log entry.


m_echoMessagesHashTable

private java.util.Hashtable m_echoMessagesHashTable
Holds the accepted EchoMessages.


m_commitMessagesHashTable

private java.util.Hashtable m_commitMessagesHashTable
Holds the accepted CommitMessages.


m_rejectMessagesHashTable

private java.util.Hashtable m_rejectMessagesHashTable
Holds the accepted RejectMessages.


m_logger

private IAgreementLog m_logger
A logger.


m_agreed

private boolean m_agreed
Indicates whether the agreement for this log entry is reached.


m_comitted

private boolean m_comitted
Indicates whether the a CommitMessage was send for this log entry.


m_timedOut

private boolean m_timedOut
Indicates whether the a lifecycle for this log entry is expired.


timeoutThread

private TimeoutThread timeoutThread
Holds the timeout thread.


m_handler

private IAgreementHandler m_handler
An Instance of the agreement handler to get some information about the current infoservice and for notifying agreements.


m_consensusId

private java.lang.String m_consensusId
The consensus log entry id.


m_criticalMasses

private int m_criticalMasses
Holds a value which determines the lower bound of good infoservices.


m_initiatorId

private java.lang.String m_initiatorId
The id of the infoservice which send the InitMessag.


m_rejected

private boolean m_rejected
Indicates whether the a RejectMessage was send for this log entry.


m_restarted

private boolean m_restarted
Indicates whether the a log entry got enough RejectMessages to reset the lastCommonRandom and restart the protocol.


m_lastCommonRandom

private java.lang.String m_lastCommonRandom
The result of the last agreement or an initalized value at startup which is used as round number too.

Constructor Detail

ConsensusLogEchoMulticast

public ConsensusLogEchoMulticast(EchoMulticastAgreementHandlerImpl a_handler,
                                 InitMessage a_initMessage)
Constructor for creating a log entry.

Parameters:
a_handler - The corrosponding agreementhandler.
a_initMessage - Initmessage. This ist the startmessage of the protocol.

ConsensusLogEchoMulticast

public ConsensusLogEchoMulticast(EchoMulticastAgreementHandlerImpl a_handler,
                                 java.lang.String a_consensusId,
                                 IAgreementLog a_log,
                                 java.lang.String a_initiatorsId)
Constructor for creating a logentry.

Parameters:
a_handler - The corrosponding agreementhandler.
a_consensusId - The id of this consensuslogentry.
a_log - A filelogger.

ConsensusLogEchoMulticast

public ConsensusLogEchoMulticast(EchoMulticastAgreementHandlerImpl a_handler,
                                 InitMessage a_initMessage,
                                 IAgreementLog a_log)
Constructor for creating a logentry.

Parameters:
a_handler - The corrosponding agreementhandler.
a_initMessage - Initmessage. This ist the startmessage of the protocol.
a_log - A filelogger.
Method Detail

initializeConsensusLog

private void initializeConsensusLog(EchoMulticastAgreementHandlerImpl a_handler,
                                    java.lang.String a_consensusId,
                                    IAgreementLog a_log,
                                    java.lang.String a_initiatorsId)
Sets up the necessary start variables.

Parameters:
a_handler -
a_consensusId -
a_log -
a_initiatorsId -

checkGenericMessage

private boolean checkGenericMessage(AMessage a_msg)
Check the properties encapsulated in the AMessage super class.

Parameters:
a_msg - The message.
Returns:
true if successful.

addInitMessage

public boolean addInitMessage(InitMessage a_msg)
If checkInitMessage(a_msg) was successful the messge will be added to the consensuslog, otherwise discarded.

Parameters:
a_msg - The message.

checkInitMessage

private boolean checkInitMessage(InitMessage a_msg)
Checks the given InitMessage AND sets the ConsensusId.

Parameters:
a_msg -
Returns:
true for success otherwise false

addEchoMessage

public boolean addEchoMessage(EchoMessage a_msg)
If checkEchoMessage(a_msg) is successful the messge will be added to the consensuslog, otherwise discarded.

Parameters:
a_msg - The message.

checkEchoMessage

private boolean checkEchoMessage(EchoMessage a_msg)
Checks the given EchoMessage.

Parameters:
a_msg -
Returns:
true for success otherwise false

addCommitMessage

public boolean addCommitMessage(CommitMessage a_msg)
If checkCommitMessage(a_msg) is successful the messge will be added to the consensuslog, otherwise discarded.

Parameters:
a_msg - The message.

checkCommitMessage

private boolean checkCommitMessage(CommitMessage a_msg)
Checks the given CommitMessage.

Parameters:
a_msg -
Returns:
true for success otherwise false

addRejectMessage

public void addRejectMessage(RejectMessage a_msg)
If checkRejectMessage(a_msg) is successful the messge will be added to the consensuslog, otherwise discarded.

Parameters:
a_msg - The message.

checkRejectMessage

private boolean checkRejectMessage(RejectMessage a_msg)
Check the given reject-message and, if positive, extract and save the new value of lastCommonRandom

Parameters:
a_msg - The message.
Returns:
True if the check was successful.

checkRejectMajority

private void checkRejectMajority(RejectMessage a_msg)
Count the number of received RejectMessage and sets this value to sm_lastCommonRandom if the amount reachs at least m_criticalMasses.


putter

private void putter(java.util.Hashtable amounts,
                    RejectMessage msg)
Counts the received RejectMessages.

Parameters:
amounts - A hashtable which contains the various RejectMessages.
msg - The message.

tryToCreateACommitMessage

public CommitMessage tryToCreateACommitMessage()
Check the criteria for creating a CommitMessage an do it if possible.

Returns:
the created CommitMessage or null.

getEchoMessageCount

public int getEchoMessageCount()
Count the EchoMessages.

Returns:
Number of EchoMessages.

getCommitMessageCount

public int getCommitMessageCount()
Get the hashtable which holds the accepted CommitMessages.

Returns:
The hashtable.

isAgreed

public boolean isAgreed()
Indicates whether the agreement for this log entry is reached.

Specified by:
isAgreed in interface IConsensusLog
Returns:
true if an agreement has been reached, false otherwise

setAgreed

public void setAgreed(boolean agreed)
Indicates whether the agreement for this log entry is reached.

Specified by:
setAgreed in interface IConsensusLog
Parameters:
agreed - The new value

isComitted

public boolean isComitted()
Indicates whether the a CommitMessage was send for this log entry.

Specified by:
isComitted in interface IConsensusLog
Returns:
true if so, otherwise false.

setComitted

public void setComitted(boolean comitted)
Set a value which indicates whether the a CommitMessage was send for this log entry.

Specified by:
setComitted in interface IConsensusLog
Parameters:
comitted - The new status

stopTimeout

public void stopTimeout()
Stops the consensus log time out.

Specified by:
stopTimeout in interface IConsensusLog

getConsensusID

public java.lang.String getConsensusID()
Gets the consensus log entry id.

Specified by:
getConsensusID in interface IConsensusLog
Returns:
The id.

getInitMessages

public InitMessage getInitMessages()
Gets the accepted initial message according to this log entry.

Returns:
The initial message.

getInitiatorId

public java.lang.String getInitiatorId()
Gets the id of the infoservice which send the InitMessag.

Specified by:
getInitiatorId in interface IConsensusLog
Returns:
The id.

isRejected

public boolean isRejected()
Indicates whether the a RejectMessage was send for this log entry.

Specified by:
isRejected in interface IConsensusLog
Returns:
true if so, otherwise false.

getLastCommonRandom

public java.lang.String getLastCommonRandom()
Gets the result of the last agreement or an initalized value at start up which is used as round number too.

Specified by:
getLastCommonRandom in interface IConsensusLog
Returns:
The last common random.

isRestarted

public boolean isRestarted()
Indicates whether the a log entry got enough RejectMessages to reset the lastCommonRandom and restart the protocol.

Returns:
true if so, otherwise false.

setRestarted

public void setRestarted(boolean a_restarted)
Sets a value which indicates whether the a log entry got enough RejectMessages to reset the lastCommonRandom and restart the protocol.

Parameters:
a_restarted -

debug

private void debug(java.lang.String a_message)

timeout

public void timeout(java.lang.Object a_value)
On creating a consensuslog a timer will be set. If the timer expired, the log entry will be closed and all stored data will be evaluated.

Specified by:
timeout in interface TimeoutListener