Search in sources :

Example 1 with SubscriberFutureStub

use of com.google.pubsub.v1.SubscriberGrpc.SubscriberFutureStub in project google-cloud-java by GoogleCloudPlatform.

the class Subscriber method startPollingConnections.

private void startPollingConnections() throws IOException {
    synchronized (pollingSubscriberConnections) {
        Credentials credentials = credentialsProvider.getCredentials();
        CallCredentials callCredentials = credentials == null ? null : MoreCallCredentials.from(credentials);
        for (int i = 0; i < numChannels; i++) {
            SubscriberFutureStub stub = SubscriberGrpc.newFutureStub(channels.get(i));
            if (callCredentials != null) {
                stub = stub.withCallCredentials(callCredentials);
            }
            pollingSubscriberConnections.add(new PollingSubscriberConnection(cachedSubscriptionNameString, receiver, ackExpirationPadding, maxAckExtensionPeriod, ackLatencyDistribution, stub, flowController, flowControlSettings.getMaxOutstandingElementCount(), executor, alarmsExecutor, clock));
        }
        startConnections(pollingSubscriberConnections, new Listener() {

            @Override
            public void failed(State from, Throwable failure) {
                // If a connection failed is because of a fatal error, we should fail the
                // whole subscriber.
                stopAllPollingConnections();
                try {
                    notifyFailed(failure);
                } catch (IllegalStateException e) {
                    if (isRunning()) {
                        throw e;
                    }
                // It could happen that we are shutting down while some channels fail.
                }
            }
        });
    }
}
Also used : CallCredentials(io.grpc.CallCredentials) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Credentials(com.google.auth.Credentials) CallCredentials(io.grpc.CallCredentials) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) SubscriberFutureStub(com.google.pubsub.v1.SubscriberGrpc.SubscriberFutureStub)

Aggregations

Credentials (com.google.auth.Credentials)1 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 SubscriberFutureStub (com.google.pubsub.v1.SubscriberGrpc.SubscriberFutureStub)1 CallCredentials (io.grpc.CallCredentials)1 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)1