-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
171 lines (138 loc) · 6.53 KB
/
App.java
File metadata and controls
171 lines (138 loc) · 6.53 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package tech.thedumbdev;
import software.amazon.awssdk.regions.Region;
import tech.thedumbdev.data.DataStore;
import tech.thedumbdev.data.ElasticStore;
import tech.thedumbdev.data.FileStore;
import tech.thedumbdev.data.exceptions.ElasticStoreException;
import tech.thedumbdev.enums.Severity;
import tech.thedumbdev.pojo.Log;
import tech.thedumbdev.service.Logger;
import tech.thedumbdev.service.Notify;
import java.util.Scanner;
public class App {
public static void main(String[] args) {
// ============================================================
// Example 1: FileStore without Notification service
// ============================================================
/*
Logger.initLogger(null, null);
Logger instance = Logger.getLogger();
instance.addLog(new Log("FileStore: Log 1", Severity.LOW));
instance.addLog(new Log("FileStore: Log 2", Severity.MEDIUM));
instance.addLog(new Log("FileStore: Log 3", Severity.HIGH));
// This is not necessary, just added this so that we can see a time difference in between logs
try {
Thread.sleep(1000);
} catch (Exception e) {
throw new RuntimeException(e);
}
instance.addLog(new Log("FileStore: Log 4", Severity.CRITICAL));
instance.addLog(new Log("FileStore: Log 5", Severity.WARN));
instance.appendLog();
instance.shutdown();
*/
// ============================================================
// Example 2: FileStore with Notification service
// ============================================================
/*
Scanner sc = new Scanner(System.in);
// Notification service init
System.out.println("Enter Region");
String region = sc.nextLine();
System.out.println("Enter Topic ARN");
String topicARN = sc.nextLine();
System.out.println("Enter Email");
String email = sc.nextLine();
System.out.println("Enter Access Key");
String accessKey = sc.nextLine();
System.out.println("Enter Secret Key");
String secretKey = sc.nextLine();
Notify notify = new Notify(Region.of(region), topicARN, email, accessKey, secretKey);
Logger.initLogger(null, notify);
Logger instance = Logger.getLogger();
instance.addLog(new Log("FileStore with Notify: Log 1", Severity.CRITICAL));
instance.addLog(new Log("FileStore with Notify: Log 2", Severity.HIGH));
instance.addLog(new Log("FileStore with Notify: Log 3", Severity.MEDIUM));
// This is not necessary, just added this so that we can see a time difference in between logs
try {
Thread.sleep(1000);
} catch (Exception e) {
throw new RuntimeException(e);
}
instance.addLog(new Log("FileStore with Notify: Log 4", Severity.LOW));
instance.addLog(new Log("FileStore with Notify: Log 5", Severity.WARN));
instance.appendLog();
instance.shutdown();
*/
// ============================================================
// Example 3: ElasticStore without Notification service
// ============================================================
/*
try {
DataStore dataStore = new ElasticStore("http://localhost:9200", "");
Logger.initLogger(dataStore, null);
} catch (ElasticStoreException e) {
throw new RuntimeException("Failed to create elastic store connection");
}
Logger instance = Logger.getLogger();
instance.addLog(new Log("ElasticStore: Log 1", Severity.WARN));
instance.addLog(new Log("ElasticStore: Log 2", Severity.LOW));
instance.addLog(new Log("ElasticStore: Log 3", Severity.MEDIUM));
// This is not necessary, just added this so that we can see a time difference in between logs
try {
Thread.sleep(1000);
} catch (Exception e) {
throw new RuntimeException(e);
}
instance.addLog(new Log("ElasticStore: Log 4", Severity.HIGH));
instance.addLog(new Log("ElasticStore: Log 5", Severity.CRITICAL));
instance.appendLog();
instance.shutdown();
*/
// ============================================================
// Example 4: ElasticStore with Notification service
// ============================================================
/*
Scanner sc = new Scanner(System.in);
// Notification service init
System.out.println("Enter Region");
String region = sc.nextLine();
System.out.println("Enter Topic ARN");
String topicARN = sc.nextLine();
System.out.println("Enter Email");
String email = sc.nextLine();
System.out.println("Enter Access Key");
String accessKey = sc.nextLine();
System.out.println("Enter Secret Key");
String secretKey = sc.nextLine();
Notify notify = new Notify(Region.of(region), topicARN, email, accessKey, secretKey);
try {
DataStore dataStore = new ElasticStore("http://localhost:9200", "");
Logger.initLogger(dataStore, notify);
} catch (ElasticStoreException e) {
throw new RuntimeException("Failed to create elastic store connection");
}
Logger instance = Logger.getLogger();
instance.addLog(new Log("ElasticStore with Notify: Log 1", Severity.CRITICAL));
instance.addLog(new Log("ElasticStore with Notify: Log 2", Severity.HIGH));
instance.addLog(new Log("ElasticStore with Notify: Log 3", Severity.MEDIUM));
// This is not necessary, just added this so that we can see a time difference in between logs
try {
Thread.sleep(1000);
} catch (Exception e) {
throw new RuntimeException(e);
}
instance.addLog(new Log("ElasticStore with Notify: Log 4", Severity.LOW));
instance.addLog(new Log("ElasticStore with Notify: Log 5", Severity.WARN));
instance.appendLog();
instance.shutdown();
*/
// ---------------------------------------------------------------------
// NOTE:
// - All four examples are intentionally commented out. Uncomment the block
// you want to run (only one at a time is recommended for demos).
// - Replace placeholder AWS credentials / ARNs / endpoints with real values
// before enabling notification-enabled examples.
// ---------------------------------------------------------------------
}
}