Skip to content

Commit

Permalink
more skin queue work
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Jan 15, 2025
1 parent 07e4df9 commit 00a200a
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/main/java/de/oliver/fancynpcs/skins/MineSkinQueue.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package de.oliver.fancynpcs.skins;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.mineskin.data.SkinInfo;
import org.mineskin.request.GenerateRequest;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

public class MineSkinQueue {

private final static ScheduledExecutorService EXECUTOR = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder()
.setNameFormat("MineSkinQueue")
.build());
private static MineSkinQueue INSTANCE;
private final Queue<Runnable> queue;
private final Queue<SkinRequest> queue;

private long nextRequestTime = System.currentTimeMillis();

private MineSkinQueue() {
this.queue = new LinkedList<>();
Expand All @@ -30,28 +35,29 @@ public static MineSkinQueue get() {
return INSTANCE;
}

public void add(Runnable runnable) {
this.queue.add(runnable);
}

private void run() {
EXECUTOR.scheduleAtFixedRate(this::poll, 5, 60, TimeUnit.SECONDS);
}

private void poll() {
System.out.println("Polling queue");
if (this.queue.isEmpty()) {
return;
}

System.out.println("Running runnables");
int counter = 0;
while (!this.queue.isEmpty() && counter < 9) {
Runnable runnable = this.queue.poll();
if (runnable != null) {
runnable.run();
}
counter++;
if (System.currentTimeMillis() < this.nextRequestTime) {
return;
}

SkinRequest req = this.queue.poll();


}

public void add(SkinRequest req) {
this.queue.add(req);
}


public record SkinRequest(GenerateRequest request, Consumer<SkinInfo> finish) {
}
}

0 comments on commit 00a200a

Please sign in to comment.