diff options
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/XMPPComponent.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/XMPPComponent.java | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java index ff4ec3e6..bb5f5ef7 100644 --- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java +++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java @@ -29,7 +29,6 @@ public class XMPPComponent implements ServletContextListener { public static String HOSTNAME = null; public static String COMPONENTNAME = null; - public static String LOGFILE = null; public static String STATSFILE = null; public static ConnectionRouter connRouter; static final List<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>()); @@ -125,7 +124,7 @@ public class XMPPComponent implements ServletContextListener { try { connOut.sendStanza(xml); } catch (IOException e) { - System.err.println("STREAM TO " + connOut.to + " " + connOut.streamID + " ERROR: " + e.toString()); + LOGGER.warning("STREAM TO " + connOut.to + " " + connOut.streamID + " ERROR: " + e.toString()); } return; } @@ -161,14 +160,11 @@ public class XMPPComponent implements ServletContextListener { conf.load(new FileInputStream("/etc/juick/s2s.conf")); HOSTNAME = conf.getProperty("hostname"); COMPONENTNAME = conf.getProperty("componentname"); - LOGFILE = conf.getProperty("logfile"); STATSFILE = conf.getProperty("statsfile"); Class.forName("com.mysql.jdbc.Driver"); sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", "")); - Runtime.getRuntime().addShutdownHook(new Shutdown()); - childParsers.put(JuickMessage.XMLNS, new JuickMessage()); connRouter = new ConnectionRouter(); @@ -185,6 +181,34 @@ public class XMPPComponent implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent sce) { + synchronized (XMPPComponent.outConnections) { + for (Iterator<ConnectionOut> i = XMPPComponent.outConnections.iterator(); i.hasNext();) { + ConnectionOut c = i.next(); + c.closeConnection(); + i.remove(); + } + } + + synchronized (XMPPComponent.inConnections) { + for (Iterator<ConnectionIn> i = XMPPComponent.inConnections.iterator(); i.hasNext();) { + ConnectionIn c = i.next(); + c.closeConnection(); + i.remove(); + } + } + + XMPPComponent.connRouter.closeConnection(); + + synchronized (XMPPComponent.sqlSync) { + if (XMPPComponent.sql != null) { + try { + XMPPComponent.sql.close(); + XMPPComponent.sql = null; + } catch (SQLException e) { + LOGGER.warning("SQL ERROR: " + e); + } + } + } // Now deregister JDBC drivers in this context's ClassLoader: // Get the webapp's ClassLoader ClassLoader cl = Thread.currentThread().getContextClassLoader(); |