blob: 8c470a1291c0abb52d0382b12a6177f4b7577ce7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package moe.ymc.acron.s2c;
import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
import moe.ymc.acron.serialization.Serializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
public class EventQueue {
private static final Logger LOGGER = LogManager.getLogger();
private static final ChannelGroup sMessageRecipients =
new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
public static void registerMessageRecipient(@NotNull Channel channel) {
sMessageRecipients.add(channel);
}
public static void enqueue(@NotNull Event message) {
LOGGER.debug("Enqueue: {} ({} channels)",
message,
sMessageRecipients.size());
sMessageRecipients.writeAndFlush(Serializer.serialize(message));
}
}
|