-
Notifications
You must be signed in to change notification settings - Fork 0
/
MOMLog.java
50 lines (36 loc) · 1.59 KB
/
MOMLog.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
42
43
44
45
46
47
48
49
50
import exceptions.EMomError;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class MOMLog implements TopicListenerInterface {
private static String HOST = "localhost";
public static void main(String[] args) throws RemoteException, NotBoundException, EMomError {
System.out.println("Starting MOM Log...");
if (args.length > 0) {
HOST = args[0];
}
MsgQ_Init();
System.out.println("MOM Log up and listening to system events ✓\n");
System.out.println(" ↓ [Log System] ↓ ");
}
private static void MsgQ_Init() throws RemoteException, NotBoundException, EMomError {
// Get the RMI registry
Registry registry = LocateRegistry.getRegistry(HOST);
// Look up the remote object
MOM mom = (MOM) registry.lookup("MOM");
System.out.println("MOM server found");
System.out.println("Creating listener and subscribing to Log topic...");
// Create a listener and subscribe to the Log topic
MOMLog log = new MOMLog();
TopicListenerInterface logStub = (TopicListenerInterface) UnicastRemoteObject.exportObject(log, 0);
mom.MsgQ_Subscribe("Log", logStub);
}
@Override
public void onTopicMessage(String topicName, Message message) throws RemoteException {
System.out.println(topicName + ": " + message.getMessage());
}
@Override
public void onTopicClosed(String topicName) throws RemoteException {}
}