Java 类io.netty.channel.group.ChannelMatcher 实例源码

项目:gameboot    文件:NettyConnectionRegistry.java   
/**
 * Send to group.
 *
 * @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);
}
项目:gameboot    文件:NettyConnectionRegistry.java   
private ChannelMatcher createMatcher(SystemIdKey... except) {
  if (except == null || except.length == 0) return NOOP_MATCHER;

  List<Channel> exceptions = new ArrayList<>();
  for (SystemIdKey key : except) {
    Channel c = get(key);
    if (c != null) exceptions.add(c);
  }

  return exceptions.isEmpty() ? NOOP_MATCHER : new ChannelMatcher() {

    @Override
    public boolean matches(Channel channel) {
      return !exceptions.contains(channel);
    }
  };
}
项目:gameboot    文件:NettyConnectionRegistry.java   
/**
 * Send to group.
 *
 * @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);
}
项目:SynchronizeFX    文件:NettyBasicServer.java   
@Override
public void sendToAllExcept(final List<Command> commands, final Object nonReciver) {
    clients.writeAndFlush(commands, new ChannelMatcher() {
        @Override
        public boolean matches(final Channel candidate) {
            return candidate != nonReciver;
        }
    });
}
项目:gameboot    文件:NettyConnectionRegistry.java   
/**
 * Send to group.
 *
 * @param groupName
 *          the group name
 * @param message
 *          the message
 * @param except
 *          the except
 */
public void sendToGroup(String groupName, byte[] message, SystemIdKey... except) {
  if (!containsGroup(groupName)) return;

  ChannelMatcher exceptions = createMatcher(except);

  sendToGroup(groupName, message, exceptions);
}
项目:gameboot    文件:NettyConnectionRegistry.java   
/**
 * Send to group.
 *
 * @param groupName
 *          the group name
 * @param message
 *          the message
 * @param except
 *          the except
 */
public void sendToGroup(String groupName, String message, SystemIdKey... except) {
  if (!containsGroup(groupName)) return;

  ChannelMatcher exceptions = createMatcher(except);

  sendToGroup(groupName, message, exceptions);
}
项目:gameboot    文件:NettyConnectionRegistry.java   
/**
 * Send to all.
 *
 * @param message
 *          the message
 * @param matcher
 *          the matcher
 * @param listeners
 *          the listeners
 */
public void sendToAll(String message, ChannelMatcher matcher, ChannelFutureListener... listeners) {
  sendToGroup(ALL, message, matcher, listeners);
}
项目:gameboot    文件:NettyConnectionRegistry.java   
/**
 * Send to all.
 *
 * @param message
 *          the message
 * @param matcher
 *          the matcher
 * @param listeners
 *          the listeners
 */
public void sendToAll(byte[] message, ChannelMatcher matcher, ChannelFutureListener... listeners) {
  sendToGroup(ALL, message, matcher, listeners);
}