Search in sources :

Example 1 with SocketResponse

use of com.github.dreamhead.moco.SocketResponse in project moco by dreamhead.

the class MocoSocketHandler method channelRead0.

@Override
protected void channelRead0(final ChannelHandlerContext ctx, final ByteBuf msg) throws Exception {
    try {
        MessageContent content = content().withContent(new ByteBufInputStream(msg)).build();
        SocketRequest request = new DefaultSocketRequest(content);
        this.monitor.onMessageArrived(request);
        SocketResponse response = new DefaultSocketResponse();
        handleSession(new SessionContext(request, response));
        this.monitor.onMessageLeave(response);
        ctx.write(Unpooled.wrappedBuffer(response.getContent().getContent()));
    } catch (Exception e) {
        this.monitor.onException(e);
    }
}
Also used : MessageContent(com.github.dreamhead.moco.model.MessageContent) DefaultSocketRequest(com.github.dreamhead.moco.model.DefaultSocketRequest) SocketRequest(com.github.dreamhead.moco.SocketRequest) DefaultSocketRequest(com.github.dreamhead.moco.model.DefaultSocketRequest) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) SocketResponse(com.github.dreamhead.moco.SocketResponse) DefaultSocketResponse(com.github.dreamhead.moco.model.DefaultSocketResponse) DefaultSocketResponse(com.github.dreamhead.moco.model.DefaultSocketResponse) MocoException(com.github.dreamhead.moco.MocoException)

Aggregations

MocoException (com.github.dreamhead.moco.MocoException)1 SocketRequest (com.github.dreamhead.moco.SocketRequest)1 SocketResponse (com.github.dreamhead.moco.SocketResponse)1 DefaultSocketRequest (com.github.dreamhead.moco.model.DefaultSocketRequest)1 DefaultSocketResponse (com.github.dreamhead.moco.model.DefaultSocketResponse)1 MessageContent (com.github.dreamhead.moco.model.MessageContent)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1