
cz.jalasoft.net.http.netty.NettyHttpResponseCollector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of NettyHttpClient Show documentation
Show all versions of NettyHttpClient Show documentation
An implementation of HttpClient API that takes advantage of the Netty framework.
The newest version!
/*
* Copyright (c) 2015 Avast a.s., www.avast.com
*/
package cz.jalasoft.net.http.netty;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId;
import io.netty.handler.codec.http.FullHttpResponse;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* TODO Add JavaDoc description of class
*
* @author Jan Lastovicka ([email protected])
* @since 2015-02-21
*/
@ChannelHandler.Sharable
final class NettyHttpResponseCollector extends ChannelHandlerAdapter {
private final ConcurrentMap responseMap;
NettyHttpResponseCollector() {
responseMap = new ConcurrentHashMap<>();
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
FullHttpResponse response = (FullHttpResponse) msg;
try {
responseMap.put(ctx.channel().id(), response.copy());
} finally {
response.release();
}
ctx.close();
}
FullHttpResponse getAndRemoveResponse(ChannelId channelId) {
return responseMap.remove(channelId);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy