Module convex.peer
Package convex.peer

Class BeliefPropagator

java.lang.Object
convex.peer.AThreadedComponent
convex.peer.BeliefPropagator

public class BeliefPropagator extends AThreadedComponent
Component class to handle propagation of new Beliefs from a Peer Overall logic: 1. We want to propagate a new Belief delta as fast as possible once one is received 2. We want to pause to ensure that as many peers as possible have received the delta
  • Field Details

    • BELIEF_REBROADCAST_DELAY

      public static final int BELIEF_REBROADCAST_DELAY
      See Also:
    • BELIEF_FULL_BROADCAST_DELAY

      public static final int BELIEF_FULL_BROADCAST_DELAY
      Time between full Belief broadcasts
      See Also:
    • BELIEF_BROADCAST_DELAY

      public static final int BELIEF_BROADCAST_DELAY
      Minimum delay between successive Belief broadcasts
      See Also:
    • BELIEF_BROADCAST_POLL_TIME

      public static final int BELIEF_BROADCAST_POLL_TIME
      Polling period for Belief propagator loop
      See Also:
  • Constructor Details

    • BeliefPropagator

      public BeliefPropagator(Server server)
  • Method Details

    • getBeliefBroadcastCount

      public long getBeliefBroadcastCount()
    • queueBelief

      public boolean queueBelief(Message beliefMessage)
      Queues a Belief Message for processing
      Parameters:
      beliefMessage - Belief Message to queue
      Returns:
      True if Belief is queued successfully
    • loop

      protected void loop() throws InterruptedException
      Specified by:
      loop in class AThreadedComponent
      Throws:
      InterruptedException
    • maybeBroadcast

      protected boolean maybeBroadcast(boolean updated) throws InterruptedException
      Throws:
      InterruptedException
    • start

      public void start()
      Description copied from class: AThreadedComponent
      Start the threaded component
      Overrides:
      start in class AThreadedComponent
    • maybeUpdateBelief

      protected boolean maybeUpdateBelief(Belief newBelief)
      Handle general Belief update, taking belief registered in newBeliefs
      Returns:
      true if Peer Belief changed, false otherwise
      Throws:
      InterruptedException
    • maybeMergeBeliefs

      protected boolean maybeMergeBeliefs(Belief... newBeliefs)
      Checks for mergeable remote beliefs, and if found merge and update own belief.
      Parameters:
      newBelief -
      Returns:
      True if Peer Belief Order was changed, false otherwise.
    • mergeBeliefMessage

      protected boolean mergeBeliefMessage(HashMap<AccountKey,SignedData<Order>> orders, Message m)
      Merge a single Belief message into a map of accumulated latest Orders
      Parameters:
      orders -
      m -
      Returns:
      true if there was any updated order Order, false otherwise
    • createFullUpdateMessage

      protected Message createFullUpdateMessage() throws IOException
      Throws:
      IOException
    • createQuickUpdateMessage

      protected Message createQuickUpdateMessage() throws IOException
      Throws:
      IOException
    • getLastBroadcastBelief

      public Belief getLastBroadcastBelief()
    • getThreadName

      protected String getThreadName()
      Specified by:
      getThreadName in class AThreadedComponent
    • setOrderUpdateObserver

      public void setOrderUpdateObserver(Consumer<SignedData<Order>> orderUpdateObserver)
      Sets the observer for order updates
      Parameters:
      orderUpdateObserver - New Observer for ORder updates
    • setBeliefUpdateObserver

      public void setBeliefUpdateObserver(Consumer<Belief> observer)
      Sets the observer for belief updates
      Parameters:
      observer - New Observer for Belief updates