-
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.
new scheduler in DEECo core, start() is now synchronous and main loop
delegates via nextStep() to SchedulerNotifier. Some Javadoc and tests still missing.
- Loading branch information
Showing
20 changed files
with
400 additions
and
1,022 deletions.
There are no files selected for viewing
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
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
90 changes: 90 additions & 0 deletions
90
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/DiscreteEventSimulation.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,90 @@ | ||
package cz.cuni.mff.d3s.deeco.scheduler; | ||
|
||
import java.util.PriorityQueue; | ||
import java.util.Queue; | ||
|
||
public class DiscreteEventSimulation implements SchedulerNotifier { | ||
|
||
Queue<EventTime> eventTimes; | ||
SimulationTimeEventListener simulationTimeEventListener; | ||
|
||
long currentTime; | ||
|
||
public DiscreteEventSimulation() { | ||
currentTime = 0; | ||
eventTimes = new PriorityQueue<>(); | ||
} | ||
|
||
class EventTime implements Comparable<EventTime> { | ||
long timePoint; | ||
boolean isTerminationEvent; | ||
|
||
public EventTime(long timePoint, boolean isTerminationEvent) { | ||
this.timePoint = timePoint; | ||
this.isTerminationEvent = isTerminationEvent; | ||
} | ||
|
||
public int compareTo(EventTime e) { | ||
if (this.timePoint > e.timePoint) { | ||
return 1; | ||
} else if (this.timePoint < e.timePoint) { | ||
return -1; | ||
} else { | ||
if (e.isTerminationEvent) { | ||
return -1; | ||
} else if (this.isTerminationEvent) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public long getCurrentMilliseconds() { | ||
return currentTime; | ||
} | ||
|
||
@Override | ||
public void setSimulationTimeEventListener(SimulationTimeEventListener simulationTimeEventListener) { | ||
this.simulationTimeEventListener = simulationTimeEventListener; | ||
} | ||
|
||
@Override | ||
public void notifyAt(long time) { | ||
eventTimes.add(new EventTime(time,false)); | ||
} | ||
|
||
@Override | ||
public boolean tryToTerminate() { | ||
if (!eventTimes.isEmpty()) { | ||
EventTime eventTime = eventTimes.peek(); | ||
if (eventTime.isTerminationEvent) { | ||
currentTime = eventTime.timePoint; | ||
eventTimes.clear(); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void nextStep() { | ||
if (!eventTimes.isEmpty()) { | ||
currentTime = eventTimes.remove().timePoint; | ||
simulationTimeEventListener.at(currentTime); | ||
} | ||
} | ||
|
||
@Override | ||
public void setTerminationTime(long duration) { | ||
eventTimes.add(new EventTime(duration,true)); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
currentTime = 0; | ||
eventTimes.clear(); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/NoExecutorAvailableException.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,13 @@ | ||
package cz.cuni.mff.d3s.deeco.scheduler; | ||
|
||
import cz.cuni.mff.d3s.deeco.runtime.DEECoException; | ||
|
||
public class NoExecutorAvailableException extends DEECoException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public NoExecutorAvailableException() { | ||
super("No executor was available for the scheduler."); | ||
} | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/SchedulerNotifier.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,18 @@ | ||
package cz.cuni.mff.d3s.deeco.scheduler; | ||
|
||
public interface SchedulerNotifier extends CurrentTimeProvider, TerminationTimeHolder { | ||
|
||
void notifyAt(long time); | ||
|
||
void setSimulationTimeEventListener(SimulationTimeEventListener simulationTimeEventListener); | ||
|
||
void nextStep(); | ||
|
||
boolean tryToTerminate(); | ||
|
||
/** | ||
* This call sets the current time of the simulator to 0. | ||
*/ | ||
void reset(); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/SimulationTimeEventListener.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,23 @@ | ||
/** | ||
* | ||
*/ | ||
package cz.cuni.mff.d3s.deeco.scheduler; | ||
|
||
|
||
/** | ||
* Listener interface for time events triggered by a simulation. | ||
* | ||
* @author Michal Kit <kit@d3s.mff.cuni.cz> | ||
* | ||
*/ | ||
public interface SimulationTimeEventListener { | ||
|
||
/** | ||
* Simulation callback method for the previous registration | ||
* | ||
* @param time | ||
* current simulation time | ||
* @throws NoExecutorAvailableException | ||
*/ | ||
void at(long time); | ||
} |
Oops, something went wrong.