Ejemplo n.º 1
0
  public static void main(String[] args) throws Exception {
    System.out.println("Californium (Cf) Observe Benchmark Client");
    System.out.println("(c) 2015, Institute for Pervasive Computing, ETH Zurich");
    System.out.println();
    System.out.println("This machine has " + CORES + " cores");
    System.out.println("Operating system: " + OS);

    String address = null;
    int port = DEFAULT_PORT;
    int udp_sender = DEFAULT_SENDER_COUNT;
    int udp_receiver = DEFAULT_RECEIVER_COUNT;
    int protocol_threads = DEFAULT_PROTOCOL_STAGE_THREAD_COUNT;
    boolean verbose = false;
    boolean use_executor = false;

    // Parse input
    if (args.length > 0) {
      int index = 0;
      while (index < args.length) {
        String arg = args[index];
        if ("-usage".equals(arg) || "-help".equals(arg) || "-h".equals(arg) || "-?".equals(arg)) {
          printUsage();
        } else if ("-t".equals(arg)) {
          protocol_threads = Integer.parseInt(args[index + 1]);
        } else if ("-s".equals(arg)) {
          udp_sender = Integer.parseInt(args[index + 1]);
        } else if ("-r".equals(arg)) {
          udp_receiver = Integer.parseInt(args[index + 1]);
        } else if ("-p".equals(arg)) {
          port = Integer.parseInt(args[index + 1]);
        } else if ("-a".equals(arg)) {
          address = args[index + 1];
        } else if ("-v".equals(arg)) {
          verbose = true;
        } else if ("-use-executor".equals(arg)) {
          use_executor = true;
        } else {
          System.err.println("Unknwon arg " + arg);
          printUsage();
        }
        index += 2;
      }
    }

    // Parse address
    InetAddress addr = address != null ? InetAddress.getByName(address) : null;
    InetSocketAddress sockAddr = new InetSocketAddress((InetAddress) addr, port);

    setBenchmarkConfiguration(udp_sender, udp_receiver, verbose);

    // Create server
    CoapServer server = new CoapServer();

    if (use_executor) {
      System.out.println("Using a scheduled thread pool with " + protocol_threads + " workers");
      server.setExecutor(Executors.newScheduledThreadPool(protocol_threads));
    }

    System.out.println("Number of receiver/sender threads: " + udp_receiver + "/" + udp_sender);

    server.add(new AnnounceResource("announce"));

    server.addEndpoint(new CoapEndpoint(sockAddr));
    server.start();

    System.out.println("Observe benchmark announcement server listening on " + sockAddr);
  }