Search in sources :

Example 1 with ABSDynamicObject

use of org.abs_models.backend.java.lib.runtime.ABSDynamicObject 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;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) HashMap(java.util.HashMap) SimpleTaskScheduler(org.abs_models.backend.java.scheduling.SimpleTaskScheduler) ArrayList(java.util.ArrayList) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) TaskScheduler(org.abs_models.backend.java.scheduling.TaskScheduler) SimpleTaskScheduler(org.abs_models.backend.java.scheduling.SimpleTaskScheduler) ABSProcess(org.abs_models.backend.java.lib.types.ABSProcess) DynamicException(org.abs_models.backend.java.codegeneration.dynamic.DynamicException) TaskSchedulingStrategy(org.abs_models.backend.java.scheduling.TaskSchedulingStrategy) COG(org.abs_models.backend.java.lib.runtime.COG)

Example 2 with ABSDynamicObject

use of org.abs_models.backend.java.lib.runtime.ABSDynamicObject 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");
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSDynamicFeature(org.abs_models.backend.java.lib.runtime.ABSDynamicFeature) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) ABSString(org.abs_models.backend.java.lib.types.ABSString)

Example 3 with ABSDynamicObject

use of org.abs_models.backend.java.lib.runtime.ABSDynamicObject 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;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSDynamicUpdate(org.abs_models.backend.java.lib.runtime.ABSDynamicUpdate) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) ABSString(org.abs_models.backend.java.lib.types.ABSString)

Example 4 with ABSDynamicObject

use of org.abs_models.backend.java.lib.runtime.ABSDynamicObject in project abstools by abstools.

the class Product method setupMetaAPI.

/*
     * Define the methods of this class
     */
public static void setupMetaAPI() {
    thisClass.setName("Product");
    /*
         * MetaABS Product API -- cf. abslang.abs module ABS.Meta
         */
    thisClass.addMethod(/*ABSString*/
    "getName", new ABSClosure() {

        @Override
        public ABSString exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            return ABSString.fromString(thisP.getName());
        }
    });
    thisClass.addMethod(/*List<ABSDynamicFeature>*/
    "getFeatures", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            ArrayList<ABSDynamicFeature> features = new ArrayList<>();
            for (ABSDynamicFeature f : thisP.getFeatures()) {
                features.add(f);
            }
            return ListUtils.toABSList(features);
        }
    });
    thisClass.addMethod(/*Set<ABSDynamicProduct>*/
    "getConfigurableProducts", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            return ListUtils.toABSSet(thisP.getConfigurableProducts());
        }
    });
    thisClass.addMethod(/*ABSDynamicReconfiguration*/
    "getReconfiguration", new ABSClosure() {

        @Override
        public ABSDynamicReconfiguration exec(ABSDynamicObject t, ABSValue... params) {
            ABSDynamicProduct thisP = (ABSDynamicProduct) t;
            ABSDynamicProduct targetP = (ABSDynamicProduct) params[0];
            return thisP.getReconfiguration(targetP);
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSDynamicFeature(org.abs_models.backend.java.lib.runtime.ABSDynamicFeature) ABSDynamicProduct(org.abs_models.backend.java.lib.runtime.ABSDynamicProduct) ArrayList(java.util.ArrayList) ABSValue(org.abs_models.backend.java.lib.types.ABSValue) ABSString(org.abs_models.backend.java.lib.types.ABSString) ABSDynamicReconfiguration(org.abs_models.backend.java.lib.runtime.ABSDynamicReconfiguration)

Example 5 with ABSDynamicObject

use of org.abs_models.backend.java.lib.runtime.ABSDynamicObject in project abstools by abstools.

the class Method method setupAPI.

/*
     * Define the methods of this class
     */
public static void setupAPI() {
    thisClass.setName("Method");
    // FIXME This does not work currently, because abslang.abs needs to declare
    // * the return type
    // * the number and types of arguments
    thisClass.addMethod(/*ABSValue*/
    "exec", new ABSClosure() {

        @Override
        public ABSValue exec(ABSDynamicObject t, ABSValue... params) {
            ABSClosure method = (ABSClosure) t;
            // FIXME
            // params[0] is the receiver object,
            // params[1] is an ABSList with the actual arguments
            ABSValue res = method.exec((ABSDynamicObject) params[0], params[1]);
            // FIXME return the result...
            return ABSUnit.UNIT;
        }
    });
}
Also used : ABSDynamicObject(org.abs_models.backend.java.lib.runtime.ABSDynamicObject) ABSClosure(org.abs_models.backend.java.lib.runtime.ABSClosure) ABSValue(org.abs_models.backend.java.lib.types.ABSValue)

Aggregations

ABSClosure (org.abs_models.backend.java.lib.runtime.ABSClosure)10 ABSDynamicObject (org.abs_models.backend.java.lib.runtime.ABSDynamicObject)10 ABSValue (org.abs_models.backend.java.lib.types.ABSValue)10 ABSString (org.abs_models.backend.java.lib.types.ABSString)8 ABSUnit (org.abs_models.backend.java.lib.types.ABSUnit)4 ABSDynamicProduct (org.abs_models.backend.java.lib.runtime.ABSDynamicProduct)3 ABSDynamicReconfiguration (org.abs_models.backend.java.lib.runtime.ABSDynamicReconfiguration)3 ArrayList (java.util.ArrayList)2 ABSDynamicClass (org.abs_models.backend.java.lib.runtime.ABSDynamicClass)2 ABSDynamicFeature (org.abs_models.backend.java.lib.runtime.ABSDynamicFeature)2 ABSDynamicUpdate (org.abs_models.backend.java.lib.runtime.ABSDynamicUpdate)2 COG (org.abs_models.backend.java.lib.runtime.COG)2 HashMap (java.util.HashMap)1 List (java.util.List)1 DynamicException (org.abs_models.backend.java.codegeneration.dynamic.DynamicException)1 ABSDynamicDelta (org.abs_models.backend.java.lib.runtime.ABSDynamicDelta)1 ABSDynamicProductLine (org.abs_models.backend.java.lib.runtime.ABSDynamicProductLine)1 ABSBool (org.abs_models.backend.java.lib.types.ABSBool)1 ABSProcess (org.abs_models.backend.java.lib.types.ABSProcess)1 SimpleTaskScheduler (org.abs_models.backend.java.scheduling.SimpleTaskScheduler)1