Skip to content

Commit d837206

Browse files
author
Stephane Landelle
committed
Change Protocol method to directly use a NettyResponseFuture
1 parent 768a104 commit d837206

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,10 @@ public void handle(final Channel channel, final NettyResponseFuture<?> future, f
463463
}
464464

465465
@Override
466-
public void onError(Channel channel, Throwable error) {
466+
public void onError(NettyResponseFuture<?> future, Throwable error) {
467467
}
468468

469469
@Override
470-
public void onClose(Channel channel) {
470+
public void onClose(NettyResponseFuture<?> future) {
471471
}
472-
}
472+
}

providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Processor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
113113
if (!config.getIOExceptionFilters().isEmpty() && requestSender.applyIoExceptionFiltersAndReplayRequest(future, CHANNEL_CLOSED_EXCEPTION, channel))
114114
return;
115115

116-
protocol.onClose(channel);
116+
protocol.onClose(future);
117117

118118
if (future == null || future.isDone())
119119
channelManager.closeChannel(channel);
@@ -174,12 +174,11 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Excep
174174
try {
175175
LOGGER.debug("Was unable to recover Future: {}", future);
176176
requestSender.abort(future, cause);
177+
protocol.onError(future, e);
177178
} catch (Throwable t) {
178179
LOGGER.error(t.getMessage(), t);
179180
}
180181

181-
protocol.onError(channel, e);
182-
183182
channelManager.closeChannel(channel);
184183
// FIXME not really sure
185184
// ctx.fireChannelRead(e);

providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public Protocol(ChannelManager channelManager, AsyncHttpClientConfig config, Net
8686

8787
public abstract void handle(Channel channel, NettyResponseFuture<?> future, Object message) throws Exception;
8888

89-
public abstract void onError(Channel channel, Throwable error);
89+
public abstract void onError(NettyResponseFuture<?> future, Throwable error);
9090

91-
public abstract void onClose(Channel channel);
91+
public abstract void onClose(NettyResponseFuture<?> future);
9292

9393
protected boolean exitAfterHandlingRedirect(//
9494
Channel channel,//

providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.asynchttpclient.HttpResponseHeaders;
3636
import org.asynchttpclient.HttpResponseStatus;
3737
import org.asynchttpclient.Request;
38-
import org.asynchttpclient.providers.netty.DiscardEvent;
3938
import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig;
4039
import org.asynchttpclient.providers.netty.channel.ChannelManager;
4140
import org.asynchttpclient.providers.netty.channel.Channels;
@@ -169,16 +168,11 @@ public void handle(Channel channel, NettyResponseFuture<?> future, Object e) thr
169168
}
170169

171170
@Override
172-
public void onError(Channel channel, Throwable e) {
173-
try {
174-
Object attribute = Channels.getAttribute(channel);
175-
logger.warn("onError {}", e);
176-
if (!(attribute instanceof NettyResponseFuture)) {
177-
return;
178-
}
171+
public void onError(NettyResponseFuture<?> future, Throwable e) {
172+
logger.warn("onError {}", e);
179173

180-
NettyResponseFuture<?> nettyResponse = (NettyResponseFuture<?>) attribute;
181-
WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler());
174+
try {
175+
WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(future);
182176

183177
NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted());
184178
if (webSocket != null) {
@@ -191,21 +185,15 @@ public void onError(Channel channel, Throwable e) {
191185
}
192186

193187
@Override
194-
public void onClose(Channel channel) {
188+
public void onClose(NettyResponseFuture<?> future) {
195189
logger.trace("onClose {}");
196-
Object attribute = Channels.getAttribute(channel);
197-
if (!(attribute instanceof NettyResponseFuture))
198-
return;
199190

200191
try {
201-
NettyResponseFuture<?> nettyResponse = NettyResponseFuture.class.cast(attribute);
202-
WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler());
192+
WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(future);
203193
NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted());
204194

205-
// FIXME How could this test not succeed, we just checked above that
206-
// attribute is a NettyResponseFuture????
207195
logger.trace("Connection was closed abnormally (that is, with no close frame being sent).");
208-
if (attribute != DiscardEvent.INSTANCE && webSocket != null)
196+
if (webSocket != null)
209197
webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being sent).");
210198
} catch (Throwable t) {
211199
logger.error("onError", t);

0 commit comments

Comments
 (0)