mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
Функции start/stop
This commit is contained in:
parent
fc6a29cfa2
commit
40392f24cd
1 changed files with 26 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package ru.gravit.utils.event;
|
||||
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -7,6 +8,7 @@
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class EventManager {
|
||||
public static final int QUEUE_MAX_SIZE = 2048;
|
||||
|
@ -31,6 +33,26 @@ public QueueEntry(EventInterface event, UUID key) {
|
|||
EventInterface event;
|
||||
UUID key;
|
||||
}
|
||||
private EventExecutor executor;
|
||||
private Thread executorThread;
|
||||
private AtomicBoolean isStarted = new AtomicBoolean(false);
|
||||
public synchronized void start()
|
||||
{
|
||||
if(isStarted.get()) return;
|
||||
executor = new EventExecutor();
|
||||
isStarted.set(true);
|
||||
executorThread = CommonHelper.newThread("EventExecutor",true,executor);
|
||||
executorThread.start();
|
||||
}
|
||||
public synchronized void stop()
|
||||
{
|
||||
if(!isStarted.get()) return;
|
||||
executorThread.interrupt();
|
||||
try {
|
||||
executorThread.join();
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
public ArrayList<Entry> handlers = new ArrayList<>(INITIAL_HANDLERS_SIZE);
|
||||
public BlockingQueue<QueueEntry> queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди
|
||||
public int registerHandler(EventHandler<EventInterface> func, UUID[] events)
|
||||
|
@ -39,6 +61,10 @@ public int registerHandler(EventHandler<EventInterface> func, UUID[] events)
|
|||
handlers.add(new Entry(func,events));
|
||||
return handlers.size();
|
||||
}
|
||||
public void unregisterHandler(EventHandler<EventInterface> func)
|
||||
{
|
||||
handlers.removeIf(e -> e.func.equals(func));
|
||||
}
|
||||
public void sendEvent(UUID key, EventInterface event, boolean blocking)
|
||||
{
|
||||
if(blocking) process(key,event);
|
||||
|
|
Loading…
Reference in a new issue