googleapis / googleapis/google-http-java-client

allow overriding HttpResponse.getContent to install download throttler

オープン
#586 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
type: feature request
主要言語
Java
スター
1.4k
フォーク
473
PR マージ指標
30日以内にマージされた PR はありません

説明

We need to throttle downloads from cloud storage in order to minimize GC disturbances during (data) reload. I was unable to find a clean way to do this via existing API. Instead, the following workaround was implemented which suffers from extending `HttpURLConnection`. Is it possible to provide a proper hook for intercepting `InputStream`?

```java
protected Storage installHttpThrottler(StorageOptions.Builder storageOptions) {
return storageOptions
.setTransportOptions(HttpTransportOptions.newBuilder().setHttpTransportFactory(new ThrottledHttpTransportFactory()).build())
.build()
.getService();
}
```

```java
class ThrottledHttpTransportFactory implements HttpTransportFactory {
public HttpTransport create() { return new NetHttpTransport.Builder().setConnectionFactory(new ThrottledConnectionFactory()).build(); }
}
```

```java
class ThrottledConnectionFactory extends DefaultConnectionFactory {
@Override
public HttpURLConnection openConnection(URL url) throws IOException {
return new ThrottledUrlConnection(super.openConnection(url), url);
}
}
```

```java
class ThrottledUrlConnection extends HttpURLConnection {
HttpURLConnection delegate;

ThrottledUrlConnection(HttpURLConnection delegate, URL url) {
super(url);
this.delegate = delegate;
}

@Override
public InputStream getInputStream() throws IOException {
return new ThrottledInputStream(delegate.getInputStream(), rateLimiter, throughputMeter);
}
// followed by a long list of overridden methods to redirect via 'delegate'
....
}
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。