public static MessageData getMessageData() { if (messageData == null) { messageData = new MessageData(); Utils.StoppedThread twitterThread = new Utils.StoppedThread(TwitterLoader.getInstance()); twitterThread.start(); ContextListener.addThread(twitterThread); } return messageData; }
public MessageData() { Properties properties = new Properties(); try { properties.load(getClass().getResourceAsStream("/creepingline.properties")); backup = properties.getProperty("backup.file.name"); logoBackup = properties.getProperty("backup.logo.file.name"); } catch (IOException e) { log.error("error", e); } messageList = new BackUp<>(Message.class, backup); logosList = new BackUp<>(Advertisement.class, logoBackup); Utils.StoppedThread update = new Utils.StoppedThread( new Utils.StoppedRunnable() { @Override public void run() { while (!stop) { tick(); try { Thread.sleep(2000); } catch (InterruptedException e) { log.error("error", e); } } } }); update.start(); ContextListener.addThread(update); messageFlow = new SynchronizedBeanItemContainer<>(Message.class); EventsLoader eventsLoader = EventsLoader.getInstance(); new Thread( () -> { while (true) { final BlockingQueue<AnalystMessage> q = eventsLoader.getContestData().getAnalystMessages(); try { AnalystMessage e = q.poll(5000, TimeUnit.MILLISECONDS); if (e == null) continue; if (e.getCategory() == WFAnalystMessage.WFAnalystMessageCategory.HUMAN || e.getPriority() <= 1) { addMessageToFlow( new Message(e.getMessage(), e.getTime() * 1000, 0, false, "Analytics")); } } catch (InterruptedException e1) { try { Thread.sleep(5000); } catch (InterruptedException e) { break; } } } }) .start(); }