
com.github.tonivade.resp.RespConnectionHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resp-server Show documentation
Show all versions of resp-server Show documentation
Netty implementation of REdis Serialization Protocol, and a simple framework to implement command based protocols
/*
* Copyright (c) 2015-2019, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.resp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.tonivade.resp.protocol.RedisToken;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
@Sharable
class RespConnectionHandler extends ChannelInboundHandlerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(RespConnectionHandler.class);
private final Resp impl;
RespConnectionHandler(Resp impl) {
this.impl = impl;
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
impl.connected(ctx);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try {
impl.receive(ctx, (RedisToken) msg);
} finally {
ReferenceCountUtil.release(msg);
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
LOGGER.debug("channel inactive");
impl.disconnected(ctx);
ctx.close();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
LOGGER.debug("uncaught exception", cause);
impl.disconnected(ctx);
ctx.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy