@ChannelHandler.Sharable private class ChannelStatusListener extends ChannelInboundHandlerAdapter { @Override public void channelWritabilityChanged( ChannelHandlerContext ctx ) { release( ctx.channel() ); } } }
@ChannelHandler.Sharable public class DatagramPacketHandler extends MessageToMessageDecoder<DatagramPacket> { public static final DatagramPacketHandler INSTANCE = new DatagramPacketHandler(); @Override protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception { out.add(ReferenceCountUtil.retain(SenderEnvelope.of(msg.content(), msg.sender()))); } }
@Sharable public class CompatibleMarshallingEncoder extends MessageToByteEncoder<Object> {
/** * Created by ohun on 2015/12/19. * length(4)+cmd(1)+cc(2)+flags(1)+sessionId(4)+lrc(1)+body(n) * * @author ohun@live.cn */ @ChannelHandler.Sharable public final class PacketEncoder extends MessageToByteEncoder<Packet> { public static final PacketEncoder INSTANCE = new PacketEncoder(); @Override protected void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf out) throws Exception { encodePacket(packet, out); } }
/** * This class allows one to ensure that at all times for every IP address there is at most one * {@link Channel} connected to the server. */ @ChannelHandler.Sharable public class UniqueIpFilter extends AbstractRemoteAddressFilter<InetSocketAddress> { private final Set<InetAddress> connected = new ConcurrentSet<InetAddress>(); @Override protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception { final InetAddress remoteIp = remoteAddress.getAddress(); if (!connected.add(remoteIp)) { return false; } else { ctx.channel().closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { connected.remove(remoteIp); } }); return true; } } }
@Sharable public class MarshallingEncoder extends MessageToByteEncoder<Object> {
@Sharable public class Base64Encoder extends MessageToMessageEncoder<ByteBuf> {
/** * User: michaels@netflix.com * Date: 4/13/17 * Time: 6:02 PM */ @ChannelHandler.Sharable public class Http2ResetFrameHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2ResetFrame) { // Inform zuul to cancel the request. ctx.fireUserEventTriggered(new RequestCancelledEvent()); } else { super.channelRead(ctx, msg); } } }
/** * This needs to be inserted in the pipeline after the Http2 Codex, but before any h2->h1 conversion. * * User: michaels@netflix.com * Date: 2/8/17 * Time: 9:58 AM */ @ChannelHandler.Sharable public class Http2ConnectionExpiryHandler extends AbstrHttpConnectionExpiryHandler { public Http2ConnectionExpiryHandler(int maxRequests, int maxRequestsUnderBrownout, int maxExpiry) { super(ConnectionCloseType.DELAYED_GRACEFUL, maxRequestsUnderBrownout, maxRequests, maxExpiry); } @Override protected boolean isResponseHeaders(Object msg) { return msg instanceof Http2HeadersFrame; } }
/** * User: michaels@netflix.com * Date: 4/13/17 * Time: 6:02 PM */ @ChannelHandler.Sharable public class Http2ResetFrameHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2ResetFrame) { // Inform zuul to cancel the request. ctx.fireUserEventTriggered(new RequestCancelledEvent()); } else { super.channelRead(ctx, msg); } } }
@ChannelHandler.Sharable public class Connections extends ChannelInboundHandlerAdapter { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { groupMetrics.getForCurrentEventLoop().incrementCurrentConnections(); super.channelActive(ctx); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { super.channelInactive(ctx); } finally { groupMetrics.getForCurrentEventLoop().decrementCurrentConnections(); } } }
/** * This needs to be inserted in the pipeline after the Http2 Codex, but before any h2->h1 conversion. * * User: michaels@netflix.com * Date: 2/8/17 * Time: 9:58 AM */ @ChannelHandler.Sharable public class Http2ConnectionExpiryHandler extends AbstrHttpConnectionExpiryHandler { public Http2ConnectionExpiryHandler(int maxRequests, int maxRequestsUnderBrownout, int maxExpiry) { super(ConnectionCloseType.DELAYED_GRACEFUL, maxRequestsUnderBrownout, maxRequests, maxExpiry); } @Override protected boolean isResponseHeaders(Object msg) { return msg instanceof Http2HeadersFrame; } }
@ChannelHandler.Sharable public class Connections extends ChannelInboundHandlerAdapter { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { groupMetrics.getForCurrentEventLoop().incrementCurrentConnections(); super.channelActive(ctx); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { super.channelInactive(ctx); } finally { groupMetrics.getForCurrentEventLoop().decrementCurrentConnections(); } } }
/** * Author: Susheel Aroskar * Date: 5/16/18 */ @Singleton @ChannelHandler.Sharable public class SamplePushMessageSender extends PushMessageSender { public SamplePushMessageSender(PushConnectionRegistry pushConnectionRegistry) { super(pushConnectionRegistry); } @Override protected PushUserAuth getPushUserAuth(FullHttpRequest request) { final String cid = request.headers().get("X-CUSTOMER_ID"); if (Strings.isNullOrEmpty(cid)) { return new SamplePushUserAuth(HttpResponseStatus.UNAUTHORIZED.code()); } return new SamplePushUserAuth(cid); } }
/** * Author: Susheel Aroskar * Date: 5/16/18 */ @Singleton @ChannelHandler.Sharable public class SamplePushMessageSender extends PushMessageSender { public SamplePushMessageSender(PushConnectionRegistry pushConnectionRegistry) { super(pushConnectionRegistry); } @Override protected PushUserAuth getPushUserAuth(FullHttpRequest request) { final String cid = request.headers().get("X-CUSTOMER_ID"); if (Strings.isNullOrEmpty(cid)) { return new SamplePushUserAuth(HttpResponseStatus.UNAUTHORIZED.code()); } return new SamplePushUserAuth(cid); } }
@Sharable public class Base64Decoder extends MessageToMessageDecoder<ByteBuf> {
@Sharable public class ObjectEncoder extends MessageToByteEncoder<Serializable> { private static final byte[] LENGTH_PLACEHOLDER = new byte[4];
/** * Author: Susheel Aroskar * Date: 5/7/2018 */ @ChannelHandler.Sharable public class Http2StreamErrorHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof StreamException) { StreamException streamEx = (StreamException) cause; ctx.writeAndFlush(new DefaultHttp2ResetFrame(streamEx.error())); } else if (cause instanceof DecoderException) { ctx.writeAndFlush(new DefaultHttp2ResetFrame(Http2Error.PROTOCOL_ERROR)); } else { super.exceptionCaught(ctx, cause); } } }
/** * Author: Susheel Aroskar * Date: 5/7/2018 */ @ChannelHandler.Sharable public class Http2StreamErrorHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof StreamException) { StreamException streamEx = (StreamException) cause; ctx.writeAndFlush(new DefaultHttp2ResetFrame(streamEx.error())); } else if (cause instanceof DecoderException) { ctx.writeAndFlush(new DefaultHttp2ResetFrame(Http2Error.PROTOCOL_ERROR)); } else { super.exceptionCaught(ctx, cause); } } }
@Sharable public class ByteArrayEncoder extends MessageToMessageEncoder<byte[]> { @Override