8
8
import lombok .extern .slf4j .Slf4j ;
9
9
import org .apache .commons .cli .*;
10
10
11
+ /**
12
+ * This class is the CLI Client implementation for communications with the server.
13
+ * It extends the abstract {@see Client} class and parses command line parameters.
14
+ */
11
15
@ Slf4j
12
16
public class CommandLineClient extends Client {
13
17
@@ -59,6 +63,12 @@ public class CommandLineClient extends Client {
59
63
.build ());
60
64
}
61
65
66
+ /**
67
+ * Parse the passed command line arguments to create a RPC request with the SamplingMessageGrpcService.
68
+ * In case a mandatory argument is missing, the program shuts down with an error message.
69
+ *
70
+ * @param args Command line arguments passed to the JAR call
71
+ */
62
72
public void run (String [] args ) {
63
73
CommandLineParser commandLineParser = new DefaultParser ();
64
74
helpFormatter = new HelpFormatter ();
@@ -78,7 +88,6 @@ public void run(String[] args) {
78
88
79
89
ManagedChannelBuilder <?> managedChannelBuilder = ManagedChannelBuilder .forAddress (address , port ).usePlaintext ();
80
90
ManagedChannel managedChannel = managedChannelBuilder .build ();
81
- SamplingMessageGrpc .SamplingMessageStub samplingMessageStub = SamplingMessageGrpc .newStub (managedChannel );
82
91
SamplingMessageGrpc .SamplingMessageBlockingStub samplingMessageBlockingStub = SamplingMessageGrpc .newBlockingStub (managedChannel );
83
92
84
93
if (method == 0 ) {
@@ -100,6 +109,19 @@ public void run(String[] args) {
100
109
managedChannel .shutdown ();
101
110
}
102
111
112
+ /**
113
+ * Create an empty sampling message.
114
+ *
115
+ * Expected arguments are:
116
+ * -d for the duration the message should be valid
117
+ * -n for the name the message should bare
118
+ *
119
+ * If the message name is already in use, an error is returned by the server with the status code CONFLICT.
120
+ * A successful request returns a status code SUCCESS.
121
+ *
122
+ * @param commandLine CommandLine Object for argument extraction
123
+ * @param samplingMessageBlockingStub The message stub that executes the sampling message request
124
+ */
103
125
private void createSamplingMessage (CommandLine commandLine , SamplingMessageGrpc .SamplingMessageBlockingStub samplingMessageBlockingStub ) {
104
126
String name = commandLine .getOptionValue ("name" );
105
127
long duration ;
@@ -123,6 +145,19 @@ private void createSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.
123
145
log .info ("createSamplingMessageResponse Status Code: " + response .getStatusCode ().name ());
124
146
}
125
147
148
+ /**
149
+ * Write an existing sampling message.
150
+ *
151
+ * Expected arguments are:
152
+ * -d for the duration the message should be valid
153
+ * -c for the content of the message
154
+ * -n for the name the message should bare
155
+ *
156
+ * If the message name is unknown the server returns a status code NOT_FOUND and SUCCESS otherwise.
157
+ *
158
+ * @param commandLine CommandLine Object for argument extraction
159
+ * @param samplingMessageBlockingStub The message stub that executes the sampling message request
160
+ */
126
161
private void writeSamplingMessage (CommandLine commandLine , SamplingMessageGrpc .SamplingMessageBlockingStub samplingMessageBlockingStub ) {
127
162
String name = commandLine .getOptionValue ("name" );
128
163
String content = commandLine .getOptionValue ("content" );
@@ -142,6 +177,17 @@ private void writeSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.S
142
177
log .info ("writeSamplingMessageResponse Status Code: " + response .getStatusCode ().name ());
143
178
}
144
179
180
+ /**
181
+ * Clear an existing sampling message of its content. The message is also invalidated.
182
+ *
183
+ * Expected arguments are:
184
+ * -n for the name of the message to be cleared
185
+ *
186
+ * If the message name is unknown the server returns a status code NOT_FOUND and SUCCESS otherwise.
187
+ *
188
+ * @param commandLine CommandLine Object for argument extraction
189
+ * @param samplingMessageBlockingStub The message stub that executes the sampling message request
190
+ */
145
191
private void clearSamplingMessage (CommandLine commandLine , SamplingMessageGrpc .SamplingMessageBlockingStub samplingMessageBlockingStub ) {
146
192
String name = commandLine .getOptionValue ("name" );
147
193
SamplingMessageGrpcService .ClearSamplingMessageRequest request =
@@ -154,6 +200,17 @@ private void clearSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.S
154
200
log .info ("writeSamplingMessageResponse Status Code: " + response .getStatusCode ().name ());
155
201
}
156
202
203
+ /**
204
+ * Read an existing sampling message.
205
+ *
206
+ * Expected arguments are:
207
+ * -n for the name of the message to be read
208
+ *
209
+ * If the message name is unknown the server returns a status code NOT_FOUND and SUCCESS otherwise.
210
+ *
211
+ * @param commandLine CommandLine Object for argument extraction
212
+ * @param samplingMessageBlockingStub The message stub that executes the sampling message request
213
+ */
157
214
private void readSamplingMessage (CommandLine commandLine , SamplingMessageGrpc .SamplingMessageBlockingStub samplingMessageBlockingStub ) {
158
215
String name = commandLine .getOptionValue ("name" );
159
216
@@ -169,6 +226,12 @@ private void readSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.Sa
169
226
log .info ("readSamplingMessageResponse Valid: " + response .getMessageIsValid ());
170
227
}
171
228
229
+ /**
230
+ * Read the current status of an existing sampling message.
231
+ *
232
+ * @param commandLine CommandLine Object for argument extraction
233
+ * @param samplingMessageBlockingStub The message stub that executes the sampling message request
234
+ */
172
235
private void getSamplingMessageStatus (CommandLine commandLine , SamplingMessageGrpc .SamplingMessageBlockingStub samplingMessageBlockingStub ) {
173
236
String name = commandLine .getOptionValue ("name" );
174
237
@@ -182,6 +245,17 @@ private void getSamplingMessageStatus(CommandLine commandLine, SamplingMessageGr
182
245
log .info ("getSamplingMessageStatusResponse Status Code: " + response .getStatusCode ().name ());
183
246
}
184
247
248
+ /**
249
+ * Delete an existing sampling message, permanently removing it from the server storage.
250
+ *
251
+ * Expected arguments are:
252
+ * -n for the name of the message to be deleted
253
+ *
254
+ * If the message name is unknown the server returns a status code NOT_FOUND and SUCCESS otherwise.
255
+ *
256
+ * @param commandLine CommandLine Object for argument extraction
257
+ * @param samplingMessageBlockingStub The message stub that executes the sampling message request
258
+ */
185
259
private void deleteSamplingMessage (CommandLine commandLine , SamplingMessageGrpc .SamplingMessageBlockingStub samplingMessageBlockingStub ) {
186
260
String name = commandLine .getOptionValue ("name" );
187
261
@@ -196,7 +270,11 @@ private void deleteSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.
196
270
}
197
271
198
272
199
-
273
+ /**
274
+ * Prints an error message before exiting the program with an error exit code of 1.
275
+ *
276
+ * @param errorMessage Message to be displayed on the console during the program shutdown
277
+ */
200
278
private void exitWithError (String errorMessage ) {
201
279
log .debug ("ParsingError: " , errorMessage );
202
280
log .error (errorMessage );
0 commit comments