Search in sources :

Example 1 with AbstractFrontendMessage

use of org.adbcj.postgresql.codec.frontend.AbstractFrontendMessage in project adbcj by mheath.

the class Encoder method handleDownstream.

public void handleDownstream(ChannelHandlerContext context, ChannelEvent event) throws Exception {
    if (!(event instanceof MessageEvent)) {
        context.sendDownstream(event);
        return;
    }
    MessageEvent e = (MessageEvent) event;
    Object message = e.getMessage();
    boolean singleMessage = message instanceof AbstractFrontendMessage;
    boolean multipleMessages = message instanceof AbstractFrontendMessage[];
    if (!singleMessage && !multipleMessages) {
        context.sendDownstream(event);
        return;
    }
    ChannelBuffer buffer = ChannelBuffers.buffer(1024);
    ChannelBufferOutputStream out = new ChannelBufferOutputStream(buffer);
    if (singleMessage) {
        encoder.encode(out, (AbstractFrontendMessage) e.getMessage());
    } else {
        encoder.encode(out, (AbstractFrontendMessage[]) e.getMessage());
    }
    Channels.write(context, e.getFuture(), buffer);
}
Also used : ChannelBufferOutputStream(org.jboss.netty.buffer.ChannelBufferOutputStream) AbstractFrontendMessage(org.adbcj.postgresql.codec.frontend.AbstractFrontendMessage) MessageEvent(org.jboss.netty.channel.MessageEvent) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

AbstractFrontendMessage (org.adbcj.postgresql.codec.frontend.AbstractFrontendMessage)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 ChannelBufferOutputStream (org.jboss.netty.buffer.ChannelBufferOutputStream)1 MessageEvent (org.jboss.netty.channel.MessageEvent)1