Netty dynamic pipeline change

39 views
Skip to first unread message

fel...@gmail.com

unread,
Aug 12, 2016, 1:08:10 AM8/12/16
to Netty discussions
Hey everyone.
I'm currently workin on a websocket Server based on netty 4.1.2.
My Problem is, when i change my pipeline durring runtime, it has no effects. I want to replace a handler with another one.


public class FrameHandlerLogin extends SimpleChannelInboundHandler<WebSocketFrame> {
    private  String USER = "aUser";
    private String PASSWORD = "aPassword";




   
    protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
        String recievedUser;
        String recievedPsw;
      

        if (frame instanceof TextWebSocketFrame) {
            //some JSON sutff, not important
 
            if (recievedUser.equals(USER) && recievedPsw.equals(PASSWORD) ) {
                System.out.println("Recieved correct User and Password!");
   
                ctx.pipeline().remove("HandlerLogin");
                ctx.pipeline().addLast("HandlerSQL", new FrameHandlerSQL());

                ctx.channel().writeAndFlush(new TextWebSocketFrame("Success"));
               

            } else if (request.equals("Stop")) {
                System.out.println("Recieved Stop");
                ctx.close();
            } else {
                ctx.channel().writeAndFlush(
                        new TextWebSocketFrame("Password wrong."));
            }
        } else {

            String message = "unsupported frame type: " + frame.getClass().getName();
            throw new UnsupportedOperationException(message);
        }

    }
}

I thought it is possible to change the pipeline? But why does it take no effect?
Reply all
Reply to author
Forward
0 new messages