public String toString() { StringBuilder buf = new StringBuilder("Fragmentation list contains "); synchronized (frag_tables) { buf.append(frag_tables.size()).append(" tables\n"); for (Iterator<Entry<Address, FragmentationTable>> it = frag_tables.entrySet().iterator(); it.hasNext(); ) { Entry<Address, FragmentationTable> entry = it.next(); buf.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n"); } } return buf.toString(); }
/** * returns a list of all the senders that have fragmentation tables opened. * * @return an array of all the senders in the fragmentation list */ public Address[] getSenders() { Address[] result; int index = 0; synchronized (frag_tables) { result = new Address[frag_tables.size()]; for (Iterator<Address> it = frag_tables.keySet().iterator(); it.hasNext(); ) { result[index++] = it.next(); } } return result; }
/** * Adds a fragmentation table for this particular sender If this sender already has a * fragmentation table, an IllegalArgumentException will be thrown. * * @param sender - the address of the sender, cannot be null * @param table - the fragmentation table of this sender, cannot be null * @throws IllegalArgumentException if an entry for this sender already exist */ public void add(Address sender, FragmentationTable table) throws IllegalArgumentException { synchronized (frag_tables) { FragmentationTable healthCheck = frag_tables.get(sender); if (healthCheck == null) { frag_tables.put(sender, table); } else { throw new IllegalArgumentException( "Sender <" + sender + "> already exists in the fragementation list"); } } }
/** * removes the fragmentation table from the list. after this operation, the fragementation list * will no longer hold a reference to this sender's fragmentation table * * @param sender - the sender who's fragmentation table you wish to remove, cannot be null * @return true if the table was removed, false if the sender doesn't have an entry */ public boolean remove(Address sender) { synchronized (frag_tables) { boolean result = containsSender(sender); frag_tables.remove(sender); return result; } }
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 handleMessage(Message msg) throws Exception { Address dest = msg.getDest(); long len; List tmp; len = msg.size(); // todo: use msg.getLength() instead of msg.getSize() if (len > max_bundle_size) { throw new Exception( "UDP.BundlingOutgoingPacketHandler.handleMessage(): " + "message size (" + len + ") is greater than UDP fragmentation size. " + "Set the fragmentation/bundle size in FRAG and UDP correctly"); } if (total_bytes + len >= max_bundle_size) { if (Trace.trace) { Trace.info( "UDP.BundlingOutgoingPacketHandler.handleMessage()", "sending " + total_bytes + " bytes"); } bundleAndSend(); // send all pending message and clear table total_bytes = 0; } synchronized (msgs) { tmp = (List) msgs.get(dest); if (tmp == null) { tmp = new List(); msgs.put(dest, tmp); } tmp.add(msg); total_bytes += len; } if (!timer_running) { // first message to be bundled startTimer(); } }
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 handleConfigEvent(HashMap map) { if (map == null) { return; } if (map.containsKey("additional_data")) { additional_data = (byte[]) map.get("additional_data"); } if (map.containsKey("send_buf_size")) { mcast_send_buf_size = ((Integer) map.get("send_buf_size")).intValue(); ucast_send_buf_size = mcast_send_buf_size; } if (map.containsKey("recv_buf_size")) { mcast_recv_buf_size = ((Integer) map.get("recv_buf_size")).intValue(); ucast_recv_buf_size = mcast_recv_buf_size; } setBufferSizes(); }
/** * returns true if this sender already holds a fragmentation for this sender, false otherwise * * @param sender - the sender, cannot be null * @return true if this sender already has a fragmentation table */ public boolean containsSender(Address sender) { synchronized (frag_tables) { return frag_tables.containsKey(sender); } }
/** * returns a fragmentation table for this sender returns null if the sender doesn't have a * fragmentation table * * @return the fragmentation table for this sender, or null if no table exist */ public FragmentationTable get(Address sender) { synchronized (frag_tables) { return frag_tables.get(sender); } }