java.lang.Object
convex.peer.AThreadedComponent
convex.peer.BeliefPropagator
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Minimum delay between successive Belief broadcastsstatic final int
Polling period for Belief propagator loopstatic final int
Time between full Belief broadcastsstatic final int
Fields inherited from class convex.peer.AThreadedComponent
server, thread
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Message
protected Message
long
protected String
protected void
loop()
protected boolean
maybeBroadcast
(boolean updated) protected boolean
maybeMergeBeliefs
(Belief... newBeliefs) Checks for mergeable remote beliefs, and if found merge and update own belief.protected boolean
maybeUpdateBelief
(Belief newBelief) Handle general Belief update, taking belief registered in newBeliefsprotected boolean
mergeBeliefMessage
(HashMap<AccountKey, SignedData<Order>> orders, Message m) Merge a single Belief message into a map of accumulated latest Ordersboolean
queueBelief
(Message beliefMessage) Queues a Belief Message for processingvoid
setBeliefUpdateObserver
(Consumer<Belief> observer) Sets the observer for belief updatesvoid
setOrderUpdateObserver
(Consumer<SignedData<Order>> orderUpdateObserver) Sets the observer for order updatesvoid
start()
Start the threaded componentMethods inherited from class convex.peer.AThreadedComponent
close, getLoad
-
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_DELAYTime between full Belief broadcasts- See Also:
-
BELIEF_BROADCAST_DELAY
public static final int BELIEF_BROADCAST_DELAYMinimum delay between successive Belief broadcasts- See Also:
-
BELIEF_BROADCAST_POLL_TIME
public static final int BELIEF_BROADCAST_POLL_TIMEPolling period for Belief propagator loop- See Also:
-
-
Constructor Details
-
BeliefPropagator
-
-
Method Details
-
getBeliefBroadcastCount
public long getBeliefBroadcastCount() -
queueBelief
Queues a Belief Message for processing- Parameters:
beliefMessage
- Belief Message to queue- Returns:
- True if Belief is queued successfully
-
loop
- Specified by:
loop
in classAThreadedComponent
- Throws:
InterruptedException
-
maybeBroadcast
- Throws:
InterruptedException
-
start
public void start()Description copied from class:AThreadedComponent
Start the threaded component- Overrides:
start
in classAThreadedComponent
-
maybeUpdateBelief
Handle general Belief update, taking belief registered in newBeliefs- Returns:
- true if Peer Belief changed, false otherwise
- Throws:
InterruptedException
-
maybeMergeBeliefs
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
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
- Throws:
IOException
-
createQuickUpdateMessage
- Throws:
IOException
-
getLastBroadcastBelief
-
getThreadName
- Specified by:
getThreadName
in classAThreadedComponent
-
setOrderUpdateObserver
Sets the observer for order updates- Parameters:
orderUpdateObserver
- New Observer for ORder updates
-
setBeliefUpdateObserver
Sets the observer for belief updates- Parameters:
observer
- New Observer for Belief updates
-