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

io.vertx.up.uca.job.center.FormulaAgha Maven / Gradle / Ivy

The newest version!
package io.vertx.up.uca.job.center;

import io.aeon.experiment.specification.sch.KTimer;
import io.horizon.eon.em.scheduler.JobStatus;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.up.atom.worker.Mission;
import io.vertx.up.uca.job.timer.Interval;

/**
 * @author Lang
 */
public class FormulaAgha extends AbstractAgha {
    @Override
    public Future begin(final Mission mission) {
        // STARTING -> READY
        this.moveOn(mission, true);

        return this.execute(mission);
    }

    private Future execute(final Mission mission) {
        final Promise promise = Promise.promise();
        final Interval interval = this.interval();
        final KTimer timer = mission.timer();
        interval.restartAt((timeId) -> {
            // STOPPED -> READY
            if (JobStatus.STOPPED == mission.getStatus()) {
                this.moveOn(mission, true);
            }
            this.working(mission, () -> {
                /*
                 * Complete future and returned Async
                 */
                promise.tryComplete(timeId);

                // RUNNING -> STOPPED
                this.moveOn(mission, true);
            });
        }, timer);
        return promise.future()
            /*
             * Call internal execute in loop because of
             * continue working on
             */
            .compose(finished -> this.execute(mission));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy