public interface Pings extends Feature
The main purpose of a ping is to test, at a very basic level, the current network conditions that exist between the client session and the server it is connected to. The ping response includes the time taken to make a round-trip call to the server.
There are no permissions requirements associated with this feature.
session
, and used as follows:
Pings pings = session.feature(Pings.class); CompletableFuture<PingDetails> response = pings.pingServer(); PingDetails result = response.get(); // Block for response System.out.printf("Round-trip call to server took %d milliseconds%n", result.getRoundTripTime());
Alternatively, the CompletableFuture API can be used to process the result using the Diffusion input thread, without blocking the calling thread:
Pings pings = session.feature(Pings.class); pings.pingServer() .thenApply(PingDetails::getRoundTripTime) .thenAccept(t -> System.out.printf("Round-trip call to server took %d milliseconds%n", t));
Modifier and Type | Interface and Description |
---|---|
static interface |
Pings.PingCallback
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
static interface |
Pings.PingContextCallback<C>
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
static interface |
Pings.PingDetails
Server response to a ping.
|
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Pings.PingDetails> |
pingServer()
Send a ping request to the server.
|
<C> void |
pingServer(C context,
Pings.PingContextCallback<C> callback)
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
void |
pingServer(Pings.PingCallback callback)
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
getSession
CompletableFuture<Pings.PingDetails> pingServer()
If the ping was successful, the CompletableFuture will complete
successfully. The result is a Pings.PingDetails
containing
timing information.
Otherwise, the CompletableFuture will complete exceptionally with
a CompletionException
. Common reasons for failure, listed
by the exception reported as the
cause
, include:
SessionClosedException
– if the session is
closed.
@Deprecated void pingServer(Pings.PingCallback callback)
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead.
The callback
's onPingResponse
method will be called with the response.
callback
- the callback for the response to this ping operation@Deprecated <C> void pingServer(C context, Pings.PingContextCallback<C> callback)
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead.
The callback
's
onPingResponse
method will be called with the response.
C
- context object typecontext
- the context object that will be passed to the callbackcallback
- the callback for the response to this ping operationCopyright © 2024 DiffusionData Ltd. All Rights Reserved.