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:
wfranchi@computer:~$ curl -d TaskHello -d World http://localhost:8000
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
### 1. Download the project
......@@ -78,12 +82,12 @@ cd task-webserver-docker
$ docker build -t taskwebserver:1.0 .
```
### 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
```
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
```
......
......@@ -13,28 +13,33 @@ public enum TaskExecutor {
INSTANCE;
public String run(String parameters) {
Task task;
List<String> list = Arrays.stream(parameters.split("&")).collect(Collectors.toList());
String taskName = list.get(0);
String input = list.get(1);
long start = System.currentTimeMillis();
Task task;
switch (taskName) {
case "TaskBubbleSort":
task = new TaskBubbleSort(input);
break;
case "TaskFiboRecursive":
task = new TaskFiboRecursive(input);
break;
case "TaskBitcoin":
task = new TaskBitcoin(input);
break;
default:
task = new NoTask("");
break;
if (list.size() != 2) {
task = new TaskIncorrectParams("");
} else {
String taskName = list.get(0);
String input = list.get(1);
switch (taskName) {
case "TaskBubbleSort":
task = new TaskBubbleSort(input);
break;
case "TaskFiboRecursive":
task = new TaskFiboRecursive(input);
break;
case "TaskBitcoin":
task = new TaskBitcoin(input);
break;
default:
task = new TaskNotFound("");
break;
}
task.execute();
}
task.execute();
TasksList.INSTANCE.add(task);
long end = System.currentTimeMillis();
......
......@@ -16,9 +16,12 @@ public class TaskBitcoin extends TaskImpl {
@Override
public void execute() {
String[] stringArray = input.split(",");
int times = Integer.valueOf(stringArray[0]);
result = getInfo(times);
try {
int times = Integer.valueOf(input);
result = getInfo(times);
} catch (Exception e) {
result = "Exception: " + e.getMessage();
}
}
public String getInfo(int times) {
......
......@@ -8,10 +8,12 @@ public class TaskFiboRecursive extends TaskImpl {
@Override
public void execute() {
String[] stringArray = input.split(",");
// just one number is expected
int n = Integer.valueOf(stringArray[0]);
result = String.valueOf(fibonacci(n));
try {
int n = Integer.valueOf(input);
result = String.valueOf(fibonacci(n));
} catch (Exception e) {
result = "Exception: " + e.getMessage();
}
}
/**
......
package task;
public class NoTask extends TaskImpl {
public final class TaskNotFound extends TaskImpl {
public NoTask(String input) {
public TaskNotFound(String input) {
super(input);
}
......@@ -11,6 +11,6 @@ public class NoTask extends TaskImpl {
@Override
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