Skip to content

Commit f87c49c

Browse files
committed
Rename NettyResponseFuture.STATE into ChannelState
1 parent d1ad887 commit f87c49c

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

client/src/main/java/org/asynchttpclient/netty/NettyResponseFuture.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.asynchttpclient.Request;
3737
import org.asynchttpclient.channel.pool.ConnectionPoolPartitioning;
3838
import org.asynchttpclient.future.AbstractListenableFuture;
39+
import org.asynchttpclient.netty.channel.ChannelState;
3940
import org.asynchttpclient.netty.channel.Channels;
4041
import org.asynchttpclient.netty.request.NettyRequest;
4142
import org.asynchttpclient.netty.timeout.TimeoutsHolder;
@@ -53,10 +54,6 @@ public final class NettyResponseFuture<V> extends AbstractListenableFuture<V> {
5354

5455
private static final Logger LOGGER = LoggerFactory.getLogger(NettyResponseFuture.class);
5556

56-
public enum STATE {
57-
NEW, POOLED, RECONNECTED, CLOSED,
58-
}
59-
6057
private final long start = millisTime();
6158
private final ConnectionPoolPartitioning connectionPoolPartitioning;
6259
private final ProxyServer proxyServer;
@@ -72,7 +69,7 @@ public enum STATE {
7269
private final AtomicBoolean inProxyAuth = new AtomicBoolean(false);
7370
private final AtomicBoolean statusReceived = new AtomicBoolean(false);
7471
private final AtomicLong touch = new AtomicLong(millisTime());
75-
private final AtomicReference<STATE> state = new AtomicReference<>(STATE.NEW);
72+
private final AtomicReference<ChannelState> channelState = new AtomicReference<>(ChannelState.NEW);
7673
private final AtomicBoolean contentProcessed = new AtomicBoolean(false);
7774
private final AtomicInteger currentRetry = new AtomicInteger(0);
7875
private final AtomicBoolean onThrowableCalled = new AtomicBoolean(false);
@@ -348,12 +345,12 @@ public AtomicBoolean getInProxyAuth() {
348345
return inProxyAuth;
349346
}
350347

351-
public STATE getState() {
352-
return state.get();
348+
public ChannelState getChannelState() {
349+
return channelState.get();
353350
}
354351

355-
public void setState(STATE state) {
356-
this.state.set(state);
352+
public void setChannelState(ChannelState channelState) {
353+
this.channelState.set(channelState);
357354
}
358355

359356
public boolean getAndSetStatusReceived(boolean sr) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2015 AsyncHttpClient Project. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at
7+
* http://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the Apache License Version 2.0 is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
13+
*/
14+
package org.asynchttpclient.netty.channel;
15+
16+
public enum ChannelState {
17+
NEW, POOLED, RECONNECTED, CLOSED,
18+
}

client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private void onFutureFailure(Channel channel, Throwable cause) {
119119
LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry);
120120
if (canRetry//
121121
&& cause != null//
122-
&& (future.getState() != NettyResponseFuture.STATE.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) {
122+
&& (future.getChannelState() != ChannelState.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) {
123123

124124
if (requestSender.retry(future)) {
125125
return;

client/src/main/java/org/asynchttpclient/netty/handler/HttpProtocol.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.asynchttpclient.netty.NettyResponseHeaders;
4545
import org.asynchttpclient.netty.NettyResponseStatus;
4646
import org.asynchttpclient.netty.channel.ChannelManager;
47+
import org.asynchttpclient.netty.channel.ChannelState;
4748
import org.asynchttpclient.netty.channel.Channels;
4849
import org.asynchttpclient.netty.request.NettyRequestSender;
4950
import org.asynchttpclient.ntlm.NtlmEngine;
@@ -202,7 +203,7 @@ private boolean exitAfterHandling401(//
202203
}
203204

204205
// FIXME what's this???
205-
future.setState(NettyResponseFuture.STATE.NEW);
206+
future.setChannelState(ChannelState.NEW);
206207
HttpHeaders requestHeaders = new DefaultHttpHeaders().add(request.getHeaders());
207208

208209
switch (realm.getScheme()) {
@@ -333,7 +334,7 @@ private boolean exitAfterHandling407(//
333334
}
334335

335336
// FIXME what's this???
336-
future.setState(NettyResponseFuture.STATE.NEW);
337+
future.setChannelState(ChannelState.NEW);
337338
HttpHeaders requestHeaders = new DefaultHttpHeaders().add(request.getHeaders());
338339

339340
switch (proxyRealm.getScheme()) {

client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.asynchttpclient.netty.Callback;
4646
import org.asynchttpclient.netty.NettyResponseFuture;
4747
import org.asynchttpclient.netty.channel.ChannelManager;
48+
import org.asynchttpclient.netty.channel.ChannelState;
4849
import org.asynchttpclient.netty.channel.Channels;
4950
import org.asynchttpclient.netty.channel.NettyConnectListener;
5051
import org.asynchttpclient.netty.timeout.ReadTimeoutTimerTask;
@@ -207,7 +208,7 @@ private <T> ListenableFuture<T> sendRequestWithCachedChannel(Request request, Pr
207208
if (asyncHandler instanceof AsyncHandlerExtensions)
208209
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPooled(channel);
209210

210-
future.setState(NettyResponseFuture.STATE.POOLED);
211+
future.setChannelState(ChannelState.POOLED);
211212
future.attachChannel(channel, false);
212213

213214
LOGGER.debug("Using cached Channel {} for {} '{}'", channel, future.getNettyRequest().getHttpRequest().getMethod(), future.getNettyRequest().getHttpRequest().getUri());
@@ -359,7 +360,7 @@ public void abort(Channel channel, NettyResponseFuture<?> future, Throwable t) {
359360
channelManager.closeChannel(channel);
360361

361362
if (!future.isDone()) {
362-
future.setState(NettyResponseFuture.STATE.CLOSED);
363+
future.setChannelState(ChannelState.CLOSED);
363364
LOGGER.debug("Aborting Future {}\n", future);
364365
LOGGER.debug(t.getMessage(), t);
365366
future.abort(t);
@@ -380,7 +381,7 @@ public boolean retry(NettyResponseFuture<?> future) {
380381
return false;
381382

382383
if (future.canBeReplayed()) {
383-
future.setState(NettyResponseFuture.STATE.RECONNECTED);
384+
future.setChannelState(ChannelState.RECONNECTED);
384385
future.getAndSetStatusReceived(false);
385386

386387
LOGGER.debug("Trying to recover request {}\n", future.getNettyRequest().getHttpRequest());
@@ -467,7 +468,7 @@ public void replayRequest(final NettyResponseFuture<?> future, FilterContext fc,
467468

468469
Request newRequest = fc.getRequest();
469470
future.setAsyncHandler(fc.getAsyncHandler());
470-
future.setState(NettyResponseFuture.STATE.NEW);
471+
future.setChannelState(ChannelState.NEW);
471472
future.touch();
472473

473474
LOGGER.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future);

client/src/main/java/org/asynchttpclient/netty/request/ProgressListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.asynchttpclient.AsyncHandler;
2323
import org.asynchttpclient.handler.ProgressAsyncHandler;
2424
import org.asynchttpclient.netty.NettyResponseFuture;
25+
import org.asynchttpclient.netty.channel.ChannelState;
2526
import org.asynchttpclient.netty.channel.Channels;
2627
import org.asynchttpclient.netty.future.StackTraceInspector;
2728
import org.slf4j.Logger;
@@ -49,7 +50,7 @@ public ProgressListener(AsyncHandler<?> asyncHandler,//
4950

5051
private boolean abortOnThrowable(Throwable cause, Channel channel) {
5152

52-
if (cause != null && future.getState() != NettyResponseFuture.STATE.NEW) {
53+
if (cause != null && future.getChannelState() != ChannelState.NEW) {
5354
if (cause instanceof IllegalStateException || cause instanceof ClosedChannelException || StackTraceInspector.recoverOnReadOrWriteException(cause)) {
5455
LOGGER.debug(cause.getMessage(), cause);
5556
Channels.silentlyCloseChannel(channel);

0 commit comments

Comments
 (0)