Search in sources :

Example 46 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project storm by apache.

the class ThriftEncoder method encodeNettySerializable.

private HBMessage encodeNettySerializable(INettySerializable netty_message, HBServerMessageType mType) {
    HBMessageData message_data = new HBMessageData();
    HBMessage m = new HBMessage();
    try {
        ChannelBuffer cbuffer = netty_message.buffer();
        if (cbuffer.hasArray()) {
            message_data.set_message_blob(cbuffer.array());
        } else {
            byte[] buff = new byte[netty_message.encodeLength()];
            cbuffer.readBytes(buff, 0, netty_message.encodeLength());
            message_data.set_message_blob(buff);
        }
        m.set_type(mType);
        m.set_data(message_data);
        return m;
    } catch (IOException e) {
        LOG.error("Failed to encode NettySerializable: ", e);
        throw new RuntimeException(e);
    }
}
Also used : HBMessageData(org.apache.storm.generated.HBMessageData) IOException(java.io.IOException) HBMessage(org.apache.storm.generated.HBMessage) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 47 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project Openfire by igniterealtime.

the class RtmfpChannelUpstreamHandler method messageReceived.

public void messageReceived(ChannelHandlerContext channelhandlercontext, MessageEvent messageevent) throws Exception {
    ChannelBuffer channelbuffer = (ChannelBuffer) messageevent.getMessage();
    if (channelbuffer.readableBytes() < 16)
        Log.debug((new StringBuilder()).append("Incorrect packet received from ").append(messageevent.getRemoteAddress()).toString());
    byte[] abyte0 = channelbuffer.array();
    AudioPacket packet = new AudioPacket(abyte0, channelbuffer.readableBytes());
    int i = com.jcumulus.server.rtmfp.N.A(packet);
    ServerSession h = sessions.A(i);
    if (h == null) {
        Log.warn((new StringBuilder()).append("Session with id=").append(i).append(" isn't found").toString());
        return;
    } else {
        h.A(messageevent.getChannel(), messageevent.getRemoteAddress());
        h.A(packet);
        return;
    }
}
Also used : ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 48 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project Openfire by igniterealtime.

the class B method E.

public ChannelBuffer E() {
    ChannelBuffer channelbuffer = ChannelBuffers.buffer(A());
    channelbuffer.writeBytes(E, 0, A());
    return channelbuffer;
}
Also used : ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 49 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project databus by linkedin.

the class FooterAwareHttpChunkAggregator method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    Object msg = e.getMessage();
    HttpMessage currentMessage = this.currentMessage;
    if (msg instanceof HttpMessage) {
        HttpMessage m = (HttpMessage) msg;
        if (m.isChunked()) {
            // A chunked message - remove 'Transfer-Encoding' header,
            // initialize the cumulative buffer, and wait for incoming chunks.
            List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
            encodings.remove(HttpHeaders.Values.CHUNKED);
            if (encodings.isEmpty()) {
                m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
            }
            m.setContent(ChannelBuffers.dynamicBuffer(e.getChannel().getConfig().getBufferFactory()));
            this.currentMessage = m;
        } else {
            // Not a chunked message - pass through.
            this.currentMessage = null;
            ctx.sendUpstream(e);
        }
    } else if (msg instanceof HttpChunk) {
        // Sanity check
        if (currentMessage == null) {
            throw new IllegalStateException("received " + HttpChunk.class.getSimpleName() + " without " + HttpMessage.class.getSimpleName());
        }
        // Merge the received chunk into the content of the current message.
        HttpChunk chunk = (HttpChunk) msg;
        ChannelBuffer content = currentMessage.getContent();
        if (content.readableBytes() > maxContentLength - chunk.getContent().readableBytes()) {
            throw new TooLongFrameException("HTTP content length exceeded " + maxContentLength + " bytes.");
        }
        content.writeBytes(chunk.getContent());
        if (chunk.isLast()) {
            this.currentMessage = null;
            currentMessage.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(content.readableBytes()));
            if (chunk instanceof HttpChunkTrailer) {
                HttpChunkTrailer chunkTrailer = (HttpChunkTrailer) chunk;
                for (Entry<String, String> footer : chunkTrailer.getHeaders()) {
                    currentMessage.setHeader(footer.getKey(), footer.getValue());
                }
            }
            Channels.fireMessageReceived(ctx, currentMessage, e.getRemoteAddress());
        }
    } else {
        // Neither HttpMessage or HttpChunk
        ctx.sendUpstream(e);
    }
}
Also used : Entry(java.util.Map.Entry) TooLongFrameException(org.jboss.netty.handler.codec.frame.TooLongFrameException) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) HttpMessage(org.jboss.netty.handler.codec.http.HttpMessage) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 50 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer 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

ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)494 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)70 Test (org.junit.Test)67 DeviceSession (org.traccar.DeviceSession)64 Position (org.traccar.model.Position)62 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)61 Test (org.testng.annotations.Test)49 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)48 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)44 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)37 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)34 ChannelFuture (org.jboss.netty.channel.ChannelFuture)28 Checkpoint (com.linkedin.databus.core.Checkpoint)27 ByteBuffer (java.nio.ByteBuffer)27 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)26 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)26 DateBuilder (org.traccar.helper.DateBuilder)26 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)23