diff options
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/juick/push/PushComponent.java | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/main/java/com/juick/push/PushComponent.java b/src/main/java/com/juick/push/PushComponent.java index 6f857f59..a32e887c 100644 --- a/src/main/java/com/juick/push/PushComponent.java +++ b/src/main/java/com/juick/push/PushComponent.java @@ -48,6 +48,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; @@ -59,30 +61,38 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe private static Logger logger = Logger.getLogger(PushComponent.class.getName()); + private ExecutorService executorService; Connection sql; Socket socket; Stream xmpp; Sender GCMSender; @Override - public void contextInitialized(ServletContextEvent sce) { + public void contextInitialized(final ServletContextEvent sce) { logger.info("component initialized"); - Properties conf = new Properties(); - try { - conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/push.conf")); - GCMSender = new Sender(conf.getProperty("gcm_key")); + executorService = Executors.newSingleThreadExecutor(); + executorService.submit(new Runnable() { + @Override + public void run() { + Properties conf = new Properties(); + try { + conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/push.conf")); + GCMSender = new Sender(conf.getProperty("gcm_key")); - setupSql(conf.getProperty("mysql_host"), conf.getProperty("mysql_username"), - conf.getProperty("mysql_password", ""), conf.getProperty("mysql_database", "")); - setupXmppComponent(new JID("", conf.getProperty("xmpp_jid"), ""), conf.getProperty("xmpp_host", "localhost"), - Integer.parseInt(conf.getProperty("xmpp_port", "5347")), conf.getProperty("xmpp_password", "")); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } + setupSql(conf.getProperty("mysql_host"), conf.getProperty("mysql_username"), + conf.getProperty("mysql_password", ""), conf.getProperty("mysql_database", "")); + setupXmppComponent(new JID("", conf.getProperty("xmpp_jid"), ""), conf.getProperty("xmpp_host", "localhost"), + Integer.parseInt(conf.getProperty("xmpp_port", "5347")), conf.getProperty("xmpp_password", "")); + } catch (IOException e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + }); } @Override public void contextDestroyed(ServletContextEvent sce) { + executorService.shutdown(); logger.info("component destroyed"); } |