All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mdk_runtime.FakeTime Maven / Gradle / Ivy

There is a newer version: 2.0.37
Show newest version
/* Quark 1.0.452 run at 2016-11-10 18:39:58.222591 */
package mdk_runtime;

/**
 * Testing fake.
 */
public class FakeTime implements Time, SchedulingActor, io.datawire.quark.runtime.QObject {
    public static quark.reflect.Class quark_List_quark_long__ref = datawire_mdk_md.Root.quark_List_quark_long__md;
    public static quark.reflect.Class quark_Map_quark_long_mdk_runtime__FakeTimeRequest__ref = datawire_mdk_md.Root.quark_Map_quark_long_mdk_runtime__FakeTimeRequest__md;
    public static quark.reflect.Class mdk_runtime_FakeTime_ref = datawire_mdk_md.Root.mdk_runtime_FakeTime_md;
    public Double _now = 1000.0;
    public java.util.HashMap _scheduled = io.datawire.quark.runtime.Builtins.map(new Object[]{});
    public mdk_runtime.actors.MessageDispatcher dispatcher;
    public Integer _counter = 0;
    public FakeTime() {}
    public void onStart(mdk_runtime.actors.MessageDispatcher dispatcher) {
        (this).dispatcher = dispatcher;
    }
    public void onMessage(mdk_runtime.actors.Actor origin, Object msg) {
        Schedule sched = (Schedule) (msg);
        (this)._counter = ((this)._counter) + (1);
        (this._scheduled).put((new Long(this._counter)), (new _FakeTimeRequest(origin, (sched).event, ((this)._now) + ((sched).seconds))));
    }
    public Double time() {
        return (this)._now;
    }
    /**
     * Run scheduled events whose time has come.
     */
    public void pump() {
        Integer idx = 0;
        java.util.ArrayList keys = new java.util.ArrayList(((this)._scheduled).keySet());
        while ((idx) < ((keys).size())) {
            _FakeTimeRequest request = (this._scheduled).get((keys).get(idx));
            if (((request).happensAt) <= ((this)._now)) {
                ((this)._scheduled).remove((keys).get(idx));
                ((this).dispatcher).tell(this, new Happening((request).event, this.time()), (request).requester);
            }
            idx = (idx) + (1);
        }
    }
    /**
     * Move time forward.
     */
    public void advance(Double seconds) {
        (this)._now = ((this)._now) + (seconds);
    }
    /**
     * Number of scheduled events.
     */
    public Integer scheduled() {
        return (new java.util.ArrayList(((this)._scheduled).keySet())).size();
    }
    public String _getClass() {
        return "mdk_runtime.FakeTime";
    }
    public Object _getField(String name) {
        if ((name)==("_now") || ((Object)(name) != null && ((Object) (name)).equals("_now"))) {
            return (this)._now;
        }
        if ((name)==("_scheduled") || ((Object)(name) != null && ((Object) (name)).equals("_scheduled"))) {
            return (this)._scheduled;
        }
        if ((name)==("dispatcher") || ((Object)(name) != null && ((Object) (name)).equals("dispatcher"))) {
            return (this).dispatcher;
        }
        if ((name)==("_counter") || ((Object)(name) != null && ((Object) (name)).equals("_counter"))) {
            return (this)._counter;
        }
        return null;
    }
    public void _setField(String name, Object value) {
        if ((name)==("_now") || ((Object)(name) != null && ((Object) (name)).equals("_now"))) {
            (this)._now = (Double) (value);
        }
        if ((name)==("_scheduled") || ((Object)(name) != null && ((Object) (name)).equals("_scheduled"))) {
            (this)._scheduled = (java.util.HashMap) (value);
        }
        if ((name)==("dispatcher") || ((Object)(name) != null && ((Object) (name)).equals("dispatcher"))) {
            (this).dispatcher = (mdk_runtime.actors.MessageDispatcher) (value);
        }
        if ((name)==("_counter") || ((Object)(name) != null && ((Object) (name)).equals("_counter"))) {
            (this)._counter = (Integer) (value);
        }
    }
    /**
     * The Actor should begin shutting down.
     */
    public void onStop() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy