Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main/java/com/google/api/core/AbstractApiFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import java.util.concurrent.TimeoutException;
import javax.annotation.Nullable;

/**
* Abstract implementation of ApiFuture that mirrors {@code AbstractFuture} in Guava.
*/
/** Abstract implementation of ApiFuture that mirrors {@code AbstractFuture} in Guava. */
public abstract class AbstractApiFuture<V> implements ApiFuture<V> {
private final InternalSettableFuture impl = new InternalSettableFuture();

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/google/api/core/ApiAsyncFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@
/**
* Transforms a value, possibly asynchronously.
*
* <p>
* It is similar to Guava's {@code AsyncFunction}, redeclared so that Guava can be shaded.
* <p>It is similar to Guava's {@code AsyncFunction}, redeclared so that Guava can be shaded.
*/
public interface ApiAsyncFunction<I, O> {
/**
* Returns an output Future to use in place of the given input. The output Future need not be
* done, making AsyncFunction suitable for asynchronous derivations.
*
* <p>
* Throwing an exception from this method is equivalent to returning a failing Future.
* <p>Throwing an exception from this method is equivalent to returning a failing Future.
*/
ApiFuture<O> apply(I input) throws Exception;
}
14 changes: 5 additions & 9 deletions src/main/java/com/google/api/core/ApiClock.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@
/**
* An interface for getting the current value of a high-resolution time source, in nanoseconds.
*
* Clocks other than {@link NanoClock} are typically used only for testing.
* <p>Clocks other than {@link NanoClock} are typically used only for testing.
*
* This interface is required in addition to Java 8's Clock, because nanoTime is required to compare
* values with io.grpc.CallOptions.getDeadlineNanoTime().
* <p>This interface is required in addition to Java 8's Clock, because nanoTime is required to
* compare values with io.grpc.CallOptions.getDeadlineNanoTime().
*/
public interface ApiClock {

/**
* Returns the current value of this clock's high-resolution time source, in nanoseconds.
*/
/** Returns the current value of this clock's high-resolution time source, in nanoseconds. */
long nanoTime();

/**
* Returns the current value of this clock's high-resolution time source, in milliseconds.
*/
/** Returns the current value of this clock's high-resolution time source, in milliseconds. */
long millisTime();
}
3 changes: 1 addition & 2 deletions src/main/java/com/google/api/core/ApiFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
/**
* Legacy version of Function.
*
* <p>
* It is similar to Guava's {@code Function}, redeclared so that Guava can be shaded.
* <p>It is similar to Guava's {@code Function}, redeclared so that Guava can be shaded.
*/
public interface ApiFunction<F, T> {
T apply(F input);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/api/core/ApiFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* A Future that can have a listener added.
*
* Similar to Guava's {@code ListenableFuture}, but redeclared so that Guava could be shaded.
* <p>Similar to Guava's {@code ListenableFuture}, but redeclared so that Guava could be shaded.
*/
public interface ApiFuture<V> extends Future<V> {
void addListener(Runnable listener, Executor executor);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/google/api/core/ApiFutureCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
/**
* A callback for accepting the results of an {@link ApiFuture}.
*
* <p>
* It is similar to Guava's {@code FutureCallback}, redeclared so that Guava can be shaded.
* <p>It is similar to Guava's {@code FutureCallback}, redeclared so that Guava can be shaded.
*/
public interface ApiFutureCallback<V> {
void onFailure(Throwable t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
* INTERNAL USE ONLY. Adapter from ApiFuture to Guava ListenableFuture.
*/
/** INTERNAL USE ONLY. Adapter from ApiFuture to Guava ListenableFuture. */
@InternalApi
public class ApiFutureToListenableFuture<V> implements ListenableFuture<V> {
private final ApiFuture<V> apiFuture;
Expand Down
98 changes: 45 additions & 53 deletions src/main/java/com/google/api/core/ApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,32 @@
import java.util.concurrent.TimeoutException;

/**
* An object with an operational state, plus asynchronous {@link #startAsync()} and
* {@link #stopAsync()} lifecycle methods to transition between states. Example services include
* An object with an operational state, plus asynchronous {@link #startAsync()} and {@link
* #stopAsync()} lifecycle methods to transition between states. Example services include
* webservers, RPC servers and timers.
*
* <p>
* The normal lifecycle of a service is:
* <p>The normal lifecycle of a service is:
*
* <ul>
* <li>{@linkplain State#NEW NEW} -&gt;
* <li>{@linkplain State#STARTING STARTING} -&gt;
* <li>{@linkplain State#RUNNING RUNNING} -&gt;
* <li>{@linkplain State#STOPPING STOPPING} -&gt;
* <li>{@linkplain State#TERMINATED TERMINATED}
* <li>{@linkplain State#NEW NEW} -&gt;
* <li>{@linkplain State#STARTING STARTING} -&gt;
* <li>{@linkplain State#RUNNING RUNNING} -&gt;
* <li>{@linkplain State#STOPPING STOPPING} -&gt;
* <li>{@linkplain State#TERMINATED TERMINATED}
* </ul>
*
* <p>
* There are deviations from this if there are failures or if {@link ApiService#stopAsync} is called
* before the {@link ApiService} reaches the {@linkplain State#RUNNING RUNNING} state. The set of
* legal transitions form a <a href="http://en.wikipedia.org/wiki/Directed_acyclic_graph">DAG</a>,
* therefore every method of the listener will be called at most once. N.B. The {@link State#FAILED}
* and {@link State#TERMINATED} states are terminal states, once a service enters either of these
* states it cannot ever leave them.
* <p>There are deviations from this if there are failures or if {@link ApiService#stopAsync} is
* called before the {@link ApiService} reaches the {@linkplain State#RUNNING RUNNING} state. The
* set of legal transitions form a <a
* href="http://en.wikipedia.org/wiki/Directed_acyclic_graph">DAG</a>, therefore every method of the
* listener will be called at most once. N.B. The {@link State#FAILED} and {@link State#TERMINATED}
* states are terminal states, once a service enters either of these states it cannot ever leave
* them.
*
* <p>
* Implementors of this interface are strongly encouraged to extend {@link AbstractApiService} which
* implement this interface and make the threading and state management easier.
* <p>Implementors of this interface are strongly encouraged to extend {@link AbstractApiService}
* which implement this interface and make the threading and state management easier.
*
* <p>
* Similar to Guava's {@code Service}, but redeclared so that Guava could be shaded.
* <p>Similar to Guava's {@code Service}, but redeclared so that Guava could be shaded.
*/
public interface ApiService {
/**
Expand All @@ -71,17 +68,15 @@ public interface ApiService {
* service changes state. The listener will not have previous state changes replayed, so it is
* suggested that listeners are added before the service starts.
*
* <p>
* {@code addListener} guarantees execution ordering across calls to a given listener but not
* <p>{@code addListener} guarantees execution ordering across calls to a given listener but not
* across calls to multiple listeners. Specifically, a given listener will have its callbacks
* invoked in the same order as the underlying service enters those states. Additionally, at most
* one of the listener's callbacks will execute at once. However, multiple listeners' callbacks
* may execute concurrently, and listeners may execute in an order different from the one in which
* they were registered.
*
* <p>
* RuntimeExceptions thrown by a listener will be caught and logged. Any exception thrown during
* {@code Executor.execute} (e.g., a {@code RejectedExecutionException}) will be caught and
* <p>RuntimeExceptions thrown by a listener will be caught and logged. Any exception thrown
* during {@code Executor.execute} (e.g., a {@code RejectedExecutionException}) will be caught and
* logged.
*
* @param listener the listener to run when the service changes state is complete
Expand All @@ -93,8 +88,8 @@ public interface ApiService {
* Waits for the {@link ApiService} to reach the {@linkplain State#RUNNING running state}.
*
* @throws IllegalStateException if the service reaches a state from which it is not possible to
* enter the {@link State#RUNNING} state. e.g. if the {@code state} is {@code State#TERMINATED}
* when this method is called then this will throw an IllegalStateException.
* enter the {@link State#RUNNING} state. e.g. if the {@code state} is {@code
* State#TERMINATED} when this method is called then this will throw an IllegalStateException.
*/
void awaitRunning();

Expand All @@ -106,9 +101,8 @@ public interface ApiService {
* @param unit the time unit of the timeout argument
* @throws TimeoutException if the service has not reached the given state within the deadline
* @throws IllegalStateException if the service reaches a state from which it is not possible to
* enter the {@link State#RUNNING RUNNING} state. e.g. if the {@code state} is
* {@code State#TERMINATED} when this method is called then this will throw an
* IllegalStateException.
* enter the {@link State#RUNNING RUNNING} state. e.g. if the {@code state} is {@code
* State#TERMINATED} when this method is called then this will throw an IllegalStateException.
*/
void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException;

Expand Down Expand Up @@ -154,10 +148,10 @@ public interface ApiService {

/**
* If the service is {@linkplain State#STARTING starting} or {@linkplain State#RUNNING running},
* this initiates service shutdown and returns immediately. If the service is
* {@linkplain State#NEW new}, it is {@linkplain State#TERMINATED terminated} without having been
* started nor stopped. If the service has already been stopped, this method returns immediately
* without taking action.
* this initiates service shutdown and returns immediately. If the service is {@linkplain
* State#NEW new}, it is {@linkplain State#TERMINATED terminated} without having been started nor
* stopped. If the service has already been stopped, this method returns immediately without
* taking action.
*
* @return this
*/
Expand All @@ -166,9 +160,8 @@ public interface ApiService {
/**
* The lifecycle states of a service.
*
* <p>
* The ordering of the {@link State} enum is defined such that if there is a state transition from
* {@code A -> B} then {@code A.compareTo(B) < 0}. N.B. The converse is not true, i.e. if
* <p>The ordering of the {@link State} enum is defined such that if there is a state transition
* from {@code A -> B} then {@code A.compareTo(B) < 0}. N.B. The converse is not true, i.e. if
* {@code A.compareTo(B) < 0} then there is <b>not</b> guaranteed to be a valid state transition
* {@code A -> B}.
*/
Expand Down Expand Up @@ -203,8 +196,7 @@ enum State {
* A listener for the various state changes that a {@link ApiService} goes through in its
* lifecycle.
*
* <p>
* All methods are no-ops by default, implementors should override the ones they care about.
* <p>All methods are no-ops by default, implementors should override the ones they care about.
*/
@BetaApi
abstract class Listener {
Expand All @@ -214,29 +206,29 @@ abstract class Listener {
* Therefore, if this method is called, no other methods will be called on the {@link Listener}.
*
* @param from The previous state that is being transitioned from. Failure can occur in any
* state with the exception of {@linkplain State#NEW NEW} or {@linkplain State#TERMINATED
* TERMINATED}.
* state with the exception of {@linkplain State#NEW NEW} or {@linkplain State#TERMINATED
* TERMINATED}.
* @param failure The exception that caused the failure.
*/
public void failed(State from, Throwable failure) {}

/**
* Called when the service transitions from {@linkplain State#STARTING STARTING} to
* {@linkplain State#RUNNING RUNNING}. This occurs when a service has successfully started.
* Called when the service transitions from {@linkplain State#STARTING STARTING} to {@linkplain
* State#RUNNING RUNNING}. This occurs when a service has successfully started.
*/
public void running() {}

/**
* Called when the service transitions from {@linkplain State#NEW NEW} to
* {@linkplain State#STARTING STARTING}. This occurs when {@link ApiService#startAsync} is
* called the first time.
* Called when the service transitions from {@linkplain State#NEW NEW} to {@linkplain
* State#STARTING STARTING}. This occurs when {@link ApiService#startAsync} is called the first
* time.
*/
public void starting() {}

/**
* Called when the service transitions to the {@linkplain State#STOPPING STOPPING} state. The
* only valid values for {@code from} are {@linkplain State#STARTING STARTING} or
* {@linkplain State#RUNNING RUNNING}. This occurs when {@link ApiService#stopAsync} is called.
* only valid values for {@code from} are {@linkplain State#STARTING STARTING} or {@linkplain
* State#RUNNING RUNNING}. This occurs when {@link ApiService#stopAsync} is called.
*
* @param from The previous state that is being transitioned from.
*/
Expand All @@ -245,12 +237,12 @@ public void stopping(State from) {}
/**
* Called when the service transitions to the {@linkplain State#TERMINATED TERMINATED} state.
* The {@linkplain State#TERMINATED TERMINATED} state is a terminal state in the transition
* diagram. Therefore, if this method is called, no other methods will be called on the
* {@link Listener}.
* diagram. Therefore, if this method is called, no other methods will be called on the {@link
* Listener}.
*
* @param from The previous state that is being transitioned from. The only valid values for
* this are {@linkplain State#NEW NEW}, {@linkplain State#RUNNING RUNNING} or
* {@linkplain State#STOPPING STOPPING}.
* this are {@linkplain State#NEW NEW}, {@linkplain State#RUNNING RUNNING} or {@linkplain
* State#STOPPING STOPPING}.
*/
public void terminated(State from) {}
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/google/api/core/BetaApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
* Indicates a public API that can change at any time, and has no guarantee of API stability and
* backward-compatibility.
*
* <p>
* Usage guidelines:
* <p>Usage guidelines:
*
* <ol>
* <li>This annotation is used only on APIs with public visibility. Internal interfaces should not
* use it.</li>
* <li>This annotation should only be added to new APIs. Adding it to an existing API is considered
* API-breaking.</li>
* <li>Removing this annotation from an API gives it stable status, assuming the API doesn't have
* other annotations denoting instability (such as {@link InternalApi} or
* {@link InternalExtensionOnly}).</li>
* <li>This annotation is used only on APIs with public visibility. Internal interfaces should not
* use it.
* <li>This annotation should only be added to new APIs. Adding it to an existing API is
* considered API-breaking.
* <li>Removing this annotation from an API gives it stable status, assuming the API doesn't have
* other annotations denoting instability (such as {@link InternalApi} or {@link
* InternalExtensionOnly}).
* </ol>
*/
@BetaApi
Expand All @@ -63,8 +63,6 @@
})
@Documented
public @interface BetaApi {
/**
* Context information such as links to a discussion thread, tracking issue, etc.
*/
/** Context information such as links to a discussion thread, tracking issue, etc. */
String value() default "";
}
12 changes: 4 additions & 8 deletions src/main/java/com/google/api/core/InternalApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@
* Annotates a program element (class, method, package etc) which is internal to its containing
* library, not part of the public API, and should not be used by users of the library.
*
* <p>
* This annotation only makes sense on APIs that are not private. Its existence is necessary because
* Java does not have a visibility level for code within a compilation unit.
* <p>This annotation only makes sense on APIs that are not private. Its existence is necessary
* because Java does not have a visibility level for code within a compilation unit.
*
* <p>
* Adding this annotation to an API is considered API-breaking.
* <p>Adding this annotation to an API is considered API-breaking.
*/
@BetaApi
@Retention(RetentionPolicy.RUNTIME)
Expand All @@ -58,8 +56,6 @@
})
@Documented
public @interface InternalApi {
/**
* Context information such as "internal to library", "for testing", etc.
*/
/** Context information such as "internal to library", "for testing", etc. */
String value() default "";
}
22 changes: 9 additions & 13 deletions src/main/java/com/google/api/core/InternalExtensionOnly.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@
* Indicates a public API that is stable for callers to use, but has no guarantee of stability for
* extension. Consequently, the API should only be extended within the package containing the API.
*
* <p>
* For example:
* <p>For example:
*
* <ul>
* <li>An interface marked with this annotation can have new methods added to it.</li>
* <li>A non-final class with this annotation can be marked final.</li>
* <li>A class with this annotation can have new abstract methods added.</li>
* <li>a non-final method with this annotation can be marked final.</li>
* <li>An interface marked with this annotation can have new methods added to it.
* <li>A non-final class with this annotation can be marked final.
* <li>A class with this annotation can have new abstract methods added.
* <li>a non-final method with this annotation can be marked final.
* </ul>
*
* <p>
* The list above is just for illustration purposes and is not exhaustive.
* <p>The list above is just for illustration purposes and is not exhaustive.
*
* <p>
* Adding this annotation to an API is considered API-breaking.
* <p>Adding this annotation to an API is considered API-breaking.
*/
@BetaApi
@Retention(RetentionPolicy.RUNTIME)
Expand All @@ -66,8 +64,6 @@
})
@Documented
public @interface InternalExtensionOnly {
/**
* Context information on why the interface/class is annotated with InternalExtensionOnly.
*/
/** Context information on why the interface/class is annotated with InternalExtensionOnly. */
String value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture;
import com.google.common.util.concurrent.ListenableFuture;

/**
* INTERNAL USE ONLY. Adapter from Guava ListenableFuture to ApiFuture.
*/
/** INTERNAL USE ONLY. Adapter from Guava ListenableFuture to ApiFuture. */
@InternalApi
public class ListenableFutureToApiFuture<V> extends SimpleForwardingListenableFuture<V>
implements ApiFuture<V> {
Expand Down
Loading