use of com.google.api.gax.rpc.StreamController in project java-bigquerystorage by googleapis.
the class ReadRowsAttemptCallable method call.
/**
* Sends the actual RPC. The request being sent will first be transformed by the {@link
* StreamResumptionStrategy}.
*
* <p>This method expects to be called by one thread at a time. Furthermore, it expects that the
* current RPC finished before the next time it's called.
*/
@Override
public Void call() {
Preconditions.checkState(isStarted, "Must be started first");
ReadRowsRequest request = (++numAttempts == 1) ? initialRequest : resumptionStrategy.getResumeRequest(initialRequest);
// Should never happen. onAttemptError will check if ResumptionStrategy can create a resume
// request,
// which the RetryingFuture/StreamResumptionStrategy should respect.
Preconditions.checkState(request != null, "ResumptionStrategy returned a null request.");
innerAttemptFuture = SettableApiFuture.create();
seenSuccessSinceLastError = false;
ApiCallContext attemptContext = context;
if (!outerRetryingFuture.getAttemptSettings().getRpcTimeout().isZero()) {
attemptContext = attemptContext.withStreamWaitTimeout(outerRetryingFuture.getAttemptSettings().getRpcTimeout());
}
attemptContext.getTracer().attemptStarted(outerRetryingFuture.getAttemptSettings().getOverallAttemptCount());
innerCallable.call(request, new StateCheckingResponseObserver<ReadRowsResponse>() {
@Override
public void onStartImpl(StreamController controller) {
onAttemptStart(controller);
}
@Override
public void onResponseImpl(ReadRowsResponse response) {
onAttemptResponse(response);
}
@Override
public void onErrorImpl(Throwable t) {
onAttemptError(t);
}
@Override
public void onCompleteImpl() {
onAttemptComplete();
}
}, attemptContext);
outerRetryingFuture.setAttemptFuture(innerAttemptFuture);
return null;
}
use of com.google.api.gax.rpc.StreamController in project java-bigquerystorage by googleapis.
the class ReadRowsAttemptCallable method onRequest.
/**
* Called when the outer {@link ResponseObserver} is ready for more data.
*
* @see StreamController#request(int)
*/
private void onRequest(int count) {
Preconditions.checkState(!autoFlowControl, "Automatic flow control is enabled");
Preconditions.checkArgument(count > 0, "Count must be > 0");
final StreamController localInnerController;
synchronized (lock) {
int maxInc = Integer.MAX_VALUE - pendingRequests;
count = Math.min(maxInc, count);
pendingRequests += count;
localInnerController = this.innerController;
}
// ignore it and the current controller will pick it up onStart.
if (localInnerController != null) {
localInnerController.request(count);
}
}
use of com.google.api.gax.rpc.StreamController in project java-bigquerystorage by googleapis.
the class ReadRowsAttemptCallable method start.
/**
* Starts the initial call. The call is attempted on the caller's thread. Further call attempts
* will be scheduled by the {@link RetryingFuture}.
*/
public void start() {
Preconditions.checkState(!isStarted, "Already started");
// Initialize the outer observer
outerObserver.onStart(new StreamController() {
@Override
public void disableAutoInboundFlowControl() {
Preconditions.checkState(!isStarted, "Can't disable auto flow control once the stream is started");
autoFlowControl = false;
}
@Override
public void request(int count) {
onRequest(count);
}
@Override
public void cancel() {
onCancel();
}
});
if (autoFlowControl) {
synchronized (lock) {
pendingRequests = Integer.MAX_VALUE;
}
}
isStarted = true;
// Propagate the totalTimeout as the overall stream deadline.
Duration totalTimeout = outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeout();
if (totalTimeout != null && context != null) {
context = context.withTimeout(totalTimeout);
}
// Call the inner callable
call();
}
use of com.google.api.gax.rpc.StreamController in project java-bigquerystorage by googleapis.
the class ReadRowsAttemptCallable method onCancel.
/**
* Called when the outer {@link ResponseObserver} wants to prematurely cancel the stream.
*
* @see StreamController#cancel()
*/
private void onCancel() {
StreamController localInnerController;
synchronized (lock) {
if (cancellationCause != null) {
return;
}
// NOTE: BasicRetryingFuture will replace j.u.c.CancellationExceptions with it's own,
// which will not have the current stacktrace, so a special wrapper has be used here.
cancellationCause = new ServerStreamingAttemptException(new CancellationException("User cancelled stream"), resumptionStrategy.canResume(), seenSuccessSinceLastError);
localInnerController = innerController;
}
if (localInnerController != null) {
localInnerController.cancel();
}
}
use of com.google.api.gax.rpc.StreamController in project java-bigquerystorage by googleapis.
the class ReadRowsAttemptCallable method start.
/**
* Starts the initial call. The call is attempted on the caller's thread. Further call attempts
* will be scheduled by the {@link RetryingFuture}.
*/
public void start() {
Preconditions.checkState(!isStarted, "Already started");
// Initialize the outer observer
outerObserver.onStart(new StreamController() {
@Override
public void disableAutoInboundFlowControl() {
Preconditions.checkState(!isStarted, "Can't disable auto flow control once the stream is started");
autoFlowControl = false;
}
@Override
public void request(int count) {
onRequest(count);
}
@Override
public void cancel() {
onCancel();
}
});
if (autoFlowControl) {
synchronized (lock) {
pendingRequests = Integer.MAX_VALUE;
}
}
isStarted = true;
// Propagate the totalTimeout as the overall stream deadline.
Duration totalTimeout = outerRetryingFuture.getAttemptSettings().getGlobalSettings().getTotalTimeout();
if (totalTimeout != null && context != null) {
context = context.withTimeout(totalTimeout);
}
// Call the inner callable
call();
}
Aggregations