@Override public void handleTimeout(InetAddress address, EchoPacket request) { PingResponseDTO responseDTO = new PingResponseDTO(); responseDTO.setRtt(Double.POSITIVE_INFINITY); if (!isDone()) { complete(responseDTO); } }
@Override public PingSweepRequestBuilder sweep() { return new PingSweepRequestBuilderImpl(pingSweepDelegate); } }
@Override public PingResponseDTO createResponseWithException(Throwable ex) { return new PingResponseDTO(ex); } }
public static String renderSummary(PingSummary summary) { final StringBuilder builder = new StringBuilder(); PingSummaryCalculator calculator = new PingSummaryCalculator(summary.getSequences()); builder.append("\n"); builder.append(String.format("--- %s ping statistics ---", summary.getRequest().getInetAddress())); builder.append("\n"); builder.append(String.format("%d packets transmitted, %d packets received, %.2f%% packet loss", calculator.getPacketsTransmitted(), calculator.getPacketsReceived(), calculator.getPacketLoss())); builder.append("\n"); builder.append(String.format("round-trip min/avg/max/stddev = %.2f/%.2f/%.2f/%.2f ms", (double) calculator.getMin(), calculator.getAvg(), (double) calculator.getMax(), calculator.getStdDev())); builder.append("\n"); return builder.toString(); } }
@Override public CompletableFuture<PingSummary> execute(PingRequestDTO requestDTO) { return client.execute(requestDTO).thenApply(responseDTO -> { final PingResponse pingResponse = new PingResponse(); pingResponse.setRtt(responseDTO.getRtt()); PingSummary summary = new PingSummary(requestDTO.toPingRequest(), 1 /* we always only have 1 */); summary.addSequence(1, pingResponse); return summary; }); } }
public PingRequest toPingRequest() { final PingRequest pingRequest = new PingRequest(); pingRequest.setInetAddress(inetAddress); pingRequest.setTimeout(timeout); pingRequest.setRetries(retries); pingRequest.setPacketSize(packetSize); return pingRequest; }
@Override public void handleResponse(InetAddress address, EchoPacket response) { if (response != null) { PingSweepResultDTO sweepResult = new PingSweepResultDTO(); sweepResult.setAddress(address); sweepResult.setRtt(response.elapsedTime(TimeUnit.MILLISECONDS)); responseDTO.addPingSweepResult(sweepResult); } afterHandled(address); }
public static String renderHeader(PingSummary summary) { return String.format("PING %s: %d data bytes", summary.getRequest().getInetAddress(), summary.getRequest().getPacketSize()-8); }
@Override public void handleResponse(InetAddress address, EchoPacket response) { PingResponseDTO responseDTO = new PingResponseDTO(); responseDTO.setRtt(response.elapsedTime(TimeUnit.MILLISECONDS)); complete(responseDTO); }
@Override public void handleError(InetAddress address, EchoPacket request, Throwable t) { if (!isDone()) { completeExceptionally(t); } } }
@Override public PingRequestBuilder ping(InetAddress inetAddress) { return new PingRequestBuilderImpl(pingProxyDelegate).withInetAddress(inetAddress); }
double getPacketLoss() { return 1.0 - (double) getPacketsReceived() / (double) getPacketsTransmitted(); }
@Override public void handleError(InetAddress address, EchoPacket request, Throwable t) { afterHandled(address); }
private void reportProgress(PingSequence newSequence, PingSummary summary) { if (callback != null) { callback.onUpdate(newSequence, summary); } } }
@Override public PingSweepRequestBuilder withRange(InetAddress begin, InetAddress end) { return withRange(begin, end, PingConstants.DEFAULT_RETRIES, PingConstants.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); }
public void complete() { complete(responseDTO); }
@Override public PingSweepResponseDTO createResponseWithException(Throwable ex) { return new PingSweepResponseDTO(ex); }
@Override public void handleTimeout(InetAddress address, EchoPacket request) { afterHandled(address); }