Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate BatchRequest constructor #1333

Merged
merged 6 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* An instance of this class represents a single batch of requests.
Expand All @@ -41,7 +43,8 @@
* </p>
*
* <pre>
BatchRequest batch = new BatchRequest(transport, httpRequestInitializer);
// client is a AbstractGoogleClient (e.g. com.google.api.services.books.Books)
BatchRequest batch = client.batch(httpRequestInitializer);
batch.queue(volumesList, Volumes.class, GoogleJsonErrorContainer.class,
new BatchCallback&lt;Volumes, GoogleJsonErrorContainer&gt;() {

Expand Down Expand Up @@ -94,8 +97,19 @@ public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {
*/
public final class BatchRequest {

/**
* The deprecated global batch endpoint. Users should actually use the per-service batch endpoint
* declared by the service configuration.
*/
private static final String GLOBAL_BATCH_ENDPOINT = "https://www.googleapis.com/batch";
private static final String GLOBAL_BATCH_ENDPOINT_WARNING = "You are using the global batch "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can also link to javadoc or a more verbose example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would like to migrate the docs off of developers.google.com for these clients, so I migrated the batching and media upload/download docs to the main README in #1334. That will give us a place to target with this message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a link to the new docs section in the warning message.

+ "endpoint which will soon be shut down. Please instantiate your BatchRequest via your "
+ "service client's `batch(HttpRequestInitializer)` method.";

private static final Logger LOGGER = Logger.getLogger(BatchRequest.class.getName());

/** The URL where batch requests are sent. */
private GenericUrl batchUrl = new GenericUrl("https://www.googleapis.com/batch");
private GenericUrl batchUrl = new GenericUrl(GLOBAL_BATCH_ENDPOINT);

/** The request factory for connections to the server. */
private final HttpRequestFactory requestFactory;
Expand Down Expand Up @@ -128,7 +142,10 @@ static class RequestInfo<T, E> {
* @param transport The transport to use for requests
* @param httpRequestInitializer The initializer to use when creating an {@link HttpRequest} or
* {@code null} for none
* @deprecated Please use AbstractGoogleClient#batch(HttpRequestInitializer) to instantiate your
* batch request.
*/
@Deprecated
public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer) {
this.requestFactory = httpRequestInitializer == null
? transport.createRequestFactory() : transport.createRequestFactory(httpRequestInitializer);
Expand Down Expand Up @@ -213,6 +230,13 @@ public int size() {
public void execute() throws IOException {
boolean retryAllowed;
Preconditions.checkState(!requestInfos.isEmpty());

// Log a warning if the user is using the global batch endpoint. In the future, we can turn this
// into a preconditions check.
if (this.batchUrl.toString().equals(GLOBAL_BATCH_ENDPOINT)) {
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.log(Level.WARNING, GLOBAL_BATCH_ENDPOINT_WARNING);
}

HttpRequest batchRequest = requestFactory.buildPostRequest(this.batchUrl, null);
// NOTE: batch does not support gzip encoding
HttpExecuteInterceptor originalInterceptor = batchRequest.getInterceptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public final BatchRequest batch() {
* @return newly created Batch request
*/
public final BatchRequest batch(HttpRequestInitializer httpRequestInitializer) {
@SuppressWarnings("deprecated")
BatchRequest batch =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we migrate this to the new API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is the method that users should be using that sets the batch path.

new BatchRequest(getRequestFactory().getTransport(), httpRequestInitializer);
if (Strings.isNullOrEmpty(batchPath)) {
Expand Down