summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/client/ResponderClientCLI.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/derms/client/ResponderClientCLI.java')
-rw-r--r--src/main/java/derms/client/ResponderClientCLI.java101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/main/java/derms/client/ResponderClientCLI.java b/src/main/java/derms/client/ResponderClientCLI.java
deleted file mode 100644
index 42541b4..0000000
--- a/src/main/java/derms/client/ResponderClientCLI.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package derms.client;
-
-import java.net.MalformedURLException;
-
-public class ResponderClientCLI extends CLI {
- public static final String usage = "Usage: java derms.client.ResponderClientCLI <FE host>";
-
- private final ResponderClient client;
-
- private ResponderClientCLI(String FEhost) throws MalformedURLException {
- client = new ResponderClient(FEhost);
-
- commands.put("add", new Add());
- cmdDescriptions.add(new Description(
- "add <resource ID> <resource type> <duration>",
- "Add ad resource to the server"));
-
- commands.put("remove", new Remove());
- cmdDescriptions.add(new Description(
- "remove <resource ID> <duration>",
- "Decrease the duration of a resource. If duration is negative, the resource is removed entirely."));
-
- commands.put("list", new List());
- cmdDescriptions.add(new Description(
- "list <resource name>",
- "List available resources"));
- }
-
- public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println("Missing argument 'FE host'");
- System.exit(1);
- }
-
- String FEhost = args[0];
-
- try {
- (new ResponderClientCLI(FEhost)).run();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
-
- private class Add implements Command {
- @Override
- public void exec(String[] args) {
- if (args.length < 3)
- System.out.println("invalid arguments for 'add'");
- else
- add(args[0], args[1], args[2]);
- }
-
- private void add(String resourceID, String resourceName, String durationStr) {
- try {
- int duration = Integer.parseInt(durationStr);
- if (duration < 0) {
- throw new NumberFormatException("duration less than 0");
- }
- String response = client.addResource(resourceID, resourceName, duration);
- System.out.println(response);
- } catch (NumberFormatException e) {
- System.out.println("invalid duration: " + durationStr);
- }
- }
- }
-
- private class Remove implements Command {
- @Override
- public void exec(String[] args) {
- if (args.length < 2)
- System.out.println("invalid arguments for 'remove'");
- else
- remove(args[0], args[1]);
- }
-
- private void remove(String resourceID, String durationStr) {
- try {
- int duration = Integer.parseInt(durationStr);
- String response = client.removeResource(resourceID, duration);
- System.out.println(response);
- } catch (NumberFormatException e) {
- System.out.println("invalid duration: " + durationStr);
- }
- }
- }
-
- private class List implements Command {
- @Override
- public void exec(String[] args) {
- if (args.length < 1)
- System.out.println("invalid arguments for 'list'");
- else
- list(args[0]);
- }
-
- private void list(String resourceName) {
- String response = client.listResourceAvailability(resourceName);
- System.out.println(response);
- }
- }
-}