Skip to content

Commit bb488aa

Browse files
Create JavaDoc for the CommandLineClient
1 parent 8a2b35f commit bb488aa

File tree

2 files changed

+89
-10
lines changed

2 files changed

+89
-10
lines changed

client_test.bat

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
@echo off
22

3-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -d 2 -c bla -p 8080 -a 127.0.0.1 -m 0
4-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -d 2 -c bla -p 8080 -a 127.0.0.1 -m 1
5-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -d 2 -c bla -p 8080 -a 127.0.0.1 -m 3
3+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 0 -n Test -d 2
4+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 1 -n Test -d 2 -c bla
5+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 3 -n Test -d 2
66
:: Create duplicate message
7-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -d 2 -c bla -p 8080 -a 127.0.0.1 -m 0
7+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 0 -n Test -d 2
88

99

10-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -p 8080 -a 127.0.0.1 -m 3
10+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 3 -n Test
11+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 3 -n Moron
1112

1213
:: Clear message and read the content
13-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -p 8080 -a 127.0.0.1 -m 2
14-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -p 8080 -a 127.0.0.1 -m 3
14+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 2 -n Test
15+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 3 -n Test
1516

1617

17-
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -n Test -p 8080 -a 127.0.0.1 -m 5
18+
java -jar sampling-message-client/target/sampling-message-client-0.1-jar-with-dependencies.jar -p 8080 -a 127.0.0.1 -m 5 -n Test

sampling-message-client/src/main/java/de/dhbw/ravensburg/verteiltesysteme/client/CommandLineClient.java

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import lombok.extern.slf4j.Slf4j;
99
import org.apache.commons.cli.*;
1010

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+
*/
1115
@Slf4j
1216
public class CommandLineClient extends Client {
1317

@@ -59,6 +63,12 @@ public class CommandLineClient extends Client {
5963
.build());
6064
}
6165

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+
*/
6272
public void run(String[] args) {
6373
CommandLineParser commandLineParser = new DefaultParser();
6474
helpFormatter = new HelpFormatter();
@@ -78,7 +88,6 @@ public void run(String[] args) {
7888

7989
ManagedChannelBuilder<?> managedChannelBuilder = ManagedChannelBuilder.forAddress(address, port).usePlaintext();
8090
ManagedChannel managedChannel = managedChannelBuilder.build();
81-
SamplingMessageGrpc.SamplingMessageStub samplingMessageStub = SamplingMessageGrpc.newStub(managedChannel);
8291
SamplingMessageGrpc.SamplingMessageBlockingStub samplingMessageBlockingStub = SamplingMessageGrpc.newBlockingStub(managedChannel);
8392

8493
if (method == 0) {
@@ -100,6 +109,19 @@ public void run(String[] args) {
100109
managedChannel.shutdown();
101110
}
102111

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+
*/
103125
private void createSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.SamplingMessageBlockingStub samplingMessageBlockingStub) {
104126
String name = commandLine.getOptionValue("name");
105127
long duration;
@@ -123,6 +145,19 @@ private void createSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.
123145
log.info("createSamplingMessageResponse Status Code: " + response.getStatusCode().name());
124146
}
125147

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+
*/
126161
private void writeSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.SamplingMessageBlockingStub samplingMessageBlockingStub) {
127162
String name = commandLine.getOptionValue("name");
128163
String content = commandLine.getOptionValue("content");
@@ -142,6 +177,17 @@ private void writeSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.S
142177
log.info("writeSamplingMessageResponse Status Code: " + response.getStatusCode().name());
143178
}
144179

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+
*/
145191
private void clearSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.SamplingMessageBlockingStub samplingMessageBlockingStub) {
146192
String name = commandLine.getOptionValue("name");
147193
SamplingMessageGrpcService.ClearSamplingMessageRequest request =
@@ -154,6 +200,17 @@ private void clearSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.S
154200
log.info("writeSamplingMessageResponse Status Code: " + response.getStatusCode().name());
155201
}
156202

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+
*/
157214
private void readSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.SamplingMessageBlockingStub samplingMessageBlockingStub) {
158215
String name = commandLine.getOptionValue("name");
159216

@@ -169,6 +226,12 @@ private void readSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.Sa
169226
log.info("readSamplingMessageResponse Valid: " + response.getMessageIsValid());
170227
}
171228

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+
*/
172235
private void getSamplingMessageStatus(CommandLine commandLine, SamplingMessageGrpc.SamplingMessageBlockingStub samplingMessageBlockingStub) {
173236
String name = commandLine.getOptionValue("name");
174237

@@ -182,6 +245,17 @@ private void getSamplingMessageStatus(CommandLine commandLine, SamplingMessageGr
182245
log.info("getSamplingMessageStatusResponse Status Code: " + response.getStatusCode().name());
183246
}
184247

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+
*/
185259
private void deleteSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.SamplingMessageBlockingStub samplingMessageBlockingStub) {
186260
String name = commandLine.getOptionValue("name");
187261

@@ -196,7 +270,11 @@ private void deleteSamplingMessage(CommandLine commandLine, SamplingMessageGrpc.
196270
}
197271

198272

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+
*/
200278
private void exitWithError(String errorMessage) {
201279
log.debug("ParsingError: ", errorMessage);
202280
log.error(errorMessage);

0 commit comments

Comments
 (0)