Esempio n. 1
1
  public String getHardwareAddress() {
    TransportAddress transportAddress = httpServerTransport.boundAddress().publishAddress();
    if (!(transportAddress instanceof InetSocketTransportAddress)) {
      return null;
    }

    String hardwareAddress = null;
    InetAddress inetAddress =
        ((InetSocketTransportAddress) transportAddress).address().getAddress();
    try {
      NetworkInterface networkInterface = NetworkInterface.getByInetAddress(inetAddress);
      if (networkInterface != null) {
        if (networkInterface.getName().equals("lo")) {
          hardwareAddress = "loopback device";
        } else {
          byte[] hardwareAddressBytes = networkInterface.getHardwareAddress();
          StringBuilder sb = new StringBuilder(18);
          for (byte b : hardwareAddressBytes) {
            if (sb.length() > 0) sb.append(':');
            sb.append(String.format("%02x", b));
          }
          hardwareAddress = sb.toString();
        }
      }

    } catch (SocketException e) {
      if (logger.isTraceEnabled()) {
        logger.trace("Error getting network interface", e);
      }
    }
    return hardwareAddress;
  }
  public void testThatNettyHttpServerSupportsPipelining() throws Exception {
    List<String> requests = Arrays.asList("/", "/_nodes/stats", "/", "/_cluster/state", "/");

    HttpServerTransport httpServerTransport =
        internalCluster().getInstance(HttpServerTransport.class);
    InetSocketTransportAddress inetSocketTransportAddress =
        (InetSocketTransportAddress)
            randomFrom(httpServerTransport.boundAddress().boundAddresses());

    try (NettyHttpClient nettyHttpClient = new NettyHttpClient()) {
      Collection<HttpResponse> responses =
          nettyHttpClient.sendRequests(
              inetSocketTransportAddress.address(), requests.toArray(new String[] {}));
      assertThat(responses, hasSize(5));

      Collection<String> opaqueIds = returnOpaqueIds(responses);
      assertOpaqueIdsInOrder(opaqueIds);
    }
  }