use of de.jackwhite20.japs.server.network.Connection in project JaPS by JackWhite20.
the class JaPSServer method broadcastTo.
public void broadcastTo(Connection con, String channel, JSONObject data, String subscriberName) {
JSONObject clusterData = new JSONObject(data.toMap());
if (channelSessions.containsKey(channel)) {
// Remove the subscriber name to save bandwidth and remove the unneeded key
data.remove("su");
// Find the subscribers with that name and route it to these
for (Connection filteredConnection : channelSessions.get(channel).stream().filter(connection -> connection.name().equals(subscriberName)).collect(Collectors.toList())) {
filteredConnection.send(data);
}
}
// Broadcast it to the cluster if possible
clusterPubSubBroadcast(con, channel, clusterData);
}
use of de.jackwhite20.japs.server.network.Connection in project JaPS by JackWhite20.
the class ServerChannelInitializer method initChannel.
@Override
protected void initChannel(Channel channel) throws Exception {
try {
channel.config().setOption(ChannelOption.IP_TOS, 0x18);
} catch (ChannelException e) {
// Not supported
}
channel.config().setAllocator(PooledByteBufAllocator.DEFAULT);
channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
channel.pipeline().addLast(new JSONObjectDecoder());
channel.pipeline().addLast(new LengthFieldPrepender(4));
channel.pipeline().addLast(new JSONObjectEncoder());
channel.pipeline().addLast(new Connection(jaPSServer, channel));
}
Aggregations