Skip to content

Commit

Permalink
Triggers added
Browse files Browse the repository at this point in the history
  • Loading branch information
andranikm committed Oct 25, 2013
1 parent 1a8fec3 commit 3c6c6ee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


import cz.cuni.mff.d3s.deeco.executor.Executor;
import cz.cuni.mff.d3s.deeco.model.runtime.api.Trigger;
import cz.cuni.mff.d3s.deeco.task.Task;
import cz.cuni.mff.d3s.deeco.task.TriggerListener;

public class LocalTimeScheduler implements Scheduler{
Map<Task, TaskInfo> tasks;
Expand Down Expand Up @@ -100,10 +102,15 @@ public synchronized void removeTask(Task task) {

private void startTask(final Task task) {
TaskInfo ti = tasks.get(task);
// task.registerTriggers({
// ...}
// )
ti.timer. scheduleAtFixedRate(new TimerTask() {
task.registerTriggers(new TriggerListener() {

@Override
public void triggered(Trigger trigger) {
taskTriggerFired(task);
}
});

ti.timer.scheduleAtFixedRate(new TimerTask() {

@Override
public void run() {
Expand All @@ -120,6 +127,34 @@ private void stopTask(final Task task) {
ti.state = States.STOPPED;
}

/**
* Restarts the timer and executes the task.
* NOT thread safe!!!<br/>
* @throws NullPointerException when {@code task} is not in the {@link #tasks}.
* @param task
*/
protected void taskTriggerFired(final Task task) {
if( tasks.get(task).state == States.RUNNING ){
// TODO : Implement error reporting
return;
}

TaskInfo ti = tasks.get(task);
ti.timer.cancel();
ti.timer = new Timer();

ti.timer.scheduleAtFixedRate(new TimerTask() {

@Override
public void run() {
taskTimerFired(task);
}
}, 0, task.getSchedulingSpecification().getPeriod());

ti.state = States.RUNNING;
executor.execute(task);
}

protected void taskTimerFired(Task task) {
if( tasks.get(task).state == States.RUNNING ){
// TODO : Implement error reporting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
*/
public interface TriggerListener {

public boolean triggered(Trigger trigger);
public void triggered(Trigger trigger);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class LocalTimeSchedulerTest {
public void setUp() throws Exception{
executor = mock(Executor.class);
sched = new LocalTimeScheduler(executor);

//dowhen(executor.execute).then();
}


Expand Down

0 comments on commit 3c6c6ee

Please sign in to comment.