Package org.jgroups.protocols
Class MFC
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.FlowControl
-
- org.jgroups.protocols.MFC
-
- Direct Known Subclasses:
MFC_NB
public class MFC extends FlowControl
Simple flow control protocol based on a credit system. Each sender has a number of credits (bytes to send). When the credits have been exhausted, the sender blocks. Each receiver also keeps track of how many credits it has received from a sender. When credits for a sender fall below a threshold, the receiver sends more credits to the sender. Works for both unicast and multicast messages. Note that this protocol must be located towards the top of the stack, or all down_threads from JChannel to this protocol must be set to false ! This is in order to block JChannel.send()/JChannel.down().
This is the second simplified implementation of the same model. The algorithm is sketched out in doc/FlowControl.txt
Changes (Brian) April 2006:- Receivers now send credits to a sender when more than min_credits have been received (rather than when min_credits are left)
- Receivers don't send the full credits (max_credits), but rather the actual number of bytes received
- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected CreditMap
credits
Maintains credits per memberprotected long
last_credit_request
Last time a credit request was sent.protected static FcHeader
MFC_CREDIT_REQUEST_HDR
protected static FcHeader
MFC_REPLENISH_HDR
-
Fields inherited from class org.jgroups.protocols.FlowControl
frag_size, local_addr, max_block_time, max_block_times, max_credits, min_credits, min_threshold, num_credit_requests_received, num_credit_requests_sent, num_credit_responses_received, num_credit_responses_sent, received, running
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description MFC()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CreditMap
createCreditMap(long max_creds)
double
getAverageTimeBlocked()
protected Header
getCreditRequestHeader()
int
getNumberOfBlockings()
protected Header
getReplenishHeader()
protected void
handleCredit(Address sender, long increase)
protected java.lang.Object
handleDownMessage(Message msg)
protected boolean
handleMulticastMessage()
Whether the protocol handles message with dest == null || dest.isMulticastAddress()protected void
handleViewChange(java.util.List<Address> mbrs)
void
init()
Called after instance has been created (null constructor) and before protocol is started.protected boolean
needToSendCreditRequest()
java.lang.String
printCredits()
java.lang.String
printSenderCredits()
void
replenish(Address mbr, long credits)
void
resetStats()
void
stop()
This method is called on aJChannel.disconnect()
.void
unblock()
Allows to unblock a blocked sender from an external program, e.g.-
Methods inherited from class org.jgroups.protocols.FlowControl
adjustCredit, bufferToLong, down, down, getMaxBlockTime, getMaxBlockTime, getMaxBlockTimes, getMaxCredits, getMinCredits, getMinThreshold, getNumberOfCreditRequestsReceived, getNumberOfCreditRequestsSent, getNumberOfCreditResponsesReceived, getNumberOfCreditResponsesSent, getReceiverCreditsFor, handleConfigEvent, handleCreditRequest, handleUpEvent, longToBuffer, maxBlockTime, maxCredits, printMap, printReceiverCredits, sendCredit, sendCreditRequest, setMaxBlockTime, setMaxBlockTimes, setMaxCredits, setMinCredits, setMinThreshold, start, up, up, up
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, destroy, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled
-
-
-
-
Field Detail
-
MFC_REPLENISH_HDR
protected static final FcHeader MFC_REPLENISH_HDR
-
MFC_CREDIT_REQUEST_HDR
protected static final FcHeader MFC_CREDIT_REQUEST_HDR
-
credits
protected CreditMap credits
Maintains credits per member
-
last_credit_request
protected long last_credit_request
Last time a credit request was sent. Used to prevent credit request storms
-
-
Method Detail
-
unblock
public void unblock()
Allows to unblock a blocked sender from an external program, e.g. JMX- Overrides:
unblock
in classFlowControl
-
replenish
public void replenish(Address mbr, long credits)
-
printCredits
public java.lang.String printCredits()
- Overrides:
printCredits
in classFlowControl
-
printSenderCredits
public java.lang.String printSenderCredits()
- Specified by:
printSenderCredits
in classFlowControl
-
getNumberOfBlockings
public int getNumberOfBlockings()
- Specified by:
getNumberOfBlockings
in classFlowControl
-
getAverageTimeBlocked
public double getAverageTimeBlocked()
- Specified by:
getAverageTimeBlocked
in classFlowControl
-
handleMulticastMessage
protected boolean handleMulticastMessage()
Description copied from class:FlowControl
Whether the protocol handles message with dest == null || dest.isMulticastAddress()- Specified by:
handleMulticastMessage
in classFlowControl
- Returns:
-
getReplenishHeader
protected Header getReplenishHeader()
- Specified by:
getReplenishHeader
in classFlowControl
-
getCreditRequestHeader
protected Header getCreditRequestHeader()
- Specified by:
getCreditRequestHeader
in classFlowControl
-
init
public void init() throws java.lang.Exception
Description copied from class:Protocol
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.- Overrides:
init
in classFlowControl
- Throws:
java.lang.Exception
- Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception
-
stop
public void stop()
Description copied from class:Protocol
This method is called on aJChannel.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 flushed- Overrides:
stop
in classFlowControl
-
resetStats
public void resetStats()
- Overrides:
resetStats
in classFlowControl
-
createCreditMap
protected CreditMap createCreditMap(long max_creds)
-
handleDownMessage
protected java.lang.Object handleDownMessage(Message msg)
- Specified by:
handleDownMessage
in classFlowControl
-
needToSendCreditRequest
protected boolean needToSendCreditRequest()
-
handleCredit
protected void handleCredit(Address sender, long increase)
- Specified by:
handleCredit
in classFlowControl
-
handleViewChange
protected void handleViewChange(java.util.List<Address> mbrs)
- Overrides:
handleViewChange
in classFlowControl
-
-