Commit 6482843f authored by terrymanu's avatar terrymanu
Browse files

refactor ResponseHandler

parent 8d310830
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter {
                authType = AuthType.AUTH_FIN;
                break;
            case AUTH_FIN:
                authSuccess(context, byteBuf, header);
                executeCommand(context, byteBuf, header);
                break;
            default:
                throw new UnsupportedOperationException(authType.name());
@@ -58,15 +58,7 @@ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter {
    
    protected abstract void authing(ChannelHandlerContext context, ByteBuf byteBuf, int header);
    
    protected abstract void authSuccess(ChannelHandlerContext context, ByteBuf byteBuf, int header);
    
    protected abstract void eofPacket(ChannelHandlerContext context, ByteBuf byteBuf);
    
    protected abstract void okPacket(ChannelHandlerContext context, ByteBuf byteBuf);
    
    protected abstract void errPacket(ChannelHandlerContext context, ByteBuf byteBuf);
    
    protected abstract void commonPacket(ChannelHandlerContext context, ByteBuf byteBuf);
    protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf byteBuf, int header);
    
    @Override
    public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
+6 −10
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public final class MySQLResponseHandler extends ResponseHandler {
    }
    
    @Override
    protected void authSuccess(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) {
    protected void executeCommand(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) {
        switch (header) {
            case EofPacket.HEADER:
                eofPacket(context, byteBuf);
@@ -130,12 +130,11 @@ public final class MySQLResponseHandler extends ResponseHandler {
                errPacket(context, byteBuf);
                break;
            default:
                commonPacket(context, byteBuf);
                commandPacket(context, byteBuf);
        }
    }
    
    @Override
    protected void okPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
    private void okPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
        int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText());
        try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) {
            MySQLQueryResult mysqlQueryResult = new MySQLQueryResult();
@@ -147,8 +146,7 @@ public final class MySQLResponseHandler extends ResponseHandler {
        }
    }
    
    @Override
    protected void errPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
    private void errPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
        int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText());
        try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) {
            MySQLQueryResult mysqlQueryResult = new MySQLQueryResult();
@@ -160,8 +158,7 @@ public final class MySQLResponseHandler extends ResponseHandler {
        }
    }
    
    @Override
    protected void eofPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
    private void eofPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
        int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText());
        MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId);
        MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf);
@@ -182,8 +179,7 @@ public final class MySQLResponseHandler extends ResponseHandler {
        }
    }
    
    @Override
    protected void commonPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
    private void commandPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) {
        int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText());
        MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId);
        MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf);