Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit754bdbf

Browse files
author
Stephane Landelle
committed
Move reaper to Apache provider specific config,closeAsyncHttpClient#331
1 parent88ccbf4 commit754bdbf

File tree

5 files changed

+38
-37
lines changed

5 files changed

+38
-37
lines changed

‎src/main/java/com/ning/http/client/AsyncHttpClientConfig.java‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class AsyncHttpClientConfig {
6565
protectedbooleancompressionEnabled;
6666
protectedStringuserAgent;
6767
protectedbooleanallowPoolingConnection;
68-
protectedScheduledExecutorServicereaper;
6968
protectedExecutorServiceapplicationThreadPool;
7069
protectedProxyServerSelectorproxyServerSelector;
7170
protectedSSLContextsslContext;
@@ -148,7 +147,6 @@ private AsyncHttpClientConfig(int maxTotalConnections,
148147
this.ioExceptionFilters =ioExceptionFilters;
149148
this.requestCompressionLevel =requestCompressionLevel;
150149
this.maxRequestRetry =maxRequestRetry;
151-
this.reaper =reaper;
152150
this.allowSslConnectionPool =allowSslConnectionCaching;
153151
this.removeQueryParamOnRedirect =removeQueryParamOnRedirect;
154152
this.hostnameVerifier =hostnameVerifier;
@@ -166,15 +164,6 @@ private AsyncHttpClientConfig(int maxTotalConnections,
166164
this.useRawUrl =useRawUrl;
167165
}
168166

169-
/**
170-
* A {@link ScheduledExecutorService} used to expire idle connections.
171-
*
172-
* @return {@link ScheduledExecutorService}
173-
*/
174-
publicScheduledExecutorServicereaper() {
175-
returnreaper;
176-
}
177-
178167
/**
179168
* Return the maximum number of connections an {@link com.ning.http.client.AsyncHttpClient} can handle.
180169
*
@@ -469,7 +458,7 @@ public boolean isValid() {
469458
// when using a ManagedExecutorService.
470459
// When this is the case, we assume it's running.
471460
}
472-
return(atpRunning && !reaper.isShutdown());
461+
returnatpRunning;
473462
}
474463

475464
/**
@@ -1091,7 +1080,6 @@ public Builder(AsyncHttpClientConfig prototype) {
10911080
userAgent =prototype.getUserAgent();
10921081
redirectEnabled =prototype.isRedirectEnabled();
10931082
compressionEnabled =prototype.isCompressionEnabled();
1094-
reaper =prototype.reaper();
10951083
applicationThreadPool =prototype.executorService();
10961084

10971085
requestFilters.clear();

‎src/main/java/com/ning/http/client/AsyncHttpClientConfigBean.java‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
importjava.util.LinkedList;
2424
importjava.util.concurrent.ExecutorService;
2525
importjava.util.concurrent.Executors;
26-
importjava.util.concurrent.ScheduledExecutorService;
2726
importjava.util.concurrent.ThreadFactory;
2827

2928
/**
@@ -79,13 +78,6 @@ public boolean verify(String s, SSLSession sslSession) {
7978
}
8079

8180
voidconfigureExecutors() {
82-
reaper =Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(),newThreadFactory() {
83-
publicThreadnewThread(Runnabler) {
84-
Threadt =newThread(r,"AsyncHttpClient-Reaper");
85-
t.setDaemon(true);
86-
returnt;
87-
}
88-
});
8981
applicationThreadPool =Executors.newCachedThreadPool(newThreadFactory() {
9082
publicThreadnewThread(Runnabler) {
9183
Threadt =newThread(r,"AsyncHttpClient-Callback");
@@ -150,14 +142,6 @@ public AsyncHttpClientConfigBean setAllowPoolingConnection(boolean allowPoolingC
150142
returnthis;
151143
}
152144

153-
publicAsyncHttpClientConfigBeansetReaper(ScheduledExecutorServicereaper) {
154-
if (this.reaper !=null) {
155-
this.reaper.shutdownNow();
156-
}
157-
this.reaper =reaper;
158-
returnthis;
159-
}
160-
161145
publicAsyncHttpClientConfigBeansetApplicationThreadPool(ExecutorServiceapplicationThreadPool) {
162146
if (this.applicationThreadPool !=null) {
163147
this.applicationThreadPool.shutdownNow();

‎src/main/java/com/ning/http/client/providers/apache/ApacheAsyncHttpProvider.java‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
importcom.ning.http.util.AsyncHttpProviderUtils;
4646
importcom.ning.http.util.ProxyUtils;
4747
importcom.ning.http.util.UTF8UrlEncoder;
48+
4849
importorg.apache.commons.httpclient.CircularRedirectException;
4950
importorg.apache.commons.httpclient.Credentials;
5051
importorg.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
@@ -85,6 +86,7 @@
8586
importjavax.net.ssl.SSLSocketFactory;
8687
importjavax.net.ssl.TrustManager;
8788
importjavax.net.ssl.X509TrustManager;
89+
8890
importjava.io.ByteArrayInputStream;
8991
importjava.io.File;
9092
importjava.io.FileInputStream;
@@ -107,7 +109,10 @@
107109
importjava.util.Map;
108110
importjava.util.concurrent.Callable;
109111
importjava.util.concurrent.ExecutionException;
112+
importjava.util.concurrent.Executors;
110113
importjava.util.concurrent.Future;
114+
importjava.util.concurrent.ScheduledExecutorService;
115+
importjava.util.concurrent.ThreadFactory;
111116
importjava.util.concurrent.TimeUnit;
112117
importjava.util.concurrent.TimeoutException;
113118
importjava.util.concurrent.atomic.AtomicBoolean;
@@ -129,6 +134,7 @@ public class ApacheAsyncHttpProvider implements AsyncHttpProvider {
129134
privatefinalAtomicIntegermaxConnections =newAtomicInteger();
130135
privatefinalMultiThreadedHttpConnectionManagerconnectionManager;
131136
privatefinalHttpClientParamsparams;
137+
privatefinalScheduledExecutorServicereaper;
132138

133139
static {
134140
finalSocketFactoryfactory =newTrustingSSLSocketFactory();
@@ -157,13 +163,26 @@ public ApacheAsyncHttpProvider(AsyncHttpClientConfig config) {
157163
params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
158164
params.setParameter(HttpMethodParams.RETRY_HANDLER,newDefaultHttpMethodRetryHandler());
159165

160-
AsyncHttpProviderConfig<?, ?>providerConfig =config.getAsyncHttpProviderConfig();
166+
reaper =getReaper(config.getAsyncHttpProviderConfig());
167+
}
168+
169+
privateScheduledExecutorServicegetReaper(AsyncHttpProviderConfig<?, ?>providerConfig) {
170+
171+
ScheduledExecutorServicereaper =null;
161172
if (providerConfiginstanceofApacheAsyncHttpProvider) {
162-
configure(ApacheAsyncHttpProviderConfig.class.cast(providerConfig));
173+
reaper =ApacheAsyncHttpProviderConfig.class.cast(providerConfig).getReaper();
163174
}
164-
}
165175

166-
privatevoidconfigure(ApacheAsyncHttpProviderConfigconfig) {
176+
if (reaper ==null)
177+
reaper =Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(),newThreadFactory() {
178+
publicThreadnewThread(Runnabler) {
179+
Threadt =newThread(r,"AsyncHttpClient-Reaper");
180+
t.setDaemon(true);
181+
returnt;
182+
}
183+
});
184+
185+
returnreaper;
167186
}
168187

169188
public <T>ListenableFuture<T>execute(Requestrequest,AsyncHandler<T>handler)throwsIOException {
@@ -211,6 +230,7 @@ public <T> ListenableFuture<T> execute(Request request, AsyncHandler<T> handler)
211230
}
212231

213232
publicvoidclose() {
233+
reaper.shutdown();
214234
if (idleConnectionTimeoutThread !=null) {
215235
idleConnectionTimeoutThread.shutdown();
216236
idleConnectionTimeoutThread =null;
@@ -455,7 +475,7 @@ public T call() {
455475
intdelay =requestTimeout(config,future.getRequest().getPerRequestConfig());
456476
if (delay != -1) {
457477
ReaperFuturereaperFuture =newReaperFuture(future);
458-
FuturescheduledFuture =config.reaper().scheduleAtFixedRate(reaperFuture,delay,500,TimeUnit.MILLISECONDS);
478+
FuturescheduledFuture =reaper.scheduleAtFixedRate(reaperFuture,delay,500,TimeUnit.MILLISECONDS);
459479
reaperFuture.setScheduledFuture(scheduledFuture);
460480
future.setReaperFuture(reaperFuture);
461481
}

‎src/main/java/com/ning/http/client/providers/apache/ApacheAsyncHttpProviderConfig.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
*/
1313
packagecom.ning.http.client.providers.apache;
1414

15-
importcom.ning.http.client.AsyncHttpProviderConfig;
16-
1715
importjava.util.Map;
1816
importjava.util.Set;
1917
importjava.util.concurrent.ConcurrentHashMap;
18+
importjava.util.concurrent.ScheduledExecutorService;
19+
20+
importcom.ning.http.client.AsyncHttpProviderConfig;
2021

2122
publicclassApacheAsyncHttpProviderConfigimplementsAsyncHttpProviderConfig<String,String> {
2223

2324
privatefinalConcurrentHashMap<String,String>properties =newConcurrentHashMap<String,String>();
2425

26+
privateScheduledExecutorServicereaper;
2527

2628
publicAsyncHttpProviderConfigaddProperty(Stringname,Stringvalue) {
2729
properties.put(name,value);
@@ -39,4 +41,12 @@ public String removeProperty(String name) {
3941
publicSet<Map.Entry<String,String>>propertiesSet() {
4042
returnproperties.entrySet();
4143
}
44+
45+
publicvoidsetReaper(ScheduledExecutorServicereaper) {
46+
this.reaper =reaper;
47+
}
48+
49+
publicScheduledExecutorServicegetReaper() {
50+
returnreaper;
51+
}
4252
}

‎src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,6 @@ public void close() {
889889
}
890890

891891
config.executorService().shutdown();
892-
config.reaper().shutdown();
893892
if (this.allowReleaseSocketChannelFactory) {
894893
socketChannelFactory.releaseExternalResources();
895894
plainBootstrap.releaseExternalResources();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp