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

me.niccolomattei.api.telegram.scheduling.SyncScheduler Maven / Gradle / Ivy

There is a newer version: 1.4_PRERELEASE-2
Show newest version
package me.niccolomattei.api.telegram.scheduling;

import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;

/**
 * @deprecated Rework needed. Will do it soon.
 */
@Deprecated
public class SyncScheduler implements Scheduler {

	private Map tasks = new HashMap<>();

	Timer timer = null;

	{
		timer = new Timer();
	}

	@Override
	public void runTask(SchedulerTask task) {
		task.run();
	}

	@Override
	public void runTaskLater(final SchedulerTask task, long delay) {
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				task.run();
			}
		}, delay);
	}

	@Override
	public void runRepeatingTask(final SchedulerTask task, long delay, long period) {

		TimerTask ttask = new TimerTask() {

			@Override
			public void run() {
				task.run();

			}
		};

		timer.scheduleAtFixedRate(ttask, delay, period);
		UUID uuid = UUID.randomUUID();
		task.setId(uuid);
		tasks.put(uuid, ttask);
	}

	@Override
	public void cancel(UUID taskId) {
		if (tasks.containsKey(taskId)) {
			tasks.get(taskId).cancel();
			tasks.remove(taskId);
		} else
			throw new SchedulerException("Task is not a repeating task or non-existant!");
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy