From 58fb4a6394cb19ee04e65d0e921cdf0ae6fdb6e3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 26 Jan 2016 21:43:38 +0300 Subject: s2s: logging --- .../java/com/juick/xmpp/s2s/XMPPComponent.java | 34 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/juick/xmpp/s2s/XMPPComponent.java') 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 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 i = XMPPComponent.outConnections.iterator(); i.hasNext();) { + ConnectionOut c = i.next(); + c.closeConnection(); + i.remove(); + } + } + + synchronized (XMPPComponent.inConnections) { + for (Iterator 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(); -- cgit v1.2.3