本文整理汇总了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);
}
}