Search in sources :

Example 1 with Connection

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);
}
Also used : Connection(de.jackwhite20.japs.server.network.Connection) java.util(java.util) ClusterServer(de.jackwhite20.japs.shared.config.ClusterServer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PipelineUtils(de.jackwhite20.japs.shared.pipeline.PipelineUtils) Logger(java.util.logging.Logger) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Level(java.util.logging.Level) ServerChannelInitializer(de.jackwhite20.japs.server.network.initialize.ServerChannelInitializer) TimeUnit(java.util.concurrent.TimeUnit) Config(de.jackwhite20.japs.server.config.Config) Bootstrap(io.netty.bootstrap.Bootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) OpCode(de.jackwhite20.japs.shared.net.OpCode) JSONObject(org.json.JSONObject) ClusterPublisherChannelInitializer(de.jackwhite20.japs.server.network.initialize.ClusterPublisherChannelInitializer) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) io.netty.channel(io.netty.channel) JaPSCache(de.jackwhite20.japs.server.cache.JaPSCache) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) JSONObject(org.json.JSONObject) Connection(de.jackwhite20.japs.server.network.Connection)

Example 2 with Connection

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));
}
Also used : JSONObjectEncoder(de.jackwhite20.japs.shared.pipeline.handler.JSONObjectEncoder) Connection(de.jackwhite20.japs.server.network.Connection) JSONObjectDecoder(de.jackwhite20.japs.shared.pipeline.handler.JSONObjectDecoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelException(io.netty.channel.ChannelException)

Aggregations

Connection (de.jackwhite20.japs.server.network.Connection)2 JaPSCache (de.jackwhite20.japs.server.cache.JaPSCache)1 Config (de.jackwhite20.japs.server.config.Config)1 ClusterPublisherChannelInitializer (de.jackwhite20.japs.server.network.initialize.ClusterPublisherChannelInitializer)1 ServerChannelInitializer (de.jackwhite20.japs.server.network.initialize.ServerChannelInitializer)1 ClusterServer (de.jackwhite20.japs.shared.config.ClusterServer)1 OpCode (de.jackwhite20.japs.shared.net.OpCode)1 PipelineUtils (de.jackwhite20.japs.shared.pipeline.PipelineUtils)1 JSONObjectDecoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectDecoder)1 JSONObjectEncoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectEncoder)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 io.netty.channel (io.netty.channel)1 ChannelException (io.netty.channel.ChannelException)1 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)1 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)1 InetSocketAddress (java.net.InetSocketAddress)1 java.util (java.util)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1