-
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.
Renaming "DEECoSimulationRealm" to "DEECoSimulation" and introducing new
"simulation" source folder to keep all the simulation-related classes
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
jdeeco-core/simulation/cz/cuni/mff/d3s/deeco/runners/DEECoSimulation.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,61 @@ | ||
package cz.cuni.mff.d3s.deeco.runners; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import cz.cuni.mff.d3s.deeco.runtime.DEECoException; | ||
import cz.cuni.mff.d3s.deeco.runtime.DEECoNode; | ||
import cz.cuni.mff.d3s.deeco.runtime.DEECoPlugin; | ||
import cz.cuni.mff.d3s.deeco.runtime.SimulationSchedulerNotifier; | ||
|
||
/** | ||
* Main class for launching DEECo simulations. | ||
* | ||
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz> | ||
*/ | ||
public class DEECoSimulation { | ||
|
||
List<DEECoNode> nodesList; | ||
DEECoPlugin[] simulationWideplugins; | ||
SimulationSchedulerNotifier simulationSchedulerNotifier; | ||
|
||
public DEECoSimulation(SimulationSchedulerNotifier simulationSchedulerNotifier, DEECoPlugin... simulationWideplugins) { | ||
this.simulationWideplugins = simulationWideplugins; | ||
this.simulationSchedulerNotifier = simulationSchedulerNotifier; | ||
nodesList = new ArrayList<>(); | ||
} | ||
|
||
public void start() { | ||
simulationSchedulerNotifier.start(); | ||
} | ||
|
||
public DEECoNode createNode(DEECoPlugin... extraPlugins) throws DEECoException { | ||
DEECoNode node = new DEECoNode(simulationSchedulerNotifier, getAllPlugins(extraPlugins)); | ||
nodesList.add(node); | ||
return node; | ||
} | ||
|
||
public void setTerminationTime(long terminationTime) { | ||
simulationSchedulerNotifier.setTerminationTime(terminationTime); | ||
} | ||
|
||
/** | ||
* Concatenates the array of simulation-wide plugins with node-specific plugins. | ||
* The returned array is intended to be passed to the DEECoNode() constructor. | ||
* @param extraPlugins node-specific plugins | ||
*/ | ||
private DEECoPlugin[] getAllPlugins(DEECoPlugin[] extraPlugins) { | ||
DEECoPlugin[] ret = new DEECoPlugin[extraPlugins.length+simulationWideplugins.length]; | ||
int ind=0; | ||
for (int i=0; i<extraPlugins.length; i++) { | ||
ret[ind] = extraPlugins[i]; | ||
ind++; | ||
} | ||
for (int j=0; j<simulationWideplugins.length; j++) { | ||
ret[ind] = extraPlugins[j]; | ||
ind++; | ||
} | ||
return ret; | ||
} | ||
|
||
} |
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.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,11 @@ | ||
package cz.cuni.mff.d3s.deeco.runners; | ||
|
||
/** | ||
* Main class for running DEECo in "real" deployment. | ||
* For simulation purposes use {@link DEECoSimulation} instead. | ||
* | ||
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz> | ||
*/ | ||
public class DEECoRun { | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/CurrentTimeProvider.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
34 changes: 34 additions & 0 deletions
34
jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/WallTimeSchedulerNotifier.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,34 @@ | ||
package cz.cuni.mff.d3s.deeco.scheduler.notifier; | ||
|
||
|
||
public class WallTimeSchedulerNotifier extends DiscreteEventSchedulerNotifier { | ||
|
||
long terminationTime; | ||
|
||
public void start() { | ||
|
||
while (!tryToTerminate()) { | ||
EventTime eventTime = eventTimes.remove(); | ||
long nextEventTime = eventTime.getTimePoint(); | ||
try { | ||
Thread.sleep(nextEventTime-currentTime); | ||
currentTime = nextEventTime; | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
eventTime.getListener().at(currentTime); | ||
} | ||
} | ||
|
||
public boolean tryToTerminate() { | ||
if (currentTime < terminationTime) { | ||
return false; | ||
} | ||
eventTimes.clear(); | ||
return true; | ||
} | ||
|
||
public void setTerminationTime(long terminationTime) { | ||
this.terminationTime = terminationTime; | ||
} | ||
} |