Example #1
0
    /**
     * 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");
        }
      }
    }
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();
      }
    }