Guest User

Untitled

a guest
Aug 7th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package event;
  2.  
  3. import java.util.LinkedList;
  4. import java.util.Queue;
  5.  
  6. import com.tommie.rsps.Logging.Logging;
  7.  
  8. public class EventManager {
  9.  
  10.     public Queue<Event> EVENT_RUNNING = new LinkedList<Event>();
  11.    
  12.     public Queue<Event> EVENT_FINISHED = new LinkedList<Event>();
  13.  
  14.     public Queue<Event> EVENT_NEW = new LinkedList<Event>();
  15.    
  16.     public void addEvent(Event event) {
  17.         EVENT_FINISHED.add(event);
  18.     }
  19.  
  20.     public void runSystem() {
  21.         new Thread(new Runnable() {
  22.             @Override
  23.             public synchronized void run() {
  24.                 Logging.logInfo(this, "Started...!");
  25.                 while (true) {
  26.                     if (!EVENT_NEW.isEmpty() || !EVENT_RUNNING.isEmpty()) {
  27.                         EVENT_RUNNING.addAll(EVENT_NEW);
  28.                         EVENT_NEW.clear();
  29.                     }
  30.                     for (Event event : EVENT_RUNNING) {
  31.                         if (event.isReady()) {
  32.                             event.run();
  33.                         }
  34.                         if (!event.running()) {
  35.                             EVENT_FINISHED.add(event);
  36.                         }
  37.                     }
  38.                 }
  39.             }
  40.         });
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment