Example usage for io.netty.channel.group ChannelGroup writeAndFlush

List of usage examples for io.netty.channel.group ChannelGroup writeAndFlush

Introduction

In this page you can find the example usage for io.netty.channel.group ChannelGroup writeAndFlush.

Prototype

ChannelGroupFuture writeAndFlush(Object message, ChannelMatcher matcher);

Source Link

Document

Shortcut for calling #write(Object) and #flush() and only act on Channel s that are matched by the ChannelMatcher .

Usage

From source file:com.github.mrstampy.gameboot.netty.NettyConnectionRegistry.java

License:Open Source License

/**
 * Send to group./*  w  w w  . jav a  2s  .c  om*/
 *
 * @param groupName
 *          the group key
 * @param message
 *          the message
 * @param matcher
 *          the matcher
 * @param listeners
 *          the listeners
 */
public void sendToGroup(String groupName, String message, ChannelMatcher matcher,
        ChannelFutureListener... listeners) {
    groupCheck(groupName);
    if (!groups.containsKey(groupName)) {
        log.warn("No group {} to send message {}", groupName, message);
        return;
    }

    ChannelGroup group = groups.get(groupName);

    ChannelFutureListener[] all = utils.prependArray(f -> log((ChannelGroupFuture) f, groupName), listeners);
    ChannelGroupFuture cf = group.writeAndFlush(message, matcher);
    cf.addListeners(all);
}

From source file:com.github.mrstampy.gameboot.netty.NettyConnectionRegistry.java

License:Open Source License

/**
 * Send to group.//  w  w  w  . j  a  v  a  2 s . co m
 *
 * @param groupName
 *          the group key
 * @param message
 *          the message
 * @param matcher
 *          the matcher
 * @param listeners
 *          the listeners
 */
public void sendToGroup(String groupName, byte[] message, ChannelMatcher matcher,
        ChannelFutureListener... listeners) {
    groupCheck(groupName);
    checkMessage(message);

    if (!groups.containsKey(groupName)) {
        log.warn("No group {} to send message {}", groupName, message);
        return;
    }

    ChannelGroup group = groups.get(groupName);

    ChannelFutureListener[] all = utils.prependArray(f -> log((ChannelGroupFuture) f, groupName), listeners);
    ChannelGroupFuture cf = group.writeAndFlush(message, matcher);
    cf.addListeners(all);
}