Example #1
0
    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();
      }
    }
Example #2
0
    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();
      }
    }
Example #3
0
 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();
 }
Example #4
0
 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();
 }