Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HW2 Task manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
diana.alkateeb
HW2 Task manager
Commits
b37132b6
Commit
b37132b6
authored
Apr 27, 2019
by
Wagner Franchin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the way how tasks are created
parent
107fa80d
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
31 additions
and
60 deletions
+31
-60
Dockerfile
Dockerfile
+1
-1
README.md
README.md
+0
-15
TaskExecutor.java
src/singleton/TaskExecutor.java
+23
-20
Task.java
src/task/Task.java
+2
-0
TaskBitcoin.java
src/task/TaskBitcoin.java
+0
-4
TaskBubbleSort.java
src/task/TaskBubbleSort.java
+0
-4
TaskFiboRecursive.java
src/task/TaskFiboRecursive.java
+0
-4
TaskImpl.java
src/task/TaskImpl.java
+5
-4
TaskIncorrectParams.java
src/task/TaskIncorrectParams.java
+0
-4
TaskNotFound.java
src/task/TaskNotFound.java
+0
-4
No files found.
Dockerfile
View file @
b37132b6
...
...
@@ -11,7 +11,7 @@ RUN mkdir -p $WEBPATH
COPY
src/ $WEBPATH
WORKDIR
$WEBPATH
RUN
javac
*
.java
RUN
javac
*
.java
task/
*
.java
EXPOSE
8000
...
...
README.md
View file @
b37132b6
...
...
@@ -37,27 +37,12 @@ import task.TaskImpl;
public class TaskHello extends TaskImpl {
public TaskHello(String input) {
super(input);
}
@Override
public void execute() {
result = "Hello " + input;
}
}
```
*
Change
`singleton/TaskExecutor.java`
by adding a new "case" in the switch-case context for your task.
Example:
```
...
case "TaskHello":
task = new TaskHello(input);
break;
default:
...
```
*
When the project is compiled, up and running, the task can be called like:
`curl -d TaskHello -d World http://localhost:8000/`
...
...
src/singleton/TaskExecutor.java
View file @
b37132b6
...
...
@@ -12,34 +12,23 @@ public enum TaskExecutor {
//Singleton
INSTANCE
;
public
static
final
String
TASKS_PACKAGE
=
"task."
;
public
String
run
(
String
parameters
)
{
Task
task
;
String
taskName
,
input
=
""
;
List
<
String
>
list
=
Arrays
.
stream
(
parameters
.
split
(
"&"
)).
collect
(
Collectors
.
toList
());
long
start
=
System
.
currentTimeMillis
();
if
(
list
.
size
()
!=
2
)
{
task
=
new
TaskIncorrectParams
(
""
)
;
task
Name
=
"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
;
taskName
=
list
.
get
(
0
);
input
=
list
.
get
(
1
);
}
Task
task
=
createTask
(
taskName
);
task
.
setInput
(
input
);
task
.
execute
();
}
TasksList
.
INSTANCE
.
add
(
task
);
long
end
=
System
.
currentTimeMillis
();
...
...
@@ -48,4 +37,18 @@ public enum TaskExecutor {
return
task
.
getResult
();
}
private
Task
createTask
(
String
className
)
{
Task
task
=
null
;
try
{
task
=
(
Task
)
Class
.
forName
(
TASKS_PACKAGE
+
className
).
newInstance
();
}
catch
(
Exception
e
)
{
try
{
task
=
(
Task
)
Class
.
forName
(
TASKS_PACKAGE
+
"TaskNotFound"
).
newInstance
();
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
return
task
;
}
}
src/task/Task.java
View file @
b37132b6
...
...
@@ -4,6 +4,8 @@ public interface Task {
String
getInput
();
void
setInput
(
String
input
);
void
execute
();
void
setExecutedTime
(
String
executedTime
);
...
...
src/task/TaskBitcoin.java
View file @
b37132b6
...
...
@@ -10,10 +10,6 @@ import java.util.List;
public
class
TaskBitcoin
extends
TaskImpl
{
public
TaskBitcoin
(
String
input
)
{
super
(
input
);
}
@Override
public
void
execute
()
{
try
{
...
...
src/task/TaskBubbleSort.java
View file @
b37132b6
...
...
@@ -5,10 +5,6 @@ import java.util.StringJoiner;
public
class
TaskBubbleSort
extends
TaskImpl
{
public
TaskBubbleSort
(
String
input
)
{
super
(
input
);
}
@Override
public
void
execute
()
{
String
[]
stringArray
=
input
.
split
(
","
);
...
...
src/task/TaskFiboRecursive.java
View file @
b37132b6
...
...
@@ -2,10 +2,6 @@ package task;
public
class
TaskFiboRecursive
extends
TaskImpl
{
public
TaskFiboRecursive
(
String
input
)
{
super
(
input
);
}
@Override
public
void
execute
()
{
try
{
...
...
src/task/TaskImpl.java
View file @
b37132b6
...
...
@@ -6,15 +6,16 @@ public abstract class TaskImpl implements Task {
protected
String
result
;
protected
String
executedTime
;
public
TaskImpl
(
String
input
)
{
this
.
input
=
input
;
}
@Override
public
String
getInput
()
{
return
input
;
}
@Override
public
void
setInput
(
String
input
)
{
this
.
input
=
input
;
}
@Override
public
String
getResult
()
{
return
"Result: "
+
result
+
"; Executed in: "
+
executedTime
+
"\n"
;
...
...
src/task/TaskIncorrectParams.java
View file @
b37132b6
...
...
@@ -2,10 +2,6 @@ package task;
public
final
class
TaskIncorrectParams
extends
TaskImpl
{
public
TaskIncorrectParams
(
String
input
)
{
super
(
input
);
}
@Override
public
void
execute
()
{
}
...
...
src/task/TaskNotFound.java
View file @
b37132b6
...
...
@@ -2,10 +2,6 @@ package task;
public
final
class
TaskNotFound
extends
TaskImpl
{
public
TaskNotFound
(
String
input
)
{
super
(
input
);
}
@Override
public
void
execute
()
{
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment