-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.java
More file actions
55 lines (47 loc) · 1.95 KB
/
Copy pathApplication.java
File metadata and controls
55 lines (47 loc) · 1.95 KB
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
51
52
53
54
55
public class Application {
public static void main(String[] args) {
// Print args (like fmt.Println(os.Args))
System.out.println(java.util.Arrays.toString(args));
if (args.length < 1) {
System.out.println("Usage: java Application <server|producer> [port]");
return;
}
if ("broker".equals(args[0])) {
Broker broker = new Broker();
try {
broker.startBrokerServer();
} catch (Exception e) {
System.out.printf("Error starting broker: %s%n", e.getMessage());
}
} else if ("producer".equals(args[0])) {
System.out.println("Trying to start producer processes");
if (args.length < 2) {
System.out.println("Missing port argument");
return;
}
try {
int port = Integer.parseInt(args[1]);
int topicId = Integer.parseInt(args[2]);
Producer producer = new Producer(port, topicId);
producer.startProducerServer();
} catch (NumberFormatException e) {
System.out.println("Invalid port: " + args[1]);
}
} else if ("consumer".equals(args[0])) {
System.out.println("Trying to start consumer processes");
if (args.length < 2) {
System.out.println("Missing port argument");
return;
}
try {
int port = Integer.parseInt(args[1]);
int topicId = Integer.parseInt(args[2]);
int groupId = Integer.parseInt(args[3]);
Consumer consumer = new Consumer(port, topicId, groupId);
consumer.startConsumerServer();
} catch (NumberFormatException e) {
System.out.println("Invalid port: " + args[1]);
}
}
}
}