Запрет добавления и удаления обработчиков во время впыолнения

This commit is contained in:
Gravit 2018-10-18 21:48:44 +07:00
parent 40392f24cd
commit b83666a584
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -57,12 +57,14 @@ public synchronized void stop()
public BlockingQueue<QueueEntry> queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди public BlockingQueue<QueueEntry> queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди
public int registerHandler(EventHandler<EventInterface> func, UUID[] events) public int registerHandler(EventHandler<EventInterface> func, UUID[] events)
{ {
if(isStarted.get()) throw new IllegalThreadStateException("It is forbidden to add a handler during thread operation.");
Arrays.sort(events); Arrays.sort(events);
handlers.add(new Entry(func,events)); handlers.add(new Entry(func,events));
return handlers.size(); return handlers.size();
} }
public void unregisterHandler(EventHandler<EventInterface> func) public void unregisterHandler(EventHandler<EventInterface> func)
{ {
if(isStarted.get()) throw new IllegalThreadStateException("It is forbidden to remove a handler during thread operation.");
handlers.removeIf(e -> e.func.equals(func)); handlers.removeIf(e -> e.func.equals(func));
} }
public void sendEvent(UUID key, EventInterface event, boolean blocking) public void sendEvent(UUID key, EventInterface event, boolean blocking)