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

astra.core.Scheduler Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version
package astra.core;

import astra.execution.SchedulerStrategy;

public class Scheduler {
	public static final int ACTIVE = 0;
	public static final int INACTIVE = 1;
	public static final int STEPPING = 2;
	public static final int WAITING = 3;

	private static SchedulerStrategy strategy;
	
	public static void setStrategy(SchedulerStrategy s) {
		if (strategy != null) {
			strategy.stop();
		}
		strategy = s;
	}
	
	public static boolean hasStrategy() {
		return strategy != null;
	}
	
	public static void schedule(Agent agent) {
		strategy.schedule(agent);
	}
	
	public static void schedule(Task task) {
		strategy.schedule(task);
	}
	
	public static void setThreadPoolSize(int size) {
		strategy.setThreadPoolSize(size);
	}

	public static void setState(Agent agent, int state) {
		strategy.setState(agent, state);
	}

	public static void setSleepTime(long sleepTime) {
		strategy.setSleepTime(sleepTime);
	}

	public static int getState(Agent agent) {
		return strategy.getState(agent);
	}

	public static void shutdown() {
		strategy.shutdown();
	}

	public static void resumeIfWaiting(Agent agent) {
		if (strategy.getState(agent) == Scheduler.WAITING) {
			strategy.setState(agent, Scheduler.ACTIVE);
			strategy.schedule(agent);
		}
	}

	public static void displayStats() {
		System.out.println(strategy);
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy