Java Code Examples for io.netty.channel.Channel.write()

The following are Jave code examples for showing how to use write() of the io.netty.channel.Channel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: wecard-server   File: NException.java   Source Code and License Vote up 5 votes
/**
 * 捕获错误并记录
 *
 * @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());
    }
}
 
Example 2
Project: jsf-sdk   File: RingBufferHolder.java   Source Code and License Vote up 5 votes
@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();
    }

}
 
Example 3
Project: message-broker   File: AmqpMessageWriter.java   Source Code and License Vote up 4 votes
public static void write(Channel channel, List<AmqpDeliverMessage> pendingMessages) {
    for (AmqpDeliverMessage message : pendingMessages) {
        channel.write(message);
    }
}