@ManagedOperation( description = "Sends a STABLE message to all senders. This causes message purging and potential" + " retransmissions from senders") public void sendStableMessages() { for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) { Address dest = entry.getKey(); ReceiverEntry val = entry.getValue(); NakReceiverWindow win = val != null ? val.received_msgs : null; if (win != null) { long[] tmp = win.getDigest(); long low = tmp[0], high = tmp[1]; if (val.last_highest == high) { if (val.num_stable_msgs >= val.max_stable_msgs) { continue; } else val.num_stable_msgs++; } else { val.last_highest = high; val.num_stable_msgs = 1; } sendStableMessage(dest, val.recv_conn_id, low, high); } } }
@ManagedOperation public String printConnections() { StringBuilder sb = new StringBuilder(); if (!send_table.isEmpty()) { sb.append("send connections:\n"); for (Map.Entry<Address, SenderEntry> entry : send_table.entrySet()) { sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n"); } } if (!recv_table.isEmpty()) { sb.append("\nreceive connections:\n"); for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) { sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n"); } } return sb.toString(); }
@ManagedOperation(description = "Prints the contents of the send windows for all members") public String printSendWindowMessages() { StringBuilder ret = new StringBuilder(local_addr + ":\n"); for (Map.Entry<Address, SenderEntry> entry : send_table.entrySet()) { Address addr = entry.getKey(); Table<Message> buf = entry.getValue().sent_msgs; ret.append(addr).append(": ").append(buf.toString()).append('\n'); } return ret.toString(); }
public void run() { for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) { Address target = entry.getKey(); // target to send retransmit requests to ReceiverEntry val = entry.getValue(); Table<Message> buf = val != null ? val.received_msgs : null; if (buf != null && buf.getNumMissing() > 0) { SeqnoList missing = buf.getMissing(); if (missing != null) retransmit(missing, target); } } }
@ManagedOperation(description = "Returns the sizes of all NakReceiverWindow.RetransmitTables") public String printRetransmitTableSizes() { StringBuilder sb = new StringBuilder(); for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) { NakReceiverWindow win = entry.getValue().received_msgs; sb.append(entry.getKey() + ": ") .append(win.getRetransmitTableSize()) .append(" (capacity=" + win.getRetransmitTableCapacity()) .append(", fill factor=" + win.getRetransmitTableFillFactor() + "%)\n"); } return sb.toString(); }
@ManagedOperation( description = "Closes connections that have been idle for more than conn_expiry_timeout ms") public void reapIdleConnections() { if (conn_expiry_timeout <= 0) return; // remove expired connections from send_table for (Map.Entry<Address, SenderEntry> entry : send_table.entrySet()) { SenderEntry val = entry.getValue(); long age = val.age(); if (age >= conn_expiry_timeout) { removeSendConnection(entry.getKey()); if (log.isDebugEnabled()) log.debug( local_addr + ": removed expired connection for " + entry.getKey() + " (" + age + " ms old) from send_table"); } } // remove expired connections from recv_table for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) { ReceiverEntry val = entry.getValue(); long age = val.age(); if (age >= conn_expiry_timeout) { removeReceiveConnection(entry.getKey()); if (log.isDebugEnabled()) log.debug( local_addr + ": removed expired connection for " + entry.getKey() + " (" + age + " ms old) from recv_table"); } } }
String dumpMessages(HashMap map) { StringBuffer sb = new StringBuffer(); Map.Entry entry; List l; if (map != null) { synchronized (map) { for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) { entry = (Map.Entry) it.next(); l = (List) entry.getValue(); sb.append(entry.getKey()).append(": "); sb.append(l.size()).append(" msgs\n"); } } } return sb.toString(); }
void bundleAndSend() { Map.Entry entry; IpAddress dest; ObjectOutputStream out; InetAddress addr; int port; byte[] data; List l; if (Trace.trace) { Trace.info( "UDP.BundlingOutgoingPacketHandler.bundleAndSend()", "\nsending msgs:\n" + dumpMessages(msgs)); } synchronized (msgs) { stopTimer(); if (msgs.size() == 0) { return; } for (Iterator it = msgs.entrySet().iterator(); it.hasNext(); ) { entry = (Map.Entry) it.next(); dest = (IpAddress) entry.getKey(); addr = dest.getIpAddress(); port = dest.getPort(); l = (List) entry.getValue(); try { out_stream.reset(); // BufferedOutputStream bos=new BufferedOutputStream(out_stream); out_stream.write(Version.version_id, 0, Version.version_id.length); // write the version // bos.write(Version.version_id, 0, Version.version_id.length); // write the version out = new ObjectOutputStream(out_stream); // out=new ObjectOutputStream(bos); l.writeExternal(out); out.close(); // needed if out buffers its output to out_stream data = out_stream.toByteArray(); doSend(data, addr, port); } catch (IOException e) { Trace.error( "UDP.BundlingOutgoingPacketHandle.bundleAndSend()", "exception sending msg (to dest=" + dest + "): " + e); } } msgs.clear(); } }
protected void handleJmx(Map<String, String> map, String input) { Map<String, Object> tmp_stats; int index = input.indexOf("="); if (index > -1) { List<String> list = null; String protocol_name = input.substring(index + 1); index = protocol_name.indexOf("."); if (index > -1) { String rest = protocol_name; protocol_name = protocol_name.substring(0, index); String attrs = rest.substring(index + 1); // e.g. "num_sent,msgs,num_received_msgs" list = Util.parseStringList(attrs, ","); // check if there are any attribute-sets in the list for (Iterator<String> it = list.iterator(); it.hasNext(); ) { String tmp = it.next(); index = tmp.indexOf("="); if (index != -1) { String attrname = tmp.substring(0, index); String attrvalue = tmp.substring(index + 1); Protocol prot = prot_stack.findProtocol(protocol_name); Field field = prot != null ? Util.getField(prot.getClass(), attrname) : null; if (field != null) { Object value = MethodCall.convert(attrvalue, field.getType()); if (value != null) prot.setValue(attrname, value); } else { // try to find a setter for X, e.g. x(type-of-x) or setX(type-of-x) ResourceDMBean.Accessor setter = ResourceDMBean.findSetter( prot, attrname); // Util.getSetter(prot.getClass(), attrname); if (setter != null) { try { Class<?> type = setter instanceof ResourceDMBean.FieldAccessor ? ((ResourceDMBean.FieldAccessor) setter).getField().getType() : setter instanceof ResourceDMBean.MethodAccessor ? ((ResourceDMBean.MethodAccessor) setter) .getMethod() .getParameterTypes()[0] .getClass() : null; Object converted_value = MethodCall.convert(attrvalue, type); setter.invoke(converted_value); } catch (Exception e) { log.error("unable to invoke %s() on %s: %s", setter, protocol_name, e); } } else log.warn(Util.getMessage("FieldNotFound"), attrname, protocol_name); } it.remove(); } } } tmp_stats = dumpStats(protocol_name, list); if (tmp_stats != null) { for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) { Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue(); String key = entry.getKey(); map.put(key, tmp_map != null ? tmp_map.toString() : null); } } } else { tmp_stats = dumpStats(); if (tmp_stats != null) { for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) { Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue(); String key = entry.getKey(); map.put(key, tmp_map != null ? tmp_map.toString() : null); } } } }