MINA源码分析---协议解码输出接口ProtocolDecoderOutput及其实现
2014-12-07 15:54
483 查看
接口 ProtocolDecoderOutput
/*
*/
package org.apache.mina.filter.codec;
import org.apache.mina.core.filterchain.IoFilter.NextFilter;
import org.apache.mina.core.session.IoSession;
/**
* Callback for {@link ProtocolDecoder} to generate decoded messages.
* 协议解码器ProtocolDecoder的回调接口来产生解码后的消息对象
* {@link ProtocolDecoder} must call {@link #write(Object)} for each decoded
* messages.
* 协议解码器ProtocolDecoder必须为每一个解码后的消息对象调用此接口的write(Object)方法
* 将消息输出
*/
public interface ProtocolDecoderOutput {
/**
* Callback for {@link ProtocolDecoder} to generate decoded messages.
* {@link ProtocolDecoder} must call {@link #write(Object)} for each
* decoded messages.
*
* @param message the decoded message
*/
void write(Object message);
/**
* Flushes all messages you wrote via {@link #write(Object)} to
* the next filter.通过write(Object)方法将所有消息立即写到下一个过滤器中
*/
void flush(NextFilter nextFilter, IoSession session);
}
接口 ProtocolDecoderOutput的一个实现
package org.apache.mina.filter.codec;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* A {@link ProtocolDecoderOutput} based on queue.
* 一个基于ConcurrentLinkedQueue并发队列的协议解码输出器
*/
public abstract class AbstractProtocolDecoderOutput implements ProtocolDecoderOutput {
private final Queue<Object> messageQueue = new ConcurrentLinkedQueue<Object>();
public AbstractProtocolDecoderOutput() {
// Do nothing
}
public Queue<Object> getMessageQueue() {
return messageQueue;
}
public void write(Object message) {
if (message == null) {
throw new IllegalArgumentException("message");
}
messageQueue.add(message);
}
}
ProtocolCodecFilter过滤器中提供一个实现,主要是实现了flush方法
/*
*/
package org.apache.mina.filter.codec;
import org.apache.mina.core.filterchain.IoFilter.NextFilter;
import org.apache.mina.core.session.IoSession;
/**
* Callback for {@link ProtocolDecoder} to generate decoded messages.
* 协议解码器ProtocolDecoder的回调接口来产生解码后的消息对象
* {@link ProtocolDecoder} must call {@link #write(Object)} for each decoded
* messages.
* 协议解码器ProtocolDecoder必须为每一个解码后的消息对象调用此接口的write(Object)方法
* 将消息输出
*/
public interface ProtocolDecoderOutput {
/**
* Callback for {@link ProtocolDecoder} to generate decoded messages.
* {@link ProtocolDecoder} must call {@link #write(Object)} for each
* decoded messages.
*
* @param message the decoded message
*/
void write(Object message);
/**
* Flushes all messages you wrote via {@link #write(Object)} to
* the next filter.通过write(Object)方法将所有消息立即写到下一个过滤器中
*/
void flush(NextFilter nextFilter, IoSession session);
}
接口 ProtocolDecoderOutput的一个实现
package org.apache.mina.filter.codec;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* A {@link ProtocolDecoderOutput} based on queue.
* 一个基于ConcurrentLinkedQueue并发队列的协议解码输出器
*/
public abstract class AbstractProtocolDecoderOutput implements ProtocolDecoderOutput {
private final Queue<Object> messageQueue = new ConcurrentLinkedQueue<Object>();
public AbstractProtocolDecoderOutput() {
// Do nothing
}
public Queue<Object> getMessageQueue() {
return messageQueue;
}
public void write(Object message) {
if (message == null) {
throw new IllegalArgumentException("message");
}
messageQueue.add(message);
}
}
ProtocolCodecFilter过滤器中提供一个实现,主要是实现了flush方法
//协议解码器输出的一个实现 private static class ProtocolDecoderOutputImpl extends AbstractProtocolDecoderOutput { public ProtocolDecoderOutputImpl() { // Do nothing } public void flush(NextFilter nextFilter, IoSession session) { Queue<Object> messageQueue = getMessageQueue(); while (!messageQueue.isEmpty()) { nextFilter.messageReceived(session, messageQueue.poll()); } } }
相关文章推荐
- MINA源码分析---协议编码输出接口ProtocolEncoderOutput及其实现
- MINA源码分析---CumulativeProtocolDecoder协议解码器
- MINA源码分析---协议编码解码过滤器ProtocolCodecFilter
- 第二人生的源码分析(六十二)类Easy实现多协议文件传送
- 第二人生的源码分析(六十二)类Easy实现多协议文件传送
- CI框架源码完全分析之核心文件(输出类)Output.php
- Libevent源码分析-----跨平台Reactor接口的实现
- [zz]DEFAULT_KEYS_SHORTCUT 功能的验证 及其 源码实现分析
- java非并发容器ArrayList 和 LinkedList 优缺点比较及其实现源码分析
- MINA源码分析---base64编码和解码
- nginx源码分析之http解码实现
- 蔡军生先生第二人生的源码分析(六十二)类Easy实现多协议文件传送
- DEFAULT_KEYS_SHORTCUT 功能的验证 及其 源码实现分析
- Java多线程---线程池源码分析及其实现
- Redis源码分析(三十三)--- redis-cli.c客户端命令行接口的实现(2)
- (10) java源码分析 ---- HashMap源码分析 及其 实现原理分析
- LwIP 协议栈源码详解 ——TCP/IP 协议的实现(六:网络接口结构)
- Hadoop源码分析笔记(十):数据节点--流式接口的实现
- Mapreduce中的RCFile输出RCFileOutputFormat实现及其应用
- setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT) 功能的验证 及其 源码实现分析