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

Okhttp3 initial implementation #283

Merged
merged 50 commits into from
Jul 24, 2017
Merged

Okhttp3 initial implementation #283

merged 50 commits into from
Jul 24, 2017

Conversation

domesticmouse
Copy link
Contributor

Here's the initial sketch of converting to OkHttp3.

No rush on this review, I'm looking to land this early to mid Q3.

@domesticmouse domesticmouse self-assigned this Jun 28, 2017
@domesticmouse
Copy link
Contributor Author

This will fix #148

domesticmouse and others added 4 commits July 3, 2017 11:13
Fixes issue where runnable was running on the RateLimitExecutorDelayThread thread, allowing only one request per rate limit to go through.
Fix issue where Runnable runs on the incorrect thread
@domesticmouse
Copy link
Contributor Author

PTAL @markmcd @samthor

Copy link
Contributor

@samthor samthor left a comment

Choose a reason for hiding this comment

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

I just looked at the "Okhttp3 initial implementation" patch. It's hard to discern that from general doc updates in the overall PR.

@@ -30,21 +30,20 @@
* text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude
* coordinates. The Directions API can return multi-part directions using a series of waypoints.
*
* <p>See <a href="https://developers.google.com/maps/documentation/directions/intro">documentation</a>.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a big deal but please note that this file has nothing to do with the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

ExceptionsAllowedToRetry exceptionsAllowedToRetry);

interface Builder {

Copy link
Contributor

Choose a reason for hiding this comment

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

why spacing vs not-spacing previously?

Copy link
Contributor Author

@domesticmouse domesticmouse Jul 17, 2017

Choose a reason for hiding this comment

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

I hit the whole code base with google-java-format to bring it into line with our code format standards. I can do that as a separate PR on the master branch and re-generate this branch to bring the noise down.

<T, R extends ApiResponse<T>> PendingResult<T> get(ApiConfig config, Class<? extends R> clazz,
Map<String, String> params) {
Map<String, String> params) {
if (channel != null && !channel.isEmpty() && !params.containsKey("channel")) {
params.put("channel", channel);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it weird to modify the params map of the caller? In the other get() below, you just modify the actual query.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't my code, but I did sign off on bringing it into the code base. At this point I think I'll stick a TODO on it and think about how best to clean it up.

@@ -150,7 +162,8 @@ public GeoApiContext(RequestHandler requestHandler) {
}
}

// Channel can be supplied per-request or per-context. We prioritize it from the request, so if it's not provided there, provide it here
// Channel can be supplied per-request or per-context. We prioritize it from the request,
// so if it's not provided there, provide it here
if (!channelSet && channel != null && !channel.isEmpty()) {
query.append("&channel=").append(channel);
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the query is empty?

*
* @see java.net.URLConnection#setConnectTimeout(int)
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

extra space for some reason?

}

/**
* Sets the default write timeout for new connections. A value of 0 means no timeout.
Copy link
Contributor

Choose a reason for hiding this comment

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

no @see here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious what I should be referring to with a @see here.

/**
* Allows specific API exceptions to be retried or not retried.
*/
public Builder toggleifExceptionIsAllowedToRetry(Class<? extends ApiException> exception,
Copy link
Contributor

Choose a reason for hiding this comment

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

toggleIfException ... (fix camelcase)

Copy link
Contributor

Choose a reason for hiding this comment

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

I might also call this "set". Toggle implies.. on/off automagically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, done

dispatcher.setMaxRequestsPerHost(maxQps);
rateLimitExecutorService.setQueriesPerSecond(maxQps);
}
LOG.info("Request: {}", hostName + url);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove before release?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// with requests.
LOG.warn("OkHttpRequestHandler#setQueriesPerSecond(int,int) deprecated, ignoring minimumInterval");
this.setQueriesPerSecond(maxQps);
return new OkHttpPendingResult<T, R>(req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry);
Copy link
Contributor

Choose a reason for hiding this comment

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

line length?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suspect the reformat caught this one.

@samthor
Copy link
Contributor

samthor commented Jul 17, 2017 via email

@domesticmouse
Copy link
Contributor Author

domesticmouse commented Jul 17, 2017

I'm unsure of the history on these @see lines are, as the linkage between calling this method and the underlying timeout is indirect. It may make more sense to delete them from readTimeout and connectTimeout, as neither of these methods are implemented for the GAE Java7 implementation.

The Occam's razor explanation for the lack of @see on setWriteTimeout is that java.net.URLConnection doesn't contain a setWriteTimeout method...

@domesticmouse domesticmouse merged commit 43bcae6 into googlemaps:okhttp3 Jul 24, 2017
@domesticmouse domesticmouse deleted the okhttp3-impl branch August 15, 2017 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants