infoservice.agreement.multicast
Class AbstractEMCAdapter

java.lang.Object
  extended by infoservice.agreement.multicast.AbstractEMCAdapter
All Implemented Interfaces:
IInfoService
Direct Known Subclasses:
InfoserviceEMCAdapter

public abstract class AbstractEMCAdapter
extends java.lang.Object
implements IInfoService


Field Summary
private  boolean doNotHandleAnything
          LERNGRUPPE A boolean value, which indicates whether the handler is in stop mode.
protected  boolean m_activeAgreementStarted
          LERNGRUPPE A boolean value, which indicates whether an agreement is started yet.
protected  IAgreementHandler m_agreementHandler
          LERNGRUPPE The agreement handler.
private  boolean m_beInPassiveMode
          LERNGRUPPE A boolean value, which indicates whether an agreement is in passive mode yet.
protected  IAgreementLog m_log
          LERNGRUPPE A logger.
private  boolean m_mustBeRestartedForSecurityReason
          LERNGRUPPE A boolean value, which indicates whether the handler have to restart the protocol.
 
Constructor Summary
AbstractEMCAdapter(IAgreementLog a_log)
          LERNGRUPPE The constructor sets only the logger.
 
Method Summary
protected abstract  void buildCascades(long l)
          Start to build the new cascades.
protected  void debug(java.lang.String a_msg)
          Loggs a debug message.
protected  void error(java.lang.String a_msg)
          Loggs a error message.
protected  void fatal(java.lang.String a_msg)
          Loggs a fatal message.
abstract  java.lang.String getIdentifier()
          Returns an unique identifier for this IInfoService
 IAgreementLog getLog()
          Gets the current logger.
abstract  int getNumberOfAllInfoservices()
          Returns the number of known InfoServices
 void handleMessage(IAgreementMessage a_msg)
          LERNGRUPPE Handle incomming messages.
protected  void info(java.lang.String a_msg)
          Loggs a info message.
abstract  void multicastMessage(IAgreementMessage a_message)
          Multicasts the given message to all known InfoServices (except this one)
 void notifyAgreement(java.lang.Long a_oldCommonRandomSeed, java.lang.Long a_newCommonRandomSeed)
          LERNGRUPPE This gets called when the AgreementHandler has reached angreement with the others.
protected abstract  void prepareStart()
          This method is called in startAgreementCommitmentProtocol() befor the call will be delegated.
private  void reset()
          Resets the state variables.
private  void restartAgreement()
          LERNGRUPPE Some times a restart of the protocol is necessary.
abstract  void sendMessageTo(java.lang.String a_id, IAgreementMessage a_message)
          Sends the given message to the InfoService with the given ID
 void setIAgreementHandler(IAgreementHandler p_agreementhandler)
          Sets the given AgreementHandler.
 void setLog(IAgreementLog a_log)
          Set the Logger.
 void startAdapter()
          LERNGRUPPE Call this method to start the adapter.
protected  void startAgreementCommitmentProtocol()
          LERNGRUPPE Starts the protocol after checking some status values for security reasons.
protected abstract  void startListening()
          Initialize the message queue handler thread.
 void startListeningMode()
          LERNGRUPPE To start the protocoll we need two steps.
 void startProtocolByOperator()
          LERNGRUPPE Sometimes for testing reasons only a operator have to start the protocol.
protected  void tryToStartAgreementHour()
          LERNGRUPPE Watch at the clock and start agreement at the right time.
protected  void tryToStartAgreementMinute()
          LERNGRUPPE Watch at the clock and start agreement at the right time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_agreementHandler

protected IAgreementHandler m_agreementHandler
LERNGRUPPE The agreement handler. He encapsuletes all the logic for getting an common random number.


m_activeAgreementStarted

protected boolean m_activeAgreementStarted
LERNGRUPPE A boolean value, which indicates whether an agreement is started yet.


doNotHandleAnything

private boolean doNotHandleAnything
LERNGRUPPE A boolean value, which indicates whether the handler is in stop mode. This means that no incomming message will be handled.


m_mustBeRestartedForSecurityReason

private boolean m_mustBeRestartedForSecurityReason
LERNGRUPPE A boolean value, which indicates whether the handler have to restart the protocol. This is for security reasons. In fact, we set this variable if the used last common random is equals to the default value.


m_log

protected IAgreementLog m_log
LERNGRUPPE A logger.


m_beInPassiveMode

private boolean m_beInPassiveMode
LERNGRUPPE A boolean value, which indicates whether an agreement is in passive mode yet.

Constructor Detail

AbstractEMCAdapter

public AbstractEMCAdapter(IAgreementLog a_log)
LERNGRUPPE The constructor sets only the logger. To start the adapter call setIAgreementHandler(IAgreementHandler p_agreementhandler) and at next startAdapter()-method. We have to do that explicitly an NOT in the constructor. So we can take care that all infoservices know about each other befor starting the protocol.

Parameters:
a_log - The logger to use.
Method Detail

setIAgreementHandler

public void setIAgreementHandler(IAgreementHandler p_agreementhandler)
Sets the given AgreementHandler. You have to do that BEFORE you call startAdapter()-method.

Parameters:
p_agreementhandler -

startAdapter

public void startAdapter()
LERNGRUPPE Call this method to start the adapter. He will poll the tryToStartAgreement()-method within an endless loop. Take care that setIAgreementHandler(IAgreementHandler p_agreementhandler) was called before!!!


tryToStartAgreementMinute

protected void tryToStartAgreementMinute()
LERNGRUPPE Watch at the clock and start agreement at the right time.


tryToStartAgreementHour

protected void tryToStartAgreementHour()
LERNGRUPPE Watch at the clock and start agreement at the right time.


handleMessage

public void handleMessage(IAgreementMessage a_msg)
LERNGRUPPE Handle incomming messages. And start agreement by yourself if not done so.

Specified by:
handleMessage in interface IInfoService
Parameters:
The - message.

notifyAgreement

public void notifyAgreement(java.lang.Long a_oldCommonRandomSeed,
                            java.lang.Long a_newCommonRandomSeed)
LERNGRUPPE This gets called when the AgreementHandler has reached angreement with the others. When this happens it is time to wire new cascades :-)

Specified by:
notifyAgreement in interface IInfoService
Parameters:
a_newCommonRandomSeed - the agreed-upon random seed

restartAgreement

private void restartAgreement()
LERNGRUPPE Some times a restart of the protocol is necessary. This method calls startAgreementCommitmentProtocol() after waiting.


startListeningMode

public void startListeningMode()
LERNGRUPPE To start the protocoll we need two steps. At first we will listen for incomming messages. After spending some time doing that we start with our own random value. This method starts step one. The listening mode.


startProtocolByOperator

public void startProtocolByOperator()
LERNGRUPPE Sometimes for testing reasons only a operator have to start the protocol. This method do that an should never called in real life.


startAgreementCommitmentProtocol

protected void startAgreementCommitmentProtocol()
LERNGRUPPE Starts the protocol after checking some status values for security reasons. It delegates the call to the agreement handler.


reset

private void reset()
Resets the state variables.


buildCascades

protected abstract void buildCascades(long l)
Start to build the new cascades.

Parameters:
l - A long value which represents the common random number.

startListening

protected abstract void startListening()
Initialize the message queue handler thread. At this point in time incomming messages will be queued but not yet handled.


prepareStart

protected abstract void prepareStart()
                              throws java.lang.NullPointerException
This method is called in startAgreementCommitmentProtocol() befor the call will be delegated.

Throws:
java.lang.NullPointerException

sendMessageTo

public abstract void sendMessageTo(java.lang.String a_id,
                                   IAgreementMessage a_message)
Sends the given message to the InfoService with the given ID

Specified by:
sendMessageTo in interface IInfoService
Parameters:
a_id - The ID of the InfoService
a_echoMessage - The message

multicastMessage

public abstract void multicastMessage(IAgreementMessage a_message)
Multicasts the given message to all known InfoServices (except this one)

Specified by:
multicastMessage in interface IInfoService
Parameters:
a_message -

getIdentifier

public abstract java.lang.String getIdentifier()
Returns an unique identifier for this IInfoService

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

getNumberOfAllInfoservices

public abstract int getNumberOfAllInfoservices()
Returns the number of known InfoServices

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

setLog

public void setLog(IAgreementLog a_log)
Set the Logger.

Parameters:
a_log - A logger.

getLog

public IAgreementLog getLog()
Gets the current logger.

Returns:

debug

protected void debug(java.lang.String a_msg)
Loggs a debug message.

Parameters:
a_msg - A Message.

info

protected void info(java.lang.String a_msg)
Loggs a info message.

Parameters:
a_msg - A Message.

error

protected void error(java.lang.String a_msg)
Loggs a error message.

Parameters:
a_msg - A Message.

fatal

protected void fatal(java.lang.String a_msg)
Loggs a fatal message.

Parameters:
a_msg - A Message.