use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.
the class SimpleTaskScheduler method doSchedule.
private void doSchedule() {
logger.finest("Executing doSchedule...");
List<TaskInfo> choices = getSchedulableTasks();
if (logger.isLoggable(Level.INFO))
logger.info("COG " + cog.getID() + " scheduling choices: " + choices);
if (choices.isEmpty()) {
logger.info("Choices are empty!");
runtime.doNextStep();
return;
}
TaskInfo nextTask = schedule(choices);
nextTask.hasBeenActivated = true;
synchronized (this) {
if (nextTask.isSuspended()) {
suspendedTasks.remove(nextTask);
nextTask.makeReady();
} else {
readyTasks.remove(nextTask);
}
activateTask(nextTask);
}
}
use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.
the class SimpleTaskScheduler method taskFinished.
protected void taskFinished() {
logger.finest("Task finished getting monitor...");
TaskInfo finishedTask = null;
synchronized (this) {
logger.finest("got monitor");
finishedTask = activeTask;
finishedTask.task.setFinished(true);
activeTask = null;
if (suspendedTasks.size() + readyTasks.size() > 0) {
logger.finest("calling schedule...");
schedule();
logger.finest("schedule called");
}
}
logger.finest("do next step");
// we now have to wait for all tasks that waited for the future
// of this task to give them the opportunity to add a schedule action
// to the global scheduler, before we do this step
runtime.doNextStep();
logger.finest("next step done");
}
use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.
the class SimpleTaskScheduler method unsuspendTasks.
private synchronized List<TaskInfo> unsuspendTasks() {
List<TaskInfo> tasksWithSatisfiedGuards = new ArrayList<>(0);
Iterator<TaskInfo> it = suspendedTasks.iterator();
while (it.hasNext()) {
TaskInfo task = it.next();
if (task.guard.isTrue()) {
if (task.guard.staysTrue()) {
readyTasks.add(task);
task.makeReady();
it.remove();
} else {
tasksWithSatisfiedGuards.add(task);
}
}
}
return tasksWithSatisfiedGuards;
}
use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.
the class SimpleTaskScheduler method await.
@Override
public void await(ABSGuard g) {
SimpleSchedulerThread thread = null;
TaskInfo newTask = null;
TaskInfo currentTask = null;
synchronized (this) {
if (activeTask == null) {
// while shutting down the activeTask might bee null
return;
}
currentTask = activeTask;
thread = currentTask.thread;
currentTask.suspend(g);
suspendedTasks.add(currentTask);
activeTask = null;
if (view != null)
view.taskSuspended(currentTask.task.getView(), g);
thread.setGuard(g);
if (g.isTrue() || (suspendedTasks.size() + readyTasks.size()) > 1) {
logger.fine("issuing a schedule");
schedule();
}
}
runtime.doNextStep();
synchronized (this) {
newTask = activeTask;
}
if (newTask != currentTask) {
thread.await(g);
}
if (view != null)
view.taskResumed(currentTask.task.getView(), g);
}
use of abs.backend.java.scheduling.SimpleTaskScheduler.TaskInfo in project abstools by abstools.
the class UserSchedulingStrategy method schedule.
@Override
public synchronized TaskInfo schedule(final TaskScheduler scheduler, final List<TaskInfo> schedulableTasks) {
System.out.println(scheduler.getCOG().toString() + " Scheduling (" + schedulableTasks.size() + " processes in queue)...");
// Remember TaskInfos based on their Pids to speed things up a little
HashMap<Integer, TaskInfo> taskMap = new HashMap<>();
// Convert List<TaskInfo> to ArrayList<ABSProcess>
ArrayList<ABSProcess> processes = new ArrayList<>();
for (TaskInfo taskInfo : schedulableTasks) {
taskMap.put(taskInfo.task.getID(), taskInfo);
// TODO set: pid, method, arrival, cost, deadline, start, finish, critical, value
ABSProcess proc = new ABSProcess(// Or use taskInfo.id (long)??
taskInfo.task.getID(), taskInfo.task.getCall().methodName(), taskInfo.task.getArrival(), taskInfo.task.getCost(), taskInfo.task.getDeadline(), taskInfo.task.getStart(), taskInfo.task.getFinish(), taskInfo.task.isCritical(), taskInfo.task.getValue());
processes.add(proc);
}
logger.info(processes.toString());
// Convert ArryList<ABSProcess> to ABS.StdLib.List of ABSProcess
final Object queue = ListUtils.toABSList(processes);
ABSProcess result = userschedule(queue);
// Convert returned ABSValue (actually an ABSProcess) to TaskInfo
int selectedPid = result.getPid();
logger.info("scheduling Task " + selectedPid);
return taskMap.get(selectedPid);
}
Aggregations