protected void handleViewChange(List<Address> mbrs) { super.handleViewChange(mbrs); Set<Address> keys = new HashSet<Address>(credits.keys()); for (Address key : keys) { if (!mbrs.contains(key)) credits.remove(key); } for (Address key : mbrs) credits.putIfAbsent(key); }
protected void handleCredit(Address sender, long increase) { credits.replenish(sender, increase); if (log.isTraceEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("received " + increase + " credits from ") .append(sender) .append(", new credits for " + sender + " : ") .append(credits.get(sender) + ", min_credits=" + credits.getMinCredits()); log.trace(sb); } }
protected Object handleDownMessage(final Event evt, final Message msg, Address dest, int length) { if (dest != null) // 2nd line of defense, not really needed return down_prot.down(evt); long block_time = max_block_times != null ? getMaxBlockTime(length) : max_block_time; while (running) { boolean rc = credits.decrement(length, block_time); if (rc || max_block_times != null || !running) break; if (needToSendCreditRequest()) { List<Tuple<Address, Long>> targets = credits.getMembersWithCreditsLessThan(min_credits); for (Tuple<Address, Long> tuple : targets) sendCreditRequest(tuple.getVal1(), Math.min(max_credits, max_credits - tuple.getVal2())); } } // send message - either after regular processing, or after blocking (when enough credits are // available again) return down_prot.down(evt); }
public void stop() { super.stop(); credits.clear(); }
@ManagedAttribute(description = "Total time (ms) spent in flow control block") public long getTotalTimeBlocked() { return credits.getTotalBlockTime(); }
@ManagedAttribute(description = "Number of times flow control blocks sender") public int getNumberOfBlockings() { return credits.getNumBlockings(); }
@ManagedOperation(description = "Print sender credits") public String printSenderCredits() { return credits.toString(); }
@ManagedOperation(description = "Print credits") public String printCredits() { return super.printCredits() + "\nsenders min credits: " + credits.computeLowestCreditWithAccumulated(); }
/** Allows to unblock a blocked sender from an external program, e.g. JMX */ @ManagedOperation(description = "Unblock a sender") public void unblock() { if (log.isTraceEnabled()) log.trace("unblocking the sender and replenishing all members"); credits.replenishAll(); }