Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2dcd409
Better behaviour in the presence of backing off
j-baker Aug 2, 2018
c583b33
Merge branch 'develop' into jbaker/better_429_behaviour
j-baker Aug 2, 2018
d51d3ac
more docs, easier to read
j-baker Aug 2, 2018
19a8173
Better concurrency limiters
j-baker Aug 3, 2018
d7164de
fixes
j-baker Aug 3, 2018
39388b7
simplify
j-baker Aug 3, 2018
f2927d0
Checkstyle
j-baker Aug 13, 2018
8f57de6
checkstyle
j-baker Aug 13, 2018
8f02b8b
PR comments
j-baker Sep 2, 2018
fbbcc41
Tweak the concurrency limiters lib
j-baker Sep 2, 2018
27a2153
reset flow control test
j-baker Sep 2, 2018
e548996
changes
j-baker Sep 2, 2018
a4c9e68
Changes
j-baker Sep 2, 2018
c68bc89
Passes the build
j-baker Sep 2, 2018
91dd6d2
update lockfiles
j-baker Sep 2, 2018
2229a81
Merge remote-tracking branch 'origin/develop' into jbaker/better_429_…
j-baker Sep 11, 2018
ee8e539
New attempt using interceptor
j-baker Sep 11, 2018
036d45b
more comments
j-baker Sep 11, 2018
1e18435
some bullshit
j-baker Sep 12, 2018
fbdeab1
Perfect
j-baker Sep 12, 2018
951dfdd
cleanup
j-baker Sep 12, 2018
ed18c48
Ready to go?
j-baker Sep 13, 2018
fda4d64
docs
j-baker Sep 13, 2018
8a088d7
Checkstyle
j-baker Sep 13, 2018
a9721e4
chekcstyle
j-baker Sep 13, 2018
1ce7b82
Metric
j-baker Sep 13, 2018
bc38b76
Javadoc
iamdanfox Sep 13, 2018
addbdca
README describes new flow control
iamdanfox Sep 13, 2018
c97925a
Move docs -> class level javadoc
iamdanfox Sep 13, 2018
baaa142
Rename ConcurrencyLimiters#limiter -> acquireLimiter
iamdanfox Sep 13, 2018
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
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
j-baker committed Sep 12, 2018
commit 951dfdd75e05faa5ec027978eb28f3bf324881e1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import com.google.common.collect.ImmutableSet;
import com.netflix.concurrency.limits.Limiter;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import okhttp3.Interceptor;
import okhttp3.Response;
import okhttp3.ResponseBody;
Expand Down Expand Up @@ -78,28 +82,47 @@ private static Response wrapResponse(Limiter.Listener listener, Response respons
}
ResponseBody currentBody = response.body();
ResponseBody newResponseBody =
ResponseBody.create(currentBody.contentType(), currentBody.contentLength(),
new ReleaseConcurrencyLimitBufferedSource(currentBody.source(), listener));
ResponseBody.create(
currentBody.contentType(),
currentBody.contentLength(),
wrapSource(currentBody.source(), listener));
return response.newBuilder()
.body(newResponseBody)
.build();
}

private static final class ReleaseConcurrencyLimitBufferedSource extends ForwardingBufferedSource {
private static BufferedSource wrapSource(BufferedSource currentSource, Limiter.Listener listener) {
return (BufferedSource) Proxy.newProxyInstance(
BufferedSource.class.getClassLoader(),
new Class<?>[] { BufferedSource.class },
new ReleaseConcurrencyLimitProxy(currentSource, listener));
}

/**
* This proxy enables e.g. Okio to make additive additions to their API without breaking us.
*/
private static final class ReleaseConcurrencyLimitProxy implements InvocationHandler {
private final BufferedSource delegate;
private final Limiter.Listener listener;
private boolean closed = false;

private ReleaseConcurrencyLimitBufferedSource(BufferedSource delegate, Limiter.Listener listener) {
super(delegate);
this.listener = listener;
private ReleaseConcurrencyLimitProxy(BufferedSource delegate, Limiter.Listener listener) {
this.delegate = delegate;
this.listener = listener;
}

@Override
public void close() throws IOException {
listener.onSuccess();
delegate.close();
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("close") && !closed) {
closed = true;
listener.onSuccess();
Copy link
Contributor

Choose a reason for hiding this comment

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

So the closing mechanism is now implicit, in that as long as the response body is closed (either by reading it fully during json object mapping, or via inputstream.close() if streaming and want to finish earlier) we tag as successful?

Is it viable at some point to have more control over this? One thing that occasionally happens when streaming is your stream ends too early because an error was encountered once some data (esp. headers) was already sent. We would preferably mark those as failed.

}

try {
return method.invoke(delegate, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private static RemotingOkHttpClient createInternal(
client.sslSocketFactory(config.sslSocketFactory(), config.trustManager());

// Intercept calls to augment request meta data
client.addInterceptor(new ConcurrencyLimitingInterceptor());
client.addInterceptor(InstrumentedInterceptor.create(registry, hostMetrics, serviceClass));
client.addInterceptor(OkhttpTraceInterceptor.INSTANCE);
client.addInterceptor(UserAgentInterceptor.of(augmentUserAgent(userAgent, serviceClass)));
Expand Down