Java Code Examples for org.jboss.netty.channel.ChannelHandlerContext#sendUpstream()

The following examples show how to use org.jboss.netty.channel.ChannelHandlerContext#sendUpstream() . 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: HandshakeTimeoutHandler.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    if (timeoutNanos > 0) {
        timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx), 
                                   timeoutNanos, TimeUnit.NANOSECONDS);
    }
    ctx.sendUpstream(e);
}
 
Example 2
Source File: RSHandshakeTimeoutHandler.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    if (timeoutNanos > 0) {
        timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx), 
                                   timeoutNanos, TimeUnit.NANOSECONDS);
    }
    ctx.sendUpstream(e);
}
 
Example 3
Source File: BootstrapTimeoutHandler.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    if (timeoutNanos > 0) {
        timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx), 
                                   timeoutNanos, TimeUnit.NANOSECONDS);
    }
    ctx.sendUpstream(e);
}
 
Example 4
Source File: HandshakeTimeoutHandler.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
        throws Exception {
    if (timeoutNanos > 0) {
        timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx), 
                                   timeoutNanos, TimeUnit.NANOSECONDS);
    }
    ctx.sendUpstream(e);
}
 
Example 5
Source File: NettyAsyncHttpProvider.java    From ck with Apache License 2.0 5 votes vote down vote up
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
	if (log.isDebugEnabled())
		log.debug("Channel closed: " + e.getState().toString());

	if (!isClose.get() && ctx.getAttachment() instanceof NettyResponseFuture<?>) {
		NettyResponseFuture<?> future = (NettyResponseFuture<?>) ctx.getAttachment();

		if (future!= null && !future.isDone() && !future.isCancelled()){
			future.getAsyncHandler().onThrowable(new IOException("No response received. Connection timed out"));
		}
	}
	ctx.sendUpstream(e);
}
 
Example 6
Source File: MessageHandler.java    From msgpack-rpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
    Object m = e.getMessage();
    if (!(m instanceof Value)) {
        ctx.sendUpstream(e);
        return;
    }

    Value msg = (Value) m;
    handler.handleMessage(adaptor, msg);
}
 
Example 7
Source File: FrameDecoder.java    From android-netty with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {

	Object m = e.getMessage();
	if (!(m instanceof ChannelBuffer)) {
		ctx.sendUpstream(e);
		return;
	}

	ChannelBuffer input = (ChannelBuffer) m;
	if (!input.readable()) {
		return;
	}

	if (cumulation == null) {
		try {
			// the cumulation buffer is not created yet so just pass the
			// input to callDecode(...) method
			callDecode(ctx, e.getChannel(), input, e.getRemoteAddress());
		} finally {
			updateCumulation(ctx, input);
		}
	} else {
		input = appendToCumulation(input);
		try {
			callDecode(ctx, e.getChannel(), input, e.getRemoteAddress());
		} finally {
			updateCumulation(ctx, input);
		}
	}
}
 
Example 8
Source File: NettyDispatcher.java    From ikasoa with MIT License 5 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
	if (e.getMessage() instanceof TNettyMessage) {
		TNettyMessage message = (TNettyMessage) e.getMessage();
		message.setProcessStartTimeMillis(System.currentTimeMillis());
		checkResponseOrderingRequirements(ctx, message);
		TNettyTransport messageTransport = new TNettyTransport(ctx.getChannel(), message);
		TProtocol protocol = protocolFactory.getProtocol(messageTransport);
		processRequest(ctx, message, messageTransport, protocol, protocol);
	} else
		ctx.sendUpstream(e);
}
 
Example 9
Source File: FrameDecoder.java    From android-netty with Apache License 2.0 5 votes vote down vote up
/**
 * Gets called on
 * {@link #channelDisconnected(ChannelHandlerContext, ChannelStateEvent)}
 * and {@link #channelClosed(ChannelHandlerContext, ChannelStateEvent)}
 */
protected void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
	try {
		ChannelBuffer cumulation = this.cumulation;
		if (cumulation == null) {
			return;
		}

		this.cumulation = null;

		if (cumulation.readable()) {
			// Make sure all frames are read before notifying a closed
			// channel.
			callDecode(ctx, ctx.getChannel(), cumulation, null);
		}

		// Call decodeLast() finally. Please note that decodeLast() is
		// called even if there's nothing more to read from the buffer to
		// notify a user that the connection was closed explicitly.
		Object partialFrame = decodeLast(ctx, ctx.getChannel(), cumulation);
		if (partialFrame != null) {
			unfoldAndFireMessageReceived(ctx, null, partialFrame);
		}
	} finally {
		ctx.sendUpstream(e);
	}
}
 
Example 10
Source File: SwitchableLineBasedFrameDecoder.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    if (this.framingEnabled) {
        super.messageReceived(ctx, e);
    } else {
        ctx.sendUpstream(e);
    }
}
 
Example 11
Source File: NettyCodecAdapter.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    ctx.sendUpstream(e);
}
 
Example 12
Source File: NettyCodecAdapter.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
@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 13
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@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 14
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@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: Netty.java    From jlogstash-input-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void exceptionCaught(
        ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
     logger.debug("netty io error:", e.getCause());
  ctx.sendUpstream(e);
}
 
Example 16
Source File: NettyCodecAdapter.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    ctx.sendUpstream(e);
}
 
Example 17
Source File: MemcachedCommandHandler.java    From fqueue with Apache License 2.0 4 votes vote down vote up
/**
 * The actual meat of the matter. Turn CommandMessages into executions
 * against the physical cache, and then pass on the downstream messages.
 * 
 * @param channelHandlerContext
 * @param messageEvent
 * @throws Exception
 */

@Override
@SuppressWarnings("unchecked")
public void messageReceived(ChannelHandlerContext channelHandlerContext, MessageEvent messageEvent)
		throws Exception {
	if (!(messageEvent.getMessage() instanceof CommandMessage)) {
		// Ignore what this encoder can't encode.
		channelHandlerContext.sendUpstream(messageEvent);
		return;
	}

	CommandMessage<CACHE_ELEMENT> command = (CommandMessage<CACHE_ELEMENT>) messageEvent.getMessage();
	Command cmd = command.cmd;
	int cmdKeysSize = command.keys.size();

	// first process any messages in the delete queue
	cache.asyncEventPing();

	// now do the real work
	if (this.verbose) {
		StringBuilder log = new StringBuilder();
		log.append(cmd);
		if (command.element != null) {
			log.append(" ").append(command.element.getKeystring());
		}
		for (int i = 0; i < cmdKeysSize; i++) {
			log.append(" ").append(command.keys.get(i));
		}
		logger.info(log.toString());
	}

	Channel channel = messageEvent.getChannel();
	if (cmd == Command.GET || cmd == Command.GETS) {
		handleGets(channelHandlerContext, command, channel);
	} else if (cmd == Command.SET) {
		handleSet(channelHandlerContext, command, channel);
	} else if (cmd == Command.CAS) {
		handleCas(channelHandlerContext, command, channel);
	} else if (cmd == Command.ADD) {
		handleAdd(channelHandlerContext, command, channel);
	} else if (cmd == Command.REPLACE) {
		handleReplace(channelHandlerContext, command, channel);
	} else if (cmd == Command.APPEND) {
		handleAppend(channelHandlerContext, command, channel);
	} else if (cmd == Command.PREPEND) {
		handlePrepend(channelHandlerContext, command, channel);
	} else if (cmd == Command.INCR) {
		handleIncr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DECR) {
		handleDecr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DELETE) {
		handleDelete(channelHandlerContext, command, channel);
	} else if (cmd == Command.STATS) {
		handleStats(channelHandlerContext, command, cmdKeysSize, channel);
	} else if (cmd == Command.VERSION) {
		handleVersion(channelHandlerContext, command, channel);
	} else if (cmd == Command.QUIT) {
		handleQuit(channel);
	} else if (cmd == Command.FLUSH_ALL) {
		handleFlush(channelHandlerContext, command, channel);
	} else if (cmd == null) {
		// NOOP
		handleNoOp(channelHandlerContext, command);
	} else {
		throw new UnknownCommandException("unknown command:" + cmd);

	}

}
 
Example 18
Source File: MemcachedCommandHandler.java    From fqueue with Apache License 2.0 4 votes vote down vote up
/**
 * The actual meat of the matter. Turn CommandMessages into executions
 * against the physical cache, and then pass on the downstream messages.
 * 
 * @param channelHandlerContext
 * @param messageEvent
 * @throws Exception
 */

@Override
@SuppressWarnings("unchecked")
public void messageReceived(ChannelHandlerContext channelHandlerContext, MessageEvent messageEvent)
		throws Exception {
	if (!(messageEvent.getMessage() instanceof CommandMessage)) {
		// Ignore what this encoder can't encode.
		channelHandlerContext.sendUpstream(messageEvent);
		return;
	}

	CommandMessage<CACHE_ELEMENT> command = (CommandMessage<CACHE_ELEMENT>) messageEvent.getMessage();
	Command cmd = command.cmd;
	int cmdKeysSize = command.keys.size();

	// first process any messages in the delete queue
	cache.asyncEventPing();

	// now do the real work
	if (this.verbose) {
		StringBuilder log = new StringBuilder();
		log.append(cmd);
		if (command.element != null) {
			log.append(" ").append(command.element.getKeystring());
		}
		for (int i = 0; i < cmdKeysSize; i++) {
			log.append(" ").append(command.keys.get(i));
		}
		logger.info(log.toString());
	}

	Channel channel = messageEvent.getChannel();
	if (cmd == Command.GET || cmd == Command.GETS) {
		handleGets(channelHandlerContext, command, channel);
	} else if (cmd == Command.SET) {
		handleSet(channelHandlerContext, command, channel);
	} else if (cmd == Command.CAS) {
		handleCas(channelHandlerContext, command, channel);
	} else if (cmd == Command.ADD) {
		handleAdd(channelHandlerContext, command, channel);
	} else if (cmd == Command.REPLACE) {
		handleReplace(channelHandlerContext, command, channel);
	} else if (cmd == Command.APPEND) {
		handleAppend(channelHandlerContext, command, channel);
	} else if (cmd == Command.PREPEND) {
		handlePrepend(channelHandlerContext, command, channel);
	} else if (cmd == Command.INCR) {
		handleIncr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DECR) {
		handleDecr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DELETE) {
		handleDelete(channelHandlerContext, command, channel);
	} else if (cmd == Command.STATS) {
		handleStats(channelHandlerContext, command, cmdKeysSize, channel);
	} else if (cmd == Command.VERSION) {
		handleVersion(channelHandlerContext, command, channel);
	} else if (cmd == Command.QUIT) {
		handleQuit(channel);
	} else if (cmd == Command.FLUSH_ALL) {
		handleFlush(channelHandlerContext, command, channel);
	} else if (cmd == null) {
		// NOOP
		handleNoOp(channelHandlerContext, command);
	} else {
		throw new UnknownCommandException("unknown command:" + cmd);

	}

}
 
Example 19
Source File: NettyCodecAdapter.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
@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 20
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@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());
    }
}