-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatClusterUplink.java
41 lines (34 loc) · 1.25 KB
/
ChatClusterUplink.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
package server;
import com.alibaba.fastjson.JSONObject;
import sirius.biz.cluster.Interconnect;
import sirius.biz.cluster.InterconnectHandler;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Register;
import javax.annotation.Nonnull;
/**
* Publishes/subscribes messages using {@link Interconnect} to/from other nodes in the cluster
* Hint: Redis is being used as the "database" here!
*/
@Register(classes = {InterconnectHandler.class})
public class ChatClusterUplink implements InterconnectHandler {
@Part
private static Interconnect interconnect;
@Override
public void handleEvent(JSONObject event) {
// TODO CHALLENGE-3 propagate the event as JSON to all available sessions in ChatSessionRegistry
// TODO right now you definitely know how to grab ChatSessionRegistry :-)
// TODO Hint! this code looks familiar? Explains why you might get messages in double ;-)
}
/**
* Publishes a message identified as "sirius-chat" to other subscribers
* @param message message to send
*/
public void broadcastMessage(ChatMessage message) {
interconnect.dispatch(getName(), message.toJSON());
}
@Nonnull
@Override
public String getName() {
return "sirius-chat";
}
}