com.undefinedlabs.scope.deps.okhttp3.internal.http2.Ping Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scope-deps Show documentation
Show all versions of scope-deps Show documentation
Scope is a APM for tests to give engineering teams unprecedented visibility into their CI process to quickly
identify, troubleshoot and fix failed builds.
This artifact contains dependencies for Scope.
package com.undefinedlabs.scope.deps.okhttp3.internal.http2;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
final class Ping {
private final CountDownLatch latch = new CountDownLatch(1);
private long sent = -1;
private long received = -1;
Ping() {
}
void send() {
if (sent != -1) throw new IllegalStateException();
sent = System.nanoTime();
}
void receive() {
if (received != -1 || sent == -1) throw new IllegalStateException();
received = System.nanoTime();
latch.countDown();
}
void cancel() {
if (received != -1 || sent == -1) throw new IllegalStateException();
received = sent - 1;
latch.countDown();
}
/**
* Returns the round trip time for this ping in nanoseconds, waiting for the response to arrive if
* necessary. Returns -1 if the response was canceled.
*/
public long roundTripTime() throws InterruptedException {
latch.await();
return received - sent;
}
/**
* Returns the round trip time for this ping in nanoseconds, or -1 if the response was canceled,
* or -2 if the timeout elapsed before the round trip completed.
*/
public long roundTripTime(long timeout, TimeUnit unit) throws InterruptedException {
if (latch.await(timeout, unit)) {
return received - sent;
} else {
return -2;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy