Java Code Examples for org.jboss.netty.channel.Channels#fireMessageReceived()
The following examples show how to use
org.jboss.netty.channel.Channels#fireMessageReceived() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RpcUtil.java From hadoop with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { ChannelBuffer buf = (ChannelBuffer) e.getMessage(); ByteBuffer b = buf.toByteBuffer().asReadOnlyBuffer(); XDR in = new XDR(b, XDR.State.READING); RpcInfo info = null; try { RpcCall callHeader = RpcCall.read(in); ChannelBuffer dataBuffer = ChannelBuffers.wrappedBuffer(in.buffer() .slice()); info = new RpcInfo(callHeader, dataBuffer, ctx, e.getChannel(), e.getRemoteAddress()); } catch (Exception exc) { LOG.info("Malformed RPC request from " + e.getRemoteAddress()); } if (info != null) { Channels.fireMessageReceived(ctx, info); } }
Example 2
Source File: RpcUtil.java From big-c with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { ChannelBuffer buf = (ChannelBuffer) e.getMessage(); ByteBuffer b = buf.toByteBuffer().asReadOnlyBuffer(); XDR in = new XDR(b, XDR.State.READING); RpcInfo info = null; try { RpcCall callHeader = RpcCall.read(in); ChannelBuffer dataBuffer = ChannelBuffers.wrappedBuffer(in.buffer() .slice()); info = new RpcInfo(callHeader, dataBuffer, ctx, e.getChannel(), e.getRemoteAddress()); } catch (Exception exc) { LOG.info("Malformed RPC request from " + e.getRemoteAddress()); } if (info != null) { Channels.fireMessageReceived(ctx, info); } }
Example 3
Source File: FrameDecoder.java From android-netty with Apache License 2.0 | 6 votes |
/** * Replace this {@link FrameDecoder} in the {@link ChannelPipeline} with the * given {@link ChannelHandler}. All remaining bytes in the * {@link ChannelBuffer} will get send to the new {@link ChannelHandler} * that was used as replacement * */ public void replace(String handlerName, ChannelHandler handler) { if (ctx == null) { throw new IllegalStateException("Replace cann only be called once the FrameDecoder is added to the ChannelPipeline"); } ChannelPipeline pipeline = ctx.getPipeline(); pipeline.addAfter(ctx.getName(), handlerName, handler); try { if (cumulation != null) { Channels.fireMessageReceived(ctx, cumulation.readBytes(actualReadableBytes())); } } finally { pipeline.remove(this); } }
Example 4
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 5 votes |
protected void handleReplace(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Cache.StoreResponse ret; ret = cache.replace(command.element); Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel .getRemoteAddress()); }
Example 5
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 5 votes |
protected void handleCas(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Cache.StoreResponse ret; ret = cache.cas(command.cas_key, command.element); Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel .getRemoteAddress()); }
Example 6
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 5 votes |
protected void handleAppend(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Cache.StoreResponse ret; ret = cache.append(command.element); Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel .getRemoteAddress()); }
Example 7
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 5 votes |
protected void handlePrepend(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Cache.StoreResponse ret; ret = cache.prepend(command.element); Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel .getRemoteAddress()); }
Example 8
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 5 votes |
protected void handlePrepend(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Cache.StoreResponse ret; ret = cache.prepend(command.element); Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel .getRemoteAddress()); }
Example 9
Source File: SwitchableLineBasedFrameDecoder.java From james-project with Apache License 2.0 | 5 votes |
public synchronized void disableFraming(ChannelHandlerContext ctx) { this.framingEnabled = false; if (this.cumulation != null && this.cumulation.readable()) { final ChannelBuffer spareBytes = this.cumulation.readBytes(this.cumulation.readableBytes()); Channels.fireMessageReceived(ctx, spareBytes); } }
Example 10
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 5 votes |
protected void handleStats(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, int cmdKeysSize, Channel channel) { String option = ""; if (cmdKeysSize > 0) { option = command.keys.get(0); } Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withStatResponse(cache.stat( option, channelHandlerContext)), channel.getRemoteAddress()); }
Example 11
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 5 votes |
protected void handleReplace(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Cache.StoreResponse ret; ret = cache.replace(command.element); Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel .getRemoteAddress()); }
Example 12
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 4 votes |
protected void handleFlush(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withFlushResponse(cache .flush_all(command.time)), channel.getRemoteAddress()); }
Example 13
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 4 votes |
protected void handleDecr(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Integer incrDecrResp = cache.get_add(command.keys.get(0), -1 * command.incrAmount); Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command) .withIncrDecrResponse(incrDecrResp), channel.getRemoteAddress()); }
Example 14
Source File: NettyCodecAdapter.java From dubbox with Apache License 2.0 | 4 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception { Object o = event.getMessage(); if (! (o instanceof ChannelBuffer)) { ctx.sendUpstream(event); return; } ChannelBuffer input = (ChannelBuffer) o; int readable = input.readableBytes(); if (readable <= 0) { return; } com.alibaba.dubbo.remoting.buffer.ChannelBuffer message; if (buffer.readable()) { if (buffer instanceof DynamicChannelBuffer) { buffer.writeBytes(input.toByteBuffer()); message = buffer; } else { int size = buffer.readableBytes() + input.readableBytes(); message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.dynamicBuffer( size > bufferSize ? size : bufferSize); message.writeBytes(buffer, buffer.readableBytes()); message.writeBytes(input.toByteBuffer()); } } else { message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.wrappedBuffer( input.toByteBuffer()); } NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); Object msg; int saveReaderIndex; try { // decode object. do { saveReaderIndex = message.readerIndex(); try { msg = codec.decode(channel, message); } catch (IOException e) { buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER; throw e; } if (msg == Codec2.DecodeResult.NEED_MORE_INPUT) { message.readerIndex(saveReaderIndex); break; } else { if (saveReaderIndex == message.readerIndex()) { buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER; throw new IOException("Decode without read data."); } if (msg != null) { Channels.fireMessageReceived(ctx, msg, event.getRemoteAddress()); } } } while (message.readable()); } finally { if (message.readable()) { message.discardReadBytes(); buffer = message; } else { buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER; } NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }
Example 15
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 4 votes |
protected void handleGets(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) { CACHE_ELEMENT[] results = get(command.keys.toArray(new String[command.keys.size()])); ResponseMessage<CACHE_ELEMENT> resp = new ResponseMessage<CACHE_ELEMENT>(command).withElements(results); Channels.fireMessageReceived(channelHandlerContext, resp, channel.getRemoteAddress()); }
Example 16
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 4 votes |
protected void handleFlush(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) throws DatabaseException, Exception { Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withFlushResponse(cache .flush_all(command.time)), channel.getRemoteAddress()); }
Example 17
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 4 votes |
protected void handleNoOp(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command) { Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command)); }
Example 18
Source File: RpcUtil.java From big-c with Apache License 2.0 | 4 votes |
public static void sendRpcResponse(ChannelHandlerContext ctx, RpcResponse response) { Channels.fireMessageReceived(ctx, response); }
Example 19
Source File: MemcachedCommandHandler.java From fqueue with Apache License 2.0 | 4 votes |
protected void handleGets(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command, Channel channel) { CACHE_ELEMENT[] results = get(command.keys.toArray(new String[command.keys.size()])); ResponseMessage<CACHE_ELEMENT> resp = new ResponseMessage<CACHE_ELEMENT>(command).withElements(results); Channels.fireMessageReceived(channelHandlerContext, resp, channel.getRemoteAddress()); }
Example 20
Source File: NettyCodecAdapter.java From dubbox with Apache License 2.0 | 4 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception { Object o = event.getMessage(); if (! (o instanceof ChannelBuffer)) { ctx.sendUpstream(event); return; } ChannelBuffer input = (ChannelBuffer) o; int readable = input.readableBytes(); if (readable <= 0) { return; } com.alibaba.dubbo.remoting.buffer.ChannelBuffer message; if (buffer.readable()) { if (buffer instanceof DynamicChannelBuffer) { buffer.writeBytes(input.toByteBuffer()); message = buffer; } else { int size = buffer.readableBytes() + input.readableBytes(); message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.dynamicBuffer( size > bufferSize ? size : bufferSize); message.writeBytes(buffer, buffer.readableBytes()); message.writeBytes(input.toByteBuffer()); } } else { message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.wrappedBuffer( input.toByteBuffer()); } NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); Object msg; int saveReaderIndex; try { // decode object. do { saveReaderIndex = message.readerIndex(); try { msg = codec.decode(channel, message); } catch (IOException e) { buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER; throw e; } if (msg == Codec2.DecodeResult.NEED_MORE_INPUT) { message.readerIndex(saveReaderIndex); break; } else { if (saveReaderIndex == message.readerIndex()) { buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER; throw new IOException("Decode without read data."); } if (msg != null) { Channels.fireMessageReceived(ctx, msg, event.getRemoteAddress()); } } } while (message.readable()); } finally { if (message.readable()) { message.discardReadBytes(); buffer = message; } else { buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER; } NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }