/** * 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); }
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); } }; }
/** * 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); }
@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; } }); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }