本文整理匯總了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();
}