Deprecate the delayed executor entirely
This commit is contained in:
parent
bba75793dd
commit
a5f943dc19
3 changed files with 9 additions and 193 deletions
|
@ -36,9 +36,14 @@ public abstract class Task extends TimerTask implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTask ( ) {
|
public void startTask ( ) {
|
||||||
DelayedExecutorService.scheduleTask ( this , 1 );
|
Thread tx = new Thread(this);
|
||||||
if ( ! isSilent && ! EnvironmentUtils.isRunningInsideDocker ( ) )
|
tx.start();
|
||||||
DelayedExecutorService.instantExec ( new SpinnerTask ( token , this ) );
|
|
||||||
|
if(! isSilent && !EnvironmentUtils.isRunningInsideDocker())
|
||||||
|
{
|
||||||
|
Thread tx2 = new Thread(new SpinnerTask(token, this));
|
||||||
|
tx2.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTask ( ) {
|
public void stopTask ( ) {
|
||||||
|
|
|
@ -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<Task> 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) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,158 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import dev.zontreck.ariaslib.terminal.Task;
|
import dev.zontreck.ariaslib.terminal.Task;
|
||||||
import dev.zontreck.ariaslib.terminal.Terminal;
|
import dev.zontreck.ariaslib.terminal.Terminal;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class DelayedExecutorService {
|
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<DelayedExecution> 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<DelayedExecution> 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue