use of org.abs_models.backend.java.lib.types.ABSValue in project abstools by abstools.
the class TestModel method testStarted.
public void testStarted(TaskView task) {
final String testMethod;
final String className;
final List<ABSValue> testMethodArguments;
final LinkedList<ABSValue> arguments = new LinkedList<>();
if (task.getStack().hasFrames()) {
final TaskStackFrameView currentF = task.getStack().getCurrentFrame();
testMethod = currentF.getMethod().getName();
className = currentF.getMethod().getClassView().getName();
for (String parameterName : currentF.getVariableNames()) {
arguments.add(currentF.getValue(parameterName));
}
} else {
testMethod = task.getMethodName();
className = task.getTarget().getClassName();
arguments.addAll(task.getArgs());
}
if (!task.getStack().hasFrames()) {
System.out.println("Not yet started " + testMethod + " for task " + task.getID());
} else {
System.out.println("Test " + task.getStack().getCurrentFrame().getMethod() + " task: " + task.getID());
}
final TestStatus newTest = new TestStatus(task.getID(), testMethod, className, arguments, task.getStack().getFrames(), TestStatus.Status.ACTIVE);
push(newTest);
System.out.println("Test started: " + task.getMethodName() + " : " + testMethod);
informListenersTestStarted(newTest);
}
use of org.abs_models.backend.java.lib.types.ABSValue in project abstools by abstools.
the class Task method run.
public void run() {
synchronized (this) {
if (view != null)
view.taskStarted();
executingThread = Thread.currentThread();
}
try {
ABSValue res = (ABSValue) call.execute();
future.resolve(res);
} catch (ABSException e) {
this.exception = e;
future.smash(e);
getCOG().getRuntime().handleABSException(this, e);
} catch (SystemTerminatedException e) {
} catch (Exception e) {
e.printStackTrace();
ABSException absException = new ABSAssertException("Sorry, this is a bug in the Java backend of ABS: " + "Unexpected exception: " + e);
// TODO new subclass for internal error
absException.setStackTrace(e.getStackTrace());
getCOG().getRuntime().handleABSException(this, absException);
}
synchronized (this) {
if (view != null)
view.taskFinished();
}
}
use of org.abs_models.backend.java.lib.types.ABSValue in project abstools by abstools.
the class Cog method setupAPI.
private static void setupAPI() {
thisClass.setName("Cog");
thisClass.addMethod(/*List<Process>*/
"getQueue", new ABSClosure() {
@Override
public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
// TODO
return ABSUnit.UNIT;
}
});
thisClass.addMethod(/*ABSUnit*/
"info", new ABSClosure() {
@Override
public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
COG cog = (COG) t.getFieldValue_Internal("cog");
System.out.println("Cog scheduler " + cog.getScheduler().toString());
if (cog.getScheduler() instanceof SimpleTaskScheduler) {
SimpleTaskScheduler sch = (SimpleTaskScheduler) cog.getScheduler();
TaskSchedulingStrategy strat = sch.getSchedulingStrategy();
System.out.println("Strategy " + strat);
}
return ABSUnit.UNIT;
}
});
thisClass.addMethod(/*ABSUnit*/
"setScheduler", new ABSClosure() {
@Override
public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
COG cog = (COG) t.getFieldValue_Internal("cog");
if (!(cog.getScheduler() instanceof SimpleTaskScheduler)) {
throw new DynamicException("For user-defined scheduling to work, the Scheduler must be an instance of " + SimpleTaskScheduler.class.getName() + " (use \"-taskscheduler=simple\")");
}
// The user-defined scheduler
final ABSDynamicObject userScheduler = (ABSDynamicObject) params[0];
// Create a new scheduling strategy that invokes the user-defined scheduler's "schedule" method
// - convert TaskSchedulingStrategy's List<TaskInfo> to ProcessScheduler's List<Process>
// - convert returned Process to TaskInfo.
// custom TaskSchedulingStrategy
TaskSchedulingStrategy strategy = new TaskSchedulingStrategy() {
@Override
public synchronized SimpleTaskScheduler.TaskInfo schedule(final TaskScheduler scheduler, final List<SimpleTaskScheduler.TaskInfo> schedulableTasks) {
System.out.println("Scheduling (" + schedulableTasks.size() + " processes in queue)...");
// Remember TaskInfos based on their Pids to speed things up a little
HashMap<Long, SimpleTaskScheduler.TaskInfo> taskMap = new HashMap<>();
// Convert List<TaskInfo> to ArrayList<ABSProcess>
ArrayList<ABSProcess> processes = new ArrayList<>();
for (SimpleTaskScheduler.TaskInfo task : schedulableTasks) {
taskMap.put(task.id, task);
// TODO set: pid, method, arrival, cost, deadline, start, finish, critical, value
ABSProcess proc = new ABSProcess(task.task.getID(), task.task.getCall().methodName(), 0, 0, 0, 0, 0, false, 0);
processes.add(proc);
System.out.println("\t" + proc.toString());
}
// FIXME
return schedulableTasks.get(0);
}
};
// Connect the strategy to the cog's scheduler
System.out.println(cog.toString() + ": Setting TaskSchedulingStrategy to: " + userScheduler.getClassName());
// move the userScheduler object to the Cog
// this WILL cause problems if the user associates the scheduler with multiple cogs!!
// userScheduler.setCOG(cog);
SimpleTaskScheduler scheduler = (SimpleTaskScheduler) cog.getScheduler();
scheduler.setSchedulingStrategy(strategy);
return ABSUnit.UNIT;
}
});
}
use of org.abs_models.backend.java.lib.types.ABSValue in project abstools by abstools.
the class Feature method setupMetaAPI.
/*
* Define the methods of this class
*/
public static void setupMetaAPI() {
thisClass.setName("Feature");
thisClass.addMethod(/*ABSString*/
"getName", new ABSClosure() {
@Override
public ABSString exec(ABSDynamicObject t, ABSValue... params) {
ABSDynamicFeature f = (ABSDynamicFeature) t;
return ABSString.fromString(f.getName());
}
});
thisClass.addMethod(/*ABSString*/
"getAttributes", new ABSClosure() {
@Override
public ABSString exec(ABSDynamicObject t, ABSValue... params) {
ABSDynamicFeature f = (ABSDynamicFeature) t;
// TODO
return ABSString.fromString("Not Implemented Yet");
}
});
}
use of org.abs_models.backend.java.lib.types.ABSValue in project abstools by abstools.
the class Update method setupMetaAPI.
/*
* Define the methods of this class
*/
public static void setupMetaAPI() {
thisClass.setName("Update");
thisClass.addMethod(/*ABSString*/
"getName", new ABSClosure() {
@Override
public ABSString exec(ABSDynamicObject t, ABSValue... params) {
ABSDynamicUpdate update = (ABSDynamicUpdate) t;
return ABSString.fromString(update.getName());
}
});
thisClass.addMethod(/*ABSUnit*/
"apply", new ABSClosure() {
@Override
public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
ABSDynamicUpdate update = (ABSDynamicUpdate) t;
update.apply();
return ABSUnit.UNIT;
}
});
}
Aggregations