public abstract class FlowControl extends Protocol
Modifier and Type | Class and Description |
---|---|
protected class |
FlowControl.Credit |
Modifier and Type | Field and Description |
---|---|
protected int |
frag_size |
protected boolean |
ignore_synchronous_response
Whether an up thread that comes back down should be allowed to bypass blocking if all credits are exhausted.
|
protected Address |
local_addr |
protected long |
max_block_time
Max time (in milliseconds) to block.
|
protected java.util.Map<java.lang.Long,java.lang.Long> |
max_block_times
Defines the max number of milliseconds for a message to block before being sent, based on the length of
the message.
|
protected long |
max_credits
Max number of bytes to send per receiver until an ack must be received before continuing sending
|
protected long |
min_credits
Computed as max_credits times min_theshold.
|
protected double |
min_threshold
If we're down to (min_threshold * max_credits) bytes for P, we send more credits to P.
|
protected int |
num_credit_requests_received |
protected int |
num_credit_requests_sent |
protected int |
num_credit_responses_received |
protected int |
num_credit_responses_sent |
protected java.util.Map<Address,FlowControl.Credit> |
received
Keeps track of credits per member at the receiver.
|
protected boolean |
running
Whether FlowControl is still running, this is set to false when the protocol terminates (on stop())
|
after_creation_hook, down_prot, ergonomics, id, log, name, stack, stats, up_prot
Constructor and Description |
---|
FlowControl() |
Modifier and Type | Method and Description |
---|---|
protected long |
adjustCredit(java.util.Map<Address,FlowControl.Credit> map,
Address sender,
int length)
Check whether sender has enough credits left.
|
protected static long |
bufferToLong(byte[] buf,
int offset) |
java.lang.Object |
down(Event evt)
An event is to be sent down the stack.
|
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats() |
abstract double |
getAverageTimeBlocked() |
protected abstract Header |
getCreditRequestHeader() |
long |
getMaxBlockTime() |
protected long |
getMaxBlockTime(long length) |
java.lang.String |
getMaxBlockTimes() |
long |
getMaxCredits() |
long |
getMinCredits() |
double |
getMinThreshold() |
abstract int |
getNumberOfBlockings() |
int |
getNumberOfCreditRequestsReceived() |
int |
getNumberOfCreditRequestsSent() |
int |
getNumberOfCreditResponsesReceived() |
int |
getNumberOfCreditResponsesSent() |
protected abstract Header |
getReplenishHeader() |
protected void |
handleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> info) |
protected abstract void |
handleCredit(Address sender,
long increase) |
protected void |
handleCreditRequest(java.util.Map<Address,FlowControl.Credit> map,
Address sender,
long requested_credits) |
protected abstract java.lang.Object |
handleDownMessage(Event evt,
Message msg,
Address dest,
int length) |
protected abstract boolean |
handleMulticastMessage()
Whether the protocol handles message with dest == null || dest.isMulticastAddress()
|
protected void |
handleUpEvent(Message msg,
FcHeader hdr) |
protected void |
handleViewChange(java.util.List<Address> mbrs) |
void |
init()
Called after instance has been created (null constructor) and before protocol is started.
|
protected static byte[] |
longToBuffer(long num) |
java.lang.String |
printCredits() |
protected static java.lang.String |
printMap(java.util.Map<Address,FlowControl.Credit> m) |
java.lang.String |
printReceiverCredits() |
abstract java.lang.String |
printSenderCredits() |
void |
resetStats() |
protected void |
sendCredit(Address dest,
long credits) |
protected void |
sendCreditRequest(Address dest,
long credits_needed)
We cannot send this request as OOB message, as the credit request needs to queue up behind the regular messages;
if a receiver cannot process the regular messages, that is a sign that the sender should be throttled !
|
void |
setMaxBlockTime(long t) |
void |
setMaxBlockTimes(java.lang.String str) |
void |
setMaxCredits(long max_credits) |
void |
setMinCredits(long min_credits) |
void |
setMinThreshold(double min_threshold) |
void |
start()
This method is called on a
Channel.connect(String) . |
void |
stop()
This method is called on a
Channel.disconnect() . |
void |
unblock()
Allows to unblock all blocked senders from an external program, e.g.
|
java.lang.Object |
up(Event evt)
An event was received from the layer below.
|
void |
up(MessageBatch batch)
Sends up a multiple messages in a
MessageBatch . |
accept, afterCreationHook, destroy, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, statsEnabled
protected long max_credits
protected long max_block_time
protected java.util.Map<java.lang.Long,java.lang.Long> max_block_times
protected double min_threshold
protected long min_credits
protected boolean ignore_synchronous_response
protected int num_credit_requests_received
protected int num_credit_requests_sent
protected int num_credit_responses_sent
protected int num_credit_responses_received
protected final java.util.Map<Address,FlowControl.Credit> received
protected Address local_addr
protected volatile boolean running
protected int frag_size
public void resetStats()
resetStats
in class Protocol
public long getMaxCredits()
public void setMaxCredits(long max_credits)
public double getMinThreshold()
public void setMinThreshold(double min_threshold)
public long getMinCredits()
public void setMinCredits(long min_credits)
public long getMaxBlockTime()
public void setMaxBlockTime(long t)
public void setMaxBlockTimes(java.lang.String str)
public java.lang.String getMaxBlockTimes()
public abstract int getNumberOfBlockings()
public abstract double getAverageTimeBlocked()
public int getNumberOfCreditRequestsReceived()
public int getNumberOfCreditRequestsSent()
public int getNumberOfCreditResponsesReceived()
public int getNumberOfCreditResponsesSent()
public abstract java.lang.String printSenderCredits()
public java.lang.String printReceiverCredits()
public java.lang.String printCredits()
public java.util.Map<java.lang.String,java.lang.Object> dumpStats()
protected long getMaxBlockTime(long length)
protected abstract boolean handleMulticastMessage()
protected abstract void handleCredit(Address sender, long increase)
protected abstract Header getReplenishHeader()
protected abstract Header getCreditRequestHeader()
public void unblock()
public void init() throws java.lang.Exception
Protocol
public void start() throws java.lang.Exception
Protocol
Channel.connect(String)
. Starts work.
Protocols are connected and queues are ready to receive events.
Will be called from bottom to top. This call will replace
the START and START_OK events.start
in class Protocol
java.lang.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack
to fail, so Channel.connect(String)
will throw an exceptionpublic void stop()
Protocol
Channel.disconnect()
. Stops work (e.g. by closing multicast socket).
Will be called from top to bottom. This means that at the time of the method invocation the
neighbor protocol below is still working. This method will replace the
STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that
when this method is called all messages in the down queue will have been flushedpublic java.lang.Object down(Event evt)
Protocol
down_prot.down()
. In case of a GET_ADDRESS event (which tries to
retrieve the stack's address from one of the bottom layers), the layer may need to send
a new response event back up the stack using up_prot.up()
.public java.lang.Object up(Event evt)
Protocol
down_prot.down()
or c) the event (or another event) is sent up
the stack using up_prot.up()
.public void up(MessageBatch batch)
Protocol
MessageBatch
. The sender of the batch is always the same, and so is the
destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed
messages, although the transport itself will create initial MessageBatches that contain only either OOB or
regular messages.
The default processing below sends messages up the stack individually, based on a matching criteria
(calling Protocol.accept(org.jgroups.Message)
), and - if true - calls Protocol.up(org.jgroups.Event)
for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped.
Subclasses should check if there are any messages destined for them (e.g. using
MessageBatch.getMatchingMessages(short,boolean)
), then possibly remove and process them and finally pass
the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all
encrypted messages in the batch, not remove them, and pass the batch up when done.protected void handleConfigEvent(java.util.Map<java.lang.String,java.lang.Object> info)
protected abstract java.lang.Object handleDownMessage(Event evt, Message msg, Address dest, int length)
protected long adjustCredit(java.util.Map<Address,FlowControl.Credit> map, Address sender, int length)
map
- The hashmap to usesender
- The address of the senderlength
- The number of bytes received by this message. We don't care about the size of the headers for
the purpose of flow controlprotected void handleCreditRequest(java.util.Map<Address,FlowControl.Credit> map, Address sender, long requested_credits)
map
- The map to modifysender
- The sender who requests creditsrequested_credits
- Number of bytes that the sender has left to send messages to usprotected void sendCredit(Address dest, long credits)
protected void sendCreditRequest(Address dest, long credits_needed)
dest
- The member to which we send the credit requestcredits_needed
- The number of bytes (of credits) left for destprotected void handleViewChange(java.util.List<Address> mbrs)
protected static java.lang.String printMap(java.util.Map<Address,FlowControl.Credit> m)
protected static byte[] longToBuffer(long num)
protected static long bufferToLong(byte[] buf, int offset)
Copyright © 1998-2020 Red Hat. All Rights Reserved.