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

ai.evolv.ExecutionQueue Maven / Gradle / Ivy

There is a newer version: 0.7.1
Show newest version
package ai.evolv;

import ai.evolv.exceptions.AscendKeyError;

import com.google.gson.JsonArray;

import java.util.concurrent.ConcurrentLinkedQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class ExecutionQueue {

    private static Logger LOGGER = LoggerFactory.getLogger(ExecutionQueue.class);

    private final ConcurrentLinkedQueue queue;

    ExecutionQueue() {
        this.queue = new ConcurrentLinkedQueue<>();
    }

    void enqueue(Execution execution) {
        this.queue.add(execution);
    }

    void executeAllWithValuesFromAllocations(JsonArray allocations) {
        while (!queue.isEmpty()) {
            Execution execution = queue.remove();
            try {
                execution.executeWithAllocation(allocations);
            } catch (AscendKeyError e) {
                LOGGER.debug(String.format("There was an error retrieving" +
                        " the value of %s from the allocation.",  execution.getKey()), e);
                execution.executeWithDefault();
            } catch (Exception e) {
                LOGGER.error("There was an issue while performing one of" +
                        " the stored actions.", e);
            }
        }
    }

    void executeAllWithValuesFromDefaults() {
        while (!queue.isEmpty()) {
            Execution execution = queue.remove();
            execution.executeWithDefault();
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy