Search in sources :

Example 1 with ObservableReactiveUtil

use of com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil in project cloud-spanner-r2dbc by GoogleCloudPlatform.

the class SessionCleanupUtils method getSessionNames.

private static List<String> getSessionNames() throws Exception {
    String databaseName = DatabaseName.format(ServiceOptions.getDefaultProjectId(), DatabaseProperties.INSTANCE, DatabaseProperties.DATABASE);
    String nextPageToken = null;
    List<String> sessionNames = new ArrayList<>();
    do {
        ListSessionsRequest.Builder requestBuilder = ListSessionsRequest.newBuilder().setDatabase(databaseName);
        if (nextPageToken != null) {
            requestBuilder.setPageToken(nextPageToken);
        }
        ListSessionsResponse listSessionsResponse = ObservableReactiveUtil.<ListSessionsResponse>unaryCall(obs -> spannerStub.listSessions(requestBuilder.build(), obs)).block();
        nextPageToken = listSessionsResponse.getNextPageToken();
        sessionNames.addAll(listSessionsResponse.getSessionsList().stream().map(Session::getName).collect(Collectors.toList()));
    } while (nextPageToken != null && !"".equals(nextPageToken));
    return sessionNames;
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) Session(com.google.spanner.v1.Session) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) ManagedChannel(io.grpc.ManagedChannel) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ObservableReactiveUtil(com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil) Empty(com.google.protobuf.Empty) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) List(java.util.List) StreamObserver(io.grpc.stub.StreamObserver) ServiceOptions(com.google.cloud.ServiceOptions) DatabaseName(com.google.spanner.v1.DatabaseName) SpannerGrpc(com.google.spanner.v1.SpannerGrpc) ArrayList(java.util.ArrayList) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) Session(com.google.spanner.v1.Session)

Aggregations

GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 ServiceOptions (com.google.cloud.ServiceOptions)1 ObservableReactiveUtil (com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil)1 Empty (com.google.protobuf.Empty)1 DatabaseName (com.google.spanner.v1.DatabaseName)1 DeleteSessionRequest (com.google.spanner.v1.DeleteSessionRequest)1 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)1 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)1 Session (com.google.spanner.v1.Session)1 SpannerGrpc (com.google.spanner.v1.SpannerGrpc)1 SpannerStub (com.google.spanner.v1.SpannerGrpc.SpannerStub)1 ManagedChannel (io.grpc.ManagedChannel)1 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)1 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)1 StreamObserver (io.grpc.stub.StreamObserver)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1