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);
}
}
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;
}
}
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;
}
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);
}
}
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);
}
Aggregations