Interface Pings
- All Superinterfaces:
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.
Access control
There are no permissions requirements associated with this feature.
Accessing the feature
This feature may be obtained from asession
, 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));
- Since:
- 5.0
- Author:
- DiffusionData Limited
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Server response to a ping. -
Method Summary
Modifier and TypeMethodDescriptionSend a ping request to the server.Methods inherited from interface com.pushtechnology.diffusion.client.session.Feature
getSession
-
Method Details
-
pingServer
CompletableFuture<Pings.PingDetails> pingServer()Send a ping request to the server.- Returns:
- a CompletableFuture that completes when a response is received
from the server
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 thecause
, include:SessionClosedException
– if the session is closed.
- Since:
- 6.0
-