-
Notifications
You must be signed in to change notification settings - Fork 104
Add RetryingContext #590
Add RetryingContext #590
Changes from 4 commits
c17c139
5fdd7af
209a841
7ae5903
f354b17
0fea88e
de45791
89b090f
75dc914
064e2f7
f980242
58a6d1b
96638dc
09c69b8
af756a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2018 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package com.google.api.gax.retrying; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.api.core.InternalExtensionOnly; | ||
| import com.google.api.gax.rpc.ApiCallContext; | ||
| import com.google.auto.value.AutoValue; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Context for a retryable operation. | ||
| * | ||
| * <p>It provides state to individual {@link RetryingFuture}s via the {@link RetryingExecutor}. | ||
| */ | ||
| @BetaApi | ||
| @InternalExtensionOnly | ||
|
||
| @AutoValue | ||
| public abstract class RetryingContext { | ||
|
||
| public static Builder newBuilder() { | ||
| return new AutoValue_RetryingContext.Builder(); | ||
| } | ||
|
|
||
| public static RetryingContext createDefault() { | ||
| return newBuilder().build(); | ||
| } | ||
|
|
||
| public static RetryingContext fromCallContext(@Nullable ApiCallContext callContext) { | ||
|
||
| Builder builder = newBuilder(); | ||
|
|
||
| if (callContext != null) { | ||
| // TODO: transfer relevant state from the ApiCallContext | ||
| } | ||
| return builder.build(); | ||
| } | ||
|
|
||
| @BetaApi | ||
| @InternalExtensionOnly | ||
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| public abstract RetryingContext build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright 2018 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package com.google.api.gax.retrying; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.api.core.InternalExtensionOnly; | ||
| import java.util.concurrent.Callable; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * A {@link RetryingExecutor} that accepts a per-operation context. | ||
| * | ||
| * @see RetryingExecutor | ||
| */ | ||
| // TODO(igorbernstein2): Consider replacing this with a default implementation in RetryingExecutor | ||
| // once support for java 7 is dropped | ||
| @BetaApi("The surface for per invocation state is unstable and will probably change in the future") | ||
| @InternalExtensionOnly | ||
| public interface RetryingExecutorWithContext<ResponseT> extends RetryingExecutor<ResponseT> { | ||
| RetryingFuture<ResponseT> createFuture( | ||
| @Nonnull Callable<ResponseT> callable, @Nonnull RetryingContext retryingContext); | ||
| } |
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.