🚨 This is an important announcement! 🚨
This documentation site is no longer actively maintained.
For up-to-date documentation, see the new site at the EWB JVM SDK page.
Skip to main content
Version: 0.24.1

Query Network State Client

The QueryNetworkStateClient will allow you to interact with a server running the QueryNetworkStateService. It provides an object-oriented wrapper for the gRPC library, with the ability to retrieve information about the state of the network. This is done with the following 3 steps:

  1. Create a gRPC connection to the server.
  2. Create an instance of the QueryNetworkStateClient using your gRPC connection.
  3. Use your QueryNetworkStateClient to retrieve the state of the network.

Creating a gRPC channel​

The channel gRPC channel can be directly from the gPRC libray, or the channel wrapped in our GrpcChannel helper, which implements the AutoClosable interface and performs shutdown operations for you. At its most basic, this can be achieved with:

import com.zepben.evolve.streaming.grpc.GrpcChannel;
import io.grpc.ManagedChannelBuilder;

var channel = new GrpcChannel(ManagedChannelBuilder.forAddress(host, port).usePlaintext().build());

For more in depth options for using a gRPC channel, see the gRPC documentation, or look up a tutorial.

Using a gRPC channel with your client​

Using your gRPC channel with the QueryNetworkStateClient is as simple as passing it to the constructor.

import com.zepben.evolve.streaming.get.QueryNetworkStateClient;

var client = new QueryNetworkStateClient(channel);

Using your client to query the network state​

Now that you have a client, you can use it to query the state of the network on the connected server.

Querying current network state​

The current state of the network between two date/times can be retrieved using the getCurrentStates or the getCurrentStatesStream function on the QueryNetworkStateClient.

note

For Java interoperability, prefer using the getCurrentStatesStream function, as it returns a Stream compatible with Java's standard library.

import com.zepben.evolve.streaming.data.CurrentStateEvent;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Stream;

Stream<List<CurrentStateEvent>> response = client.getCurrentStatesStream(1, LocalDateTime.now().plusDays(-1), LocalDateTime.now());

response.forEach(events -> {
// process the list of events here.
});