本文整理汇总了Java中io.netty.channel.Channel.flush方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.flush方法的具体用法?Java Channel.flush怎么用?Java Channel.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEvent
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void onEvent(Object[] elements) throws Exception {
BaseMessage msg;
Map<Channel,List<BaseMessage>> msgMap = new ConcurrentHashMap<Channel, List<BaseMessage>>();
for(Object obj:elements){
msg = (BaseMessage) obj;
List<BaseMessage> msgList = msgMap.get(msg.getChannel());
if(msgList == null){
msgList = new LinkedList<BaseMessage>();
msgMap.put(msg.getChannel(),msgList);
}
msgList.add(msg);
}
// Traverse the map
for (Channel keyChannel : msgMap.keySet()) {
if (keyChannel == null) {
logger.error("Channel {} have been destoryed/removed for case of connection been close!", keyChannel);
return;
}
List<BaseMessage> msgList1 = msgMap.get(keyChannel);
if (logger.isTraceEnabled()) {
logger.trace("get channel here::{}", keyChannel);
}
for (BaseMessage msgIns : msgList1) {
keyChannel.write(msgIns, keyChannel.voidPromise());
}
keyChannel.flush();
}
}
示例2: request
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void request(Channel channel) {
List<Object> requests = writeRequests(channel.alloc());
requests.forEach(channel::write);
channel.flush();
}