Commit 5b7d4e2f authored by Wagner Franchin's avatar Wagner Franchin

Improved the code and updated the README.md

parent bccc6ece
...@@ -66,6 +66,10 @@ Something like this should be expected as output: ...@@ -66,6 +66,10 @@ Something like this should be expected as output:
wfranchi@computer:~$ curl -d TaskHello -d World http://localhost:8000 wfranchi@computer:~$ curl -d TaskHello -d World http://localhost:8000
Result: Hello World; Executed in: 0,00s Result: Hello World; Executed in: 0,00s
``` ```
Just two parameters are allowed: `-d <task name> -d <parameter values>`.
If you want to pass more parameter values one suggestion is to use key delimiter like comma `,`.
## Running the web servers in Docker containers ## Running the web servers in Docker containers
### 1. Download the project ### 1. Download the project
...@@ -78,12 +82,12 @@ cd task-webserver-docker ...@@ -78,12 +82,12 @@ cd task-webserver-docker
$ docker build -t taskwebserver:1.0 . $ docker build -t taskwebserver:1.0 .
``` ```
### 3. Running the web servers in different containers ### 3. Running the web servers in different containers
Let's start the `WebServerSocket` container that can be accessed through the port `8000`: Let's two containers. First start the `WebServerSocket` container that can be accessed through the port `8000`:
``` ```
$ docker run -d --rm --name webserversocket -e WEBSERVER=WebServerSocket -p 8000:8000 taskwebserver:1.0 $ docker run -d --rm --name webserversocket -e WEBSERVER=WebServerSocket -p 8000:8000 taskwebserver:1.0
``` ```
Let's start the `WebServerHttp` container that can be accessed through the port `8001`: And then start the `WebServerHttp` container that can be accessed through the port `8001`:
``` ```
$ docker run -d --rm --name webserverhttp -e WEBSERVER=WebServerHttp -p 8001:8000 taskwebserver:1.0 $ docker run -d --rm --name webserverhttp -e WEBSERVER=WebServerHttp -p 8001:8000 taskwebserver:1.0
``` ```
......
...@@ -13,28 +13,33 @@ public enum TaskExecutor { ...@@ -13,28 +13,33 @@ public enum TaskExecutor {
INSTANCE; INSTANCE;
public String run(String parameters) { public String run(String parameters) {
Task task;
List<String> list = Arrays.stream(parameters.split("&")).collect(Collectors.toList()); List<String> list = Arrays.stream(parameters.split("&")).collect(Collectors.toList());
String taskName = list.get(0);
String input = list.get(1);
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Task task; if (list.size() != 2) {
switch (taskName) { task = new TaskIncorrectParams("");
case "TaskBubbleSort": } else {
task = new TaskBubbleSort(input); String taskName = list.get(0);
break; String input = list.get(1);
case "TaskFiboRecursive":
task = new TaskFiboRecursive(input); switch (taskName) {
break; case "TaskBubbleSort":
case "TaskBitcoin": task = new TaskBubbleSort(input);
task = new TaskBitcoin(input); break;
break; case "TaskFiboRecursive":
default: task = new TaskFiboRecursive(input);
task = new NoTask(""); break;
break; case "TaskBitcoin":
task = new TaskBitcoin(input);
break;
default:
task = new TaskNotFound("");
break;
}
task.execute();
} }
task.execute();
TasksList.INSTANCE.add(task); TasksList.INSTANCE.add(task);
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
......
...@@ -16,9 +16,12 @@ public class TaskBitcoin extends TaskImpl { ...@@ -16,9 +16,12 @@ public class TaskBitcoin extends TaskImpl {
@Override @Override
public void execute() { public void execute() {
String[] stringArray = input.split(","); try {
int times = Integer.valueOf(stringArray[0]); int times = Integer.valueOf(input);
result = getInfo(times); result = getInfo(times);
} catch (Exception e) {
result = "Exception: " + e.getMessage();
}
} }
public String getInfo(int times) { public String getInfo(int times) {
......
...@@ -8,10 +8,12 @@ public class TaskFiboRecursive extends TaskImpl { ...@@ -8,10 +8,12 @@ public class TaskFiboRecursive extends TaskImpl {
@Override @Override
public void execute() { public void execute() {
String[] stringArray = input.split(","); try {
// just one number is expected int n = Integer.valueOf(input);
int n = Integer.valueOf(stringArray[0]); result = String.valueOf(fibonacci(n));
result = String.valueOf(fibonacci(n)); } catch (Exception e) {
result = "Exception: " + e.getMessage();
}
} }
/** /**
......
package task; package task;
public class NoTask extends TaskImpl { public final class TaskNotFound extends TaskImpl {
public NoTask(String input) { public TaskNotFound(String input) {
super(input); super(input);
} }
...@@ -11,6 +11,6 @@ public class NoTask extends TaskImpl { ...@@ -11,6 +11,6 @@ public class NoTask extends TaskImpl {
@Override @Override
public String getResult() { public String getResult() {
return "This task doesn't exist.\n"; return "ERROR: This task doesn't exist.\n";
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment