Beispiel #1
0
  /**
   * Setup the Protocol instance acording to the configuration string The following properties are
   * being read by the UDP protocol param mcast_addr - the multicast address to use default is
   * 224.0.0.200 param mcast_port - (int) the port that the multicast is sent on default is 7500
   * param ip_mcast - (boolean) flag whether to use IP multicast - default is true param ip_ttl -
   * Set the default time-to-live for multicast packets sent out on this socket. default is 32
   *
   * @return true if no other properties are left. false if the properties still have data in them,
   *     ie , properties are left over and not handled by the protocol stack
   */
  public boolean setProperties(Properties props) {
    String str, tmp;

    tmp = System.getProperty("UDP.bind_addr");
    if (tmp != null) {
      str = tmp;
    } else {
      str = props.getProperty("bind_addr");
    }
    if (str != null) {
      try {
        bind_addr = InetAddress.getByName(str);
      } catch (UnknownHostException unknown) {
        Trace.fatal("UDP.setProperties()", "(bind_addr): host " + str + " not known");
        return false;
      }
      props.remove("bind_addr");
    }

    str = props.getProperty("bind_port");
    if (str != null) {
      bind_port = new Integer(str).intValue();
      props.remove("bind_port");
    }

    str = props.getProperty("start_port");
    if (str != null) {
      bind_port = new Integer(str).intValue();
      props.remove("start_port");
    }

    str = props.getProperty("port_range");
    if (str != null) {
      port_range = new Integer(str).intValue();
      props.remove("port_range");
    }

    str = props.getProperty("mcast_addr");
    if (str != null) {
      mcast_addr_name = new String(str);
      props.remove("mcast_addr");
    }

    str = props.getProperty("mcast_port");
    if (str != null) {
      mcast_port = new Integer(str).intValue();
      props.remove("mcast_port");
    }

    str = props.getProperty("ip_mcast");
    if (str != null) {
      ip_mcast = new Boolean(str).booleanValue();
      props.remove("ip_mcast");
    }

    str = props.getProperty("ip_ttl");
    if (str != null) {
      ip_ttl = new Integer(str).intValue();
      props.remove("ip_ttl");
    }

    str = props.getProperty("mcast_send_buf_size");
    if (str != null) {
      mcast_send_buf_size = Integer.parseInt(str);
      props.remove("mcast_send_buf_size");
    }

    str = props.getProperty("mcast_recv_buf_size");
    if (str != null) {
      mcast_recv_buf_size = Integer.parseInt(str);
      props.remove("mcast_recv_buf_size");
    }

    str = props.getProperty("ucast_send_buf_size");
    if (str != null) {
      ucast_send_buf_size = Integer.parseInt(str);
      props.remove("ucast_send_buf_size");
    }

    str = props.getProperty("ucast_recv_buf_size");
    if (str != null) {
      ucast_recv_buf_size = Integer.parseInt(str);
      props.remove("ucast_recv_buf_size");
    }

    str = props.getProperty("loopback");
    if (str != null) {
      loopback = new Boolean(str).booleanValue();
      props.remove("loopback");
    }

    // this is deprecated, just left for compatibility (use use_incoming_packet_handler)
    str = props.getProperty("use_packet_handler");
    if (str != null) {
      use_incoming_packet_handler = new Boolean(str).booleanValue();
      props.remove("use_packet_handler");
      Trace.warn(
          "UDP.setProperties()",
          "'use_packet_handler' is deprecated; use 'use_incoming_packet_handler' instead");
    }

    str = props.getProperty("use_incoming_packet_handler");
    if (str != null) {
      use_incoming_packet_handler = new Boolean(str).booleanValue();
      props.remove("use_incoming_packet_handler");
    }

    str = props.getProperty("use_outgoing_packet_handler");
    if (str != null) {
      use_outgoing_packet_handler = new Boolean(str).booleanValue();
      props.remove("use_outgoing_packet_handler");
    }

    str = props.getProperty("max_bundle_size");
    if (str != null) {
      int bundle_size = Integer.parseInt(str);
      if (bundle_size > max_bundle_size) {
        Trace.error(
            "UDP.setProperties()",
            "max_bundle_size ("
                + bundle_size
                + ") is greater than largest UDP fragmentation size ("
                + max_bundle_size
                + ")");
        return false;
      }
      if (bundle_size <= 0) {
        Trace.error("UDP.setProperties()", "max_bundle_size (" + bundle_size + ") is <= 0");
        return false;
      }
      max_bundle_size = bundle_size;
      props.remove("max_bundle_size");
    }

    str = props.getProperty("max_bundle_timeout");
    if (str != null) {
      max_bundle_timeout = Long.parseLong(str);
      if (max_bundle_timeout <= 0) {
        Trace.error(
            "UDP.setProperties()", "max_bundle_timeout of " + max_bundle_timeout + " is invalid");
        return false;
      }
      props.remove("max_bundle_timeout");
    }

    str = props.getProperty("enable_bundling");
    if (str != null) {
      enable_bundling = new Boolean(str).booleanValue();
      props.remove("enable_bundling");
    }

    if (props.size() > 0) {
      System.err.println("UDP.setProperties(): the following properties are not recognized:");
      props.list(System.out);
      return false;
    }

    if (enable_bundling) {
      if (use_outgoing_packet_handler == false) {
        Trace.warn(
            "UDP.setProperties()",
            "enable_bundling is true; setting use_outgoing_packet_handler=true");
      }
      use_outgoing_packet_handler = true;
    }

    return true;
  }
  /** implemented. */
  public void test_list() {
    th.checkPoint("list(java.io.PrintStream)void");
    Properties p = new Properties();
    try {
      p.list((PrintStream) null);
      th.fail("should throw NullPointerException -- 1");
    } catch (NullPointerException ne) {
      th.check(true);
    }

    try {
      p.load(bin);
    } catch (Exception e) {
    }
    p.list(psout);
    byte ba[] = bout.toByteArray();
    Vector v = new Vector();
    Enumeration ek = p.keys();
    String s;
    while (ek.hasMoreElements()) {
      s = (String) ek.nextElement();
      v.add(s + "=" + p.getProperty(s));
    }
    v.add("Smart=move");
    v.add("animal=dog");

    int start, count = 0;
    v.removeElement("longvalue=I'mtryingtogiveavaluelongerthen40characters");
    v.add("longvalue=I'mtryingtogiveavaluelongerthen40char...");
    while (count < ba.length) {
      start = count;
      while (ba[count] != '\n' && count < ba.length) {
        count++;
      }
      s = new String(ba, start, count - start);
      if (!s.startsWith("--")) // list() adds a header
      th.check(v.contains(s), "v does not contain:$" + s + "$");
      v.removeElement(s);
      count++;
    }

    try {
      p.list((PrintStream) null);
      th.fail("should throw NullPointerException -- 2");
    } catch (NullPointerException ne) {
      th.check(true);
    }

    th.checkPoint("list(java.io.PrintWriter)void");
    resetStreams();
    p = new Properties();
    try {
      p.list((PrintWriter) null);
      th.fail("should throw NullPointerException -- 1");
    } catch (NullPointerException ne) {
      th.check(true);
    }

    try {
      p.load(bin);
    } catch (Exception e) {
    }
    p.list(pwout);
    ba = bout.toByteArray();
    v = new Vector();
    ek = p.keys();
    while (ek.hasMoreElements()) {
      s = (String) ek.nextElement();
      v.add(s + "=" + p.getProperty(s));
    }
    v.add("Smart=move");
    v.add("animal=dog");

    count = 0;
    v.removeElement("longvalue=I'mtryingtogiveavaluelongerthen40characters");
    v.add("longvalue=I'mtryingtogiveavaluelongerthen40char...");

    while (count < ba.length) {
      start = count;
      while (ba[count] != '\n' && count < ba.length) {
        count++;
      }
      s = new String(ba, start, count - start);
      if (!s.startsWith("--")) // list() adds a header
      th.check(v.contains(s), "v does not contain:$" + s + "$");
      v.removeElement(s);
      count++;
    }

    try {
      p.list((PrintStream) null);
      th.fail("should throw NullPointerException -- 2");
    } catch (NullPointerException ne) {
      th.check(true);
    }
  }