本文整理匯總了Java中io.netty.channel.Channel.write方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.write方法的具體用法?Java Channel.write怎麽用?Java Channel.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.write方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: catchErr
import io.netty.channel.Channel; //導入方法依賴的package包/類
/**
* 捕獲錯誤並記錄
*
* @param uid
* @param funName
* @param code
* @param e
* @param ch
*/
public static void catchErr(long uid, String funName, Integer code, Exception e, Channel ch) {
logger.error(funName + " ... " + e.toString());
e.printStackTrace();
Response.HeshResMessage.Builder heshResMessage = ProtobufCoreHelper.getHeshResMessage();
heshResMessage.setCode(code);
//如果是用戶發送的信息則推送錯誤信息
if (ch != null) {
ch.write(heshResMessage.build());
}
}
示例2: 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();
}
}
示例3: write
import io.netty.channel.Channel; //導入方法依賴的package包/類
public static void write(Channel channel, List<AmqpDeliverMessage> pendingMessages) {
for (AmqpDeliverMessage message : pendingMessages) {
channel.write(message);
}
}