From a5f943dc198194773c79da7ef3b16f8959c873e4 Mon Sep 17 00:00:00 2001 From: Zontreck Date: Sun, 18 Feb 2024 09:59:02 -0700 Subject: [PATCH] Deprecate the delayed executor entirely --- .../dev/zontreck/ariaslib/terminal/Task.java | 11 +- .../zontreck/ariaslib/terminal/TaskBus.java | 38 ----- .../ariaslib/util/DelayedExecutorService.java | 153 +----------------- 3 files changed, 9 insertions(+), 193 deletions(-) delete mode 100644 src/main/java/dev/zontreck/ariaslib/terminal/TaskBus.java diff --git a/src/main/java/dev/zontreck/ariaslib/terminal/Task.java b/src/main/java/dev/zontreck/ariaslib/terminal/Task.java index fa63c49..bf737c9 100644 --- a/src/main/java/dev/zontreck/ariaslib/terminal/Task.java +++ b/src/main/java/dev/zontreck/ariaslib/terminal/Task.java @@ -36,9 +36,14 @@ public abstract class Task extends TimerTask implements Runnable { } public void startTask ( ) { - DelayedExecutorService.scheduleTask ( this , 1 ); - if ( ! isSilent && ! EnvironmentUtils.isRunningInsideDocker ( ) ) - DelayedExecutorService.instantExec ( new SpinnerTask ( token , this ) ); + Thread tx = new Thread(this); + tx.start(); + + if(! isSilent && !EnvironmentUtils.isRunningInsideDocker()) + { + Thread tx2 = new Thread(new SpinnerTask(token, this)); + tx2.start(); + } } public void stopTask ( ) { diff --git a/src/main/java/dev/zontreck/ariaslib/terminal/TaskBus.java b/src/main/java/dev/zontreck/ariaslib/terminal/TaskBus.java deleted file mode 100644 index 67acd6c..0000000 --- a/src/main/java/dev/zontreck/ariaslib/terminal/TaskBus.java +++ /dev/null @@ -1,38 +0,0 @@ -package dev.zontreck.ariaslib.terminal; - -import dev.zontreck.ariaslib.util.DelayedExecutorService; - -import java.util.ArrayList; -import java.util.List; - -public class TaskBus extends Task { - public static List tasks = new ArrayList<>(); - public static Task current = null; - - public TaskBus() { - super("TaskBus", true); - } - - public static void register() { - DelayedExecutorService.getInstance().scheduleRepeating(new TaskBus(), 1); - } - - @Override - public void run() { - try { - - if (TaskBus.current == null) { - TaskBus.current = tasks.get(0); - tasks.remove(0); - TaskBus.current.startTask(); - } else { - if (TaskBus.current.isComplete()) { - TaskBus.current.stopTask(); - TaskBus.current = null; - } - } - // Don't care about a empty stack exception. We'll just queue this task check back up - } catch (Exception e) { - } - } -} diff --git a/src/main/java/dev/zontreck/ariaslib/util/DelayedExecutorService.java b/src/main/java/dev/zontreck/ariaslib/util/DelayedExecutorService.java index af4fc70..d18b493 100644 --- a/src/main/java/dev/zontreck/ariaslib/util/DelayedExecutorService.java +++ b/src/main/java/dev/zontreck/ariaslib/util/DelayedExecutorService.java @@ -11,158 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger; import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.terminal.Terminal; - +@Deprecated public class DelayedExecutorService { - private static final AtomicBoolean RUN = new AtomicBoolean(true); - private static AtomicInteger COUNT = new AtomicInteger(0); - private static final DelayedExecutorService inst; - private static ScheduledThreadPoolExecutor repeater; - static{ - inst=new DelayedExecutorService(); - repeater = new ScheduledThreadPoolExecutor(16); - repeater.scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - DelayedExecutorService.getInstance().onTick(); - } - }, 1L, 1L, TimeUnit.SECONDS); - } - private DelayedExecutorService(){} - - /** - * Sets the executor to use for this delayed executor service - * @param exec The executor to use - */ - public static void setExecutor(ScheduledThreadPoolExecutor exec) - { - repeater = exec; - } - - /** - * Requests the active executor instance - * @return The thread executor - */ - public static ScheduledThreadPoolExecutor getExecutor() - { - return repeater; - } - - /** - * This function is designed to set back up the executor if it was previously stopped and restarted. - */ - @Deprecated - public static void setup() - { - } - - /** - * Stops accepting new tasks, and current ones will abort - */ - public static void stop() - { - RUN.set(false); - stopRepeatingThread(); - } - - /** - * Resume accepting new tasks. - * - * NOTE: The task system is set to run by default. This call is only needed if DelayedExecutorService#stop was used previously - */ - public static void start() - { - RUN.set(true); - } - - public static DelayedExecutorService getInstance() - { - return inst; - } - public class DelayedExecution - { - public DelayedExecution(Task run, long unix) { - scheduled=run; - unix_time=unix; - } - public Task scheduled; - public long unix_time; - } - - public List EXECUTORS = new ArrayList<>(); - - public static void scheduleTask(final Task run, int seconds) - { - DelayedExecutorService.getInstance().schedule(run,seconds); - } - public static void scheduleRepeatingTask(final Task run, int seconds) - { - DelayedExecutorService.getInstance().scheduleRepeating(run,seconds); - } - - public void schedule(final Task run, int seconds) - { - if(!isRunning()){ - return; - } - repeater.schedule(run, seconds, TimeUnit.SECONDS); - //long unix = Instant.now().getEpochSecond()+ (seconds); - //EXECUTORS.add(new DelayedExecution(run, unix)); - } - - public static void instantExec(final Task run) - { - repeater.execute(run); - } - - public static boolean isRunning() - { - return RUN.get(); - } - - public void scheduleRepeating(final Task run, int seconds) - { - if(!isRunning()) return; - - //long unix = Instant.now().getEpochSecond()+ (seconds); - Task repeat = new Task("Repeating:"+run.TASK_NAME, true) { - @Override - public void run() { - run.run(); - scheduleRepeating(run, seconds); - } - }; - repeater.schedule(repeat, seconds, TimeUnit.SECONDS); - //EXECUTORS.add(new DelayedExecution(repeater, unix)); - } - - private static void stopRepeatingThread() - { - repeater.shutdownNow(); - //repeater=null; // Dispose of so the threads get torn down and the program can stop successfully - } - - public void onTick() - { - /*Iterator it = EXECUTORS.iterator(); - try{ - - while(it.hasNext()) - { - DelayedExecution e = it.next(); - if(e.unix_time < Instant.now().getEpochSecond()) - { - it.remove(); - Thread tx = new Thread(e.scheduled); - tx.setName("DelayedExecutorTask-"+String.valueOf(DelayedExecutorService.getNext())); - tx.start(); - } - } - }catch(Exception e){}*/ - } - - public static int getNext() - { - return COUNT.getAndIncrement(); - } }