-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Spectrum
authored and
Spectrum
committed
Oct 25, 2013
1 parent
b70ccc4
commit 3efe0fb
Showing
9 changed files
with
307 additions
and
142 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
jdeeco-core/src/cz/cuni/mff/d3s/deeco/executor/ExecutionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cz.cuni.mff.d3s.deeco.executor; | ||
|
||
import cz.cuni.mff.d3s.deeco.task.Task; | ||
|
||
public interface ExecutionListener { | ||
public void executionCompleted( Task task ); | ||
} |
5 changes: 0 additions & 5 deletions
5
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/IScheduler.java
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/LocalTimeScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
*/ | ||
package cz.cuni.mff.d3s.deeco.scheduler; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
|
||
import cz.cuni.mff.d3s.deeco.executor.Executor; | ||
import cz.cuni.mff.d3s.deeco.task.Task; | ||
|
||
public class LocalTimeScheduler implements Scheduler{ | ||
Map<Task, TaskInfo> tasks; | ||
Executor executor; | ||
private States state; | ||
|
||
private class TaskInfo{ | ||
Timer timer; | ||
States state; | ||
|
||
public TaskInfo(){ | ||
timer = new Timer(); | ||
state = States.STOPPED; | ||
} | ||
} | ||
|
||
private enum States{ | ||
RUNNING, | ||
STOPPED | ||
} | ||
|
||
public LocalTimeScheduler( Executor executor ){ | ||
this.executor = executor; | ||
tasks = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void executionCompleted(Task task) { | ||
tasks.get(task).state = States.STOPPED; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
if( state == States.RUNNING ) | ||
return; | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void stop() { | ||
if( state == States.STOPPED ) | ||
return; | ||
} | ||
|
||
@Override | ||
public void removeTasks( List<Task> tasks ){ | ||
// tasks.removeAll(tasks); | ||
} | ||
|
||
@Override | ||
public void addTasks( List<Task> tasks ){ | ||
|
||
} | ||
|
||
@Override | ||
public void addTask(Task task) { | ||
tasks.put(task, new TaskInfo()); | ||
} | ||
|
||
@Override | ||
public void removeTask(Task task) { | ||
tasks.remove(task); | ||
} | ||
|
||
private void startTask(final Task task) { | ||
TaskInfo ti = tasks.get(task); | ||
ti.timer.scheduleAtFixedRate(new TimerTask() { | ||
|
||
@Override | ||
public void run() { | ||
taskTimerFired(task); | ||
} | ||
}, 0, task.getSchedulingSpecification().getPeriod()); | ||
} | ||
|
||
protected void taskTimerFired(Task task) { | ||
if( tasks.get(task).state == States.RUNNING ){ | ||
// TODO : Implement error reporting | ||
return; | ||
} | ||
|
||
tasks.get(task).state = States.RUNNING; | ||
executor.execute(task); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/Scheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
*/ | ||
package cz.cuni.mff.d3s.deeco.scheduler; | ||
|
||
import java.util.List; | ||
|
||
import cz.cuni.mff.d3s.deeco.executor.ExecutionListener; | ||
import cz.cuni.mff.d3s.deeco.task.Task; | ||
|
||
public interface Scheduler extends ExecutionListener { | ||
public void start(); | ||
public void stop(); | ||
public void addTask( Task task ); | ||
public void addTasks( List<Task> tasks ); | ||
public void removeTask( Task task ); | ||
public void removeTasks( List<Task> tasks ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.