aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/xmpp/s2s/Connection.java35
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionIn.java50
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionListener.java49
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionOut.java34
-rw-r--r--src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java38
-rw-r--r--src/main/java/com/juick/xmpp/s2s/Shutdown.java45
-rw-r--r--src/main/java/com/juick/xmpp/s2s/XMPPComponent.java34
7 files changed, 146 insertions, 139 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/Connection.java b/src/main/java/com/juick/xmpp/s2s/Connection.java
index 699e52bfc..1a14b2cc8 100644
--- a/src/main/java/com/juick/xmpp/s2s/Connection.java
+++ b/src/main/java/com/juick/xmpp/s2s/Connection.java
@@ -1,14 +1,16 @@
package com.juick.xmpp.s2s;
+import org.xmlpull.mxp1.MXParser;
+import org.xmlpull.v1.XmlPullParser;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.net.Socket;
+import java.nio.channels.AsynchronousSocketChannel;
import java.util.Date;
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import org.xmlpull.mxp1.MXParser;
-import org.xmlpull.v1.XmlPullParser;
+import java.util.logging.Logger;
/**
*
@@ -16,12 +18,14 @@ import org.xmlpull.v1.XmlPullParser;
*/
public class Connection {
+ protected static final Logger LOGGER = Logger.getLogger(Connection.class.getName());
+
public String streamID;
public long tsCreated = 0;
public long tsLocalData = 0;
public long bytesLocal = 0;
public long packetsLocal = 0;
- Socket socket;
+ AsynchronousSocketChannel socket;
final XmlPullParser parser = new MXParser();
OutputStreamWriter writer;
@@ -29,15 +33,6 @@ public class Connection {
tsCreated = System.currentTimeMillis();
}
- public void logXml(String xml) {
- try {
- FileWriter logFile = new FileWriter(XMPPComponent.LOGFILE, true);
- logFile.write(new Date().toString() + "\t" + streamID + "\t" + xml);
- logFile.close();
- } catch (IOException e) {
- }
- }
-
public void logParser() {
if (streamID == null) {
return;
@@ -47,12 +42,12 @@ public class Connection {
tag += " " + parser.getAttributeName(i) + "=\"" + parser.getAttributeValue(i) + "\"";
}
tag += ">...</" + parser.getName() + ">\n";
- logXml(tag);
+ LOGGER.fine(tag);
}
public void sendStanza(String xml) throws IOException {
- if (XMPPComponent.LOGFILE != null && streamID != null) {
- logXml("OUT: " + xml + "\n");
+ if (streamID != null) {
+ LOGGER.fine("OUT: " + xml + "\n");
}
writer.write(xml);
writer.flush();
@@ -62,8 +57,8 @@ public class Connection {
}
void closeConnection() {
- if (XMPPComponent.LOGFILE != null && streamID != null) {
- logXml("CLOSING STREAM\n");
+ if (streamID != null) {
+ LOGGER.info(String.format("CLOSING STREAM %s", streamID));
}
try {
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
index 8150cc27b..7b9483f77 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionIn.java
@@ -5,13 +5,18 @@ import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.Presence;
import com.juick.xmpp.utils.XmlUtils;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.EOFException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.net.Socket;
+import java.nio.channels.AsynchronousSocketChannel;
+import java.nio.channels.Channels;
import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
-import org.xmlpull.v1.XmlPullParser;
+import java.util.logging.Logger;
/**
*
@@ -19,11 +24,13 @@ import org.xmlpull.v1.XmlPullParser;
*/
public class ConnectionIn extends Connection implements Runnable {
- final public ArrayList<String> from = new ArrayList<String>();
+ private static final Logger LOGGER = Logger.getLogger(ConnectionIn.class.getName());
+
+ final public List<String> from = new ArrayList<>();
public long tsRemoteData = 0;
public long packetsRemote = 0;
- public ConnectionIn(Socket socket) {
+ public ConnectionIn(AsynchronousSocketChannel socket) {
super();
this.socket = socket;
streamID = UUID.randomUUID().toString();
@@ -31,10 +38,10 @@ public class ConnectionIn extends Connection implements Runnable {
@Override
public void run() {
- System.out.println("STREAM FROM ? " + streamID + " START");
+ LOGGER.info("STREAM FROM ? " + streamID + " START");
try {
- parser.setInput(new InputStreamReader(socket.getInputStream()));
- writer = new OutputStreamWriter(socket.getOutputStream());
+ parser.setInput(new InputStreamReader(Channels.newInputStream(socket)));
+ writer = new OutputStreamWriter(Channels.newOutputStream(socket));
parser.next(); // stream:stream
updateTsRemoteData();
@@ -61,10 +68,7 @@ public class ConnectionIn extends Connection implements Runnable {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
-
- if (XMPPComponent.LOGFILE != null) {
- logParser();
- }
+ logParser();
packetsRemote++;
@@ -72,7 +76,7 @@ public class ConnectionIn extends Connection implements Runnable {
if (tag.equals("db:result")) {
String dfrom = parser.getAttributeValue(null, "from");
String to = parser.getAttributeValue(null, "to");
- System.out.println("STREAM FROM " + dfrom + " TO " + to + " " + streamID + " ASKING FOR DIALBACK");
+ LOGGER.info("STREAM FROM " + dfrom + " TO " + to + " " + streamID + " ASKING FOR DIALBACK");
if (dfrom.endsWith(XMPPComponent.HOSTNAME) && (dfrom.equals(XMPPComponent.HOSTNAME) || dfrom.endsWith("." + XMPPComponent.HOSTNAME))) {
break;
}
@@ -103,10 +107,10 @@ public class ConnectionIn extends Connection implements Runnable {
}
if (valid) {
sendStanza("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='valid'/>");
- System.out.println("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY VALID");
+ LOGGER.info("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY VALID");
} else {
sendStanza("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='invalid'/>");
- System.err.println("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID");
+ LOGGER.warning("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID");
}
} else if (tag.equals("presence") && checkFromTo(parser)) {
Presence p = Presence.parse(parser, null);
@@ -117,7 +121,7 @@ public class ConnectionIn extends Connection implements Runnable {
updateTsRemoteData();
Message msg = Message.parse(parser, XMPPComponent.childParsers);
if (msg != null && (msg.type == null || !msg.type.equals(Message.Type.error))) {
- System.out.println("STREAM " + streamID + ": " + msg.toString());
+ LOGGER.info("STREAM " + streamID + ": " + msg.toString());
if (!JuickBot.incomingMessage(msg)) {
XMPPComponent.connRouter.sendStanza(msg.toString());
}
@@ -127,18 +131,22 @@ public class ConnectionIn extends Connection implements Runnable {
String type = parser.getAttributeValue(null, "type");
String xml = XmlUtils.parseToString(parser, true);
if (type == null || !type.equals(Iq.Type.error)) {
- System.out.println("STREAM " + streamID + ": " + xml);
+ LOGGER.info("STREAM " + streamID + ": " + xml);
XMPPComponent.connRouter.sendStanza(xml);
}
} else {
- System.out.println("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true));
+ LOGGER.info("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true));
}
}
- System.err.println("STREAM " + streamID + " FINISHED");
+ LOGGER.warning("STREAM " + streamID + " FINISHED");
+ XMPPComponent.removeConnectionIn(this);
+ closeConnection();
+ } catch (EOFException ex) {
+ LOGGER.info(String.format("STREAM %s CLOSED (dirty)", streamID));
XMPPComponent.removeConnectionIn(this);
closeConnection();
} catch (Exception e) {
- System.err.println("STREAM " + streamID + " ERROR:" + e.toString());
+ LOGGER.warning("STREAM " + streamID + " ERROR:" + e.toString());
e.printStackTrace();
XMPPComponent.removeConnectionIn(this);
closeConnection();
@@ -154,10 +162,10 @@ public class ConnectionIn extends Connection implements Runnable {
sendStanza("<db:result from='" + XMPPComponent.HOSTNAME + "' to='" + sfrom + "' type='" + type + "'/>");
if (type.equals("valid")) {
from.add(sfrom);
- System.out.println("STREAM FROM " + sfrom + " " + streamID + " READY");
+ LOGGER.info("STREAM FROM " + sfrom + " " + streamID + " READY");
}
} catch (IOException e) {
- System.err.println("STREAM FROM " + sfrom + " " + streamID + " ERROR: " + e.toString());
+ LOGGER.warning("STREAM FROM " + sfrom + " " + streamID + " ERROR: " + e.toString());
}
}
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java
index f29b8d095..982f2efca 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionListener.java
@@ -1,28 +1,49 @@
package com.juick.xmpp.s2s;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
+import java.net.InetSocketAddress;
+import java.nio.channels.AsynchronousServerSocketChannel;
+import java.nio.channels.AsynchronousSocketChannel;
+import java.nio.channels.CompletionHandler;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
*
- * @author ugnich
+ * @author vt
*/
public class ConnectionListener implements Runnable {
+ private static final Logger logger = Logger.getLogger(ConnectionListener.class.getName());
+
+ ExecutorService connectionPool;
+
@Override
public void run() {
try {
- ServerSocket listener = new ServerSocket(5269);
- while (true) {
- Socket sock = listener.accept();
- ConnectionIn conn = new ConnectionIn(sock);
- XMPPComponent.addConnectionIn(conn);
- Thread t = new Thread(conn);
- t.start();
- }
- } catch (IOException e) {
- System.out.println("IOException on socket listen: " + e.toString());
+ connectionPool = Executors.newCachedThreadPool();
+ final AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open();
+ listener.bind(new InetSocketAddress(5269));
+ logger.info("s2s listener ready");
+ listener.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() {
+ @Override
+ public void completed(AsynchronousSocketChannel result, Object attachment) {
+ listener.accept(connectionPool, this);
+ ConnectionIn client = new ConnectionIn(result);
+ XMPPComponent.addConnectionIn(client);
+ connectionPool.submit(client);
+ }
+
+ @Override
+ public void failed(Throwable exc, Object attachment) {
+
+ }
+ });
+ Thread.currentThread().join();
+ listener.close();
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "s2s listener exception", e);
}
}
}
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
index 2626b926d..8e5438431 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java
@@ -4,7 +4,11 @@ import com.juick.xmpp.utils.XmlUtils;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
+import java.net.InetSocketAddress;
import java.net.Socket;
+import java.nio.channels.AsynchronousSocketChannel;
+import java.nio.channels.Channels;
+
import org.xmlpull.v1.XmlPullParser;
/**
@@ -32,14 +36,15 @@ public class ConnectionOut extends Connection implements Runnable {
@Override
public void run() {
- System.out.println("STREAM TO " + to + " START");
+ LOGGER.info("STREAM TO " + to + " START");
try {
HostnamePort addr = DNSQueries.getServerAddress(to);
- socket = new Socket(addr.hostname, addr.port);
+ socket = AsynchronousSocketChannel.open();
+ socket.connect(new InetSocketAddress(addr.hostname, addr.port));
- parser.setInput(new InputStreamReader(socket.getInputStream()));
- writer = new OutputStreamWriter(socket.getOutputStream());
+ parser.setInput(new InputStreamReader(Channels.newInputStream(socket)));
+ writer = new OutputStreamWriter(Channels.newOutputStream(socket));
sendStanza("<?xml version='1.0'?><stream:stream xmlns='jabber:server' " +
"xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" +
@@ -51,7 +56,7 @@ public class ConnectionOut extends Connection implements Runnable {
throw new Exception("STREAM TO " + to + " INVALID FIRST PACKET");
}
- System.out.println("STREAM TO " + to + " " + streamID + " OPEN");
+ LOGGER.info("STREAM TO " + to + " " + streamID + " OPEN");
XMPPComponent.addConnectionOut(this);
if (checkSID != null) {
@@ -64,26 +69,23 @@ public class ConnectionOut extends Connection implements Runnable {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
-
- if (XMPPComponent.LOGFILE != null) {
- logParser();
- }
+ logParser();
String tag = parser.getName();
if (tag.equals("db:result")) {
String type = parser.getAttributeValue(null, "type");
if (type != null && type.equals("valid")) {
streamReady = true;
- System.out.println("STREAM TO " + to + " " + streamID + " READY");
+ LOGGER.info("STREAM TO " + to + " " + streamID + " READY");
String cache = XMPPComponent.getFromCache(to);
if (cache != null) {
- System.out.println("STREAM TO " + to + " " + streamID + " SENDING CACHE");
+ LOGGER.info("STREAM TO " + to + " " + streamID + " SENDING CACHE");
sendStanza(cache);
}
} else {
- System.out.println("STREAM TO " + to + " " + streamID + " DIALBACK FAIL");
+ LOGGER.info("STREAM TO " + to + " " + streamID + " DIALBACK FAIL");
}
XmlUtils.skip(parser);
} else if (tag.equals("db:verify")) {
@@ -98,15 +100,15 @@ public class ConnectionOut extends Connection implements Runnable {
}
XmlUtils.skip(parser);
} else {
- System.out.println("STREAM TO " + to + " " + streamID + ": " + XmlUtils.parseToString(parser, true));
+ LOGGER.info("STREAM TO " + to + " " + streamID + ": " + XmlUtils.parseToString(parser, true));
}
}
- System.err.println("STREAM TO " + to + " " + streamID + " FINISHED");
+ LOGGER.warning("STREAM TO " + to + " " + streamID + " FINISHED");
XMPPComponent.removeConnectionOut(this);
closeConnection();
} catch (Exception e) {
- System.err.println(e.toString());
+ LOGGER.warning(e.toString());
XMPPComponent.removeConnectionOut(this);
closeConnection();
}
@@ -116,7 +118,7 @@ public class ConnectionOut extends Connection implements Runnable {
try {
sendStanza("<db:verify from='" + XMPPComponent.HOSTNAME + "' to='" + to + "' id='" + sid + "'>" + key + "</db:verify>");
} catch (IOException e) {
- System.err.println("STREAM TO " + to + " " + streamID + " ERROR: " + e.toString());
+ LOGGER.warning("STREAM TO " + to + " " + streamID + " ERROR: " + e.toString());
}
}
}
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java b/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
index d8ce0daff..ccd6a3359 100644
--- a/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
+++ b/src/main/java/com/juick/xmpp/s2s/ConnectionRouter.java
@@ -9,15 +9,16 @@ import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
import com.juick.xmpp.utils.SHA1;
import com.juick.xmpp.utils.XmlUtils;
+import org.xmlpull.v1.XmlPullParser;
+
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.net.Socket;
-import java.util.ArrayList;
+import java.net.InetSocketAddress;
+import java.nio.channels.AsynchronousSocketChannel;
+import java.nio.channels.Channels;
import java.util.List;
-import org.xmlpull.v1.XmlPullParser;
-
/**
*
* @author ugnich
@@ -26,13 +27,14 @@ public class ConnectionRouter extends Connection implements Runnable {
@Override
public void run() {
- System.out.println("STREAM ROUTER START");
+ LOGGER.info("STREAM ROUTER START");
try {
- socket = new Socket("localhost", 5347);
- parser.setInput(new InputStreamReader(socket.getInputStream()));
+ socket = AsynchronousSocketChannel.open();
+ socket.connect(new InetSocketAddress(5347));
+ parser.setInput(new InputStreamReader(Channels.newInputStream(socket)));
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- writer = new OutputStreamWriter(socket.getOutputStream());
+ writer = new OutputStreamWriter(Channels.newOutputStream(socket));
String msg = "<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' to='s2s'>";
writer.write(msg);
@@ -53,7 +55,7 @@ public class ConnectionRouter extends Connection implements Runnable {
throw new Exception("NO HANDSHAKE");
}
XmlUtils.skip(parser);
- System.out.println("STREAM ROUTER OPEN");
+ LOGGER.info("STREAM ROUTER OPEN");
while (parser.next() != XmlPullParser.END_DOCUMENT) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
@@ -68,7 +70,7 @@ public class ConnectionRouter extends Connection implements Runnable {
if (jid.Host.equals(XMPPComponent.COMPONENTNAME)) {
if (tag.equals("message")) {
Message xmsg = Message.parse(parser, XMPPComponent.childParsers);
- System.out.println("STREAM ROUTER (PROCESS): " + xmsg.toString());
+ LOGGER.info("STREAM ROUTER (PROCESS): " + xmsg.toString());
JuickMessage jmsg = (JuickMessage) xmsg.getChild(JuickMessage.XMLNS);
if (jmsg != null) {
if (jid.Username != null && jid.Username.equals("recomm")) {
@@ -84,23 +86,23 @@ public class ConnectionRouter extends Connection implements Runnable {
}
} else if (jid.Host.endsWith(XMPPComponent.HOSTNAME) && (jid.Host.equals(XMPPComponent.HOSTNAME) || jid.Host.endsWith("." + XMPPComponent.HOSTNAME))) {
String xml = XmlUtils.parseToString(parser, true);
- System.out.println("STREAM ROUTER: " + xml);
+ LOGGER.info("STREAM ROUTER: " + xml);
} else {
String xml = XmlUtils.parseToString(parser, true);
- System.out.println("STREAM ROUTER (OUT): " + xml);
+ LOGGER.info("STREAM ROUTER (OUT): " + xml);
XMPPComponent.sendOut(jid.Host, xml);
}
} else {
- System.out.println("STREAM ROUTER (NO TO): " + XmlUtils.parseToString(parser, true));
+ LOGGER.info("STREAM ROUTER (NO TO): " + XmlUtils.parseToString(parser, true));
}
} else {
- System.out.println("STREAM ROUTER: " + XmlUtils.parseToString(parser, true));
+ LOGGER.info("STREAM ROUTER: " + XmlUtils.parseToString(parser, true));
}
}
- System.err.println("STREAM ROUTER FINISHED");
+ LOGGER.warning("STREAM ROUTER FINISHED");
} catch (Exception e) {
- System.err.println("STREAM ROUTER PARSE ERROR: " + e.toString());
+ LOGGER.warning("STREAM ROUTER PARSE ERROR: " + e.toString());
}
System.exit(0);
}
@@ -111,8 +113,8 @@ public class ConnectionRouter extends Connection implements Runnable {
writer.write(xml);
writer.flush();
} catch (IOException e) {
- System.err.println("STREAM ROUTER ERROR: " + xml);
- System.err.println("STREAM ROUTER ERROR: " + e.toString());
+ LOGGER.warning("STREAM ROUTER ERROR: " + xml);
+ LOGGER.warning("STREAM ROUTER ERROR: " + e.toString());
System.exit(0);
}
}
diff --git a/src/main/java/com/juick/xmpp/s2s/Shutdown.java b/src/main/java/com/juick/xmpp/s2s/Shutdown.java
deleted file mode 100644
index fb3543f81..000000000
--- a/src/main/java/com/juick/xmpp/s2s/Shutdown.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.juick.xmpp.s2s;
-
-import java.sql.SQLException;
-import java.util.Iterator;
-
-/**
- *
- * @author ugnich
- */
-public class Shutdown extends Thread {
-
- @Override
- public void run() {
- System.out.println("SHUTTING DOWN");
-
- 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) {
- System.err.println("SQL ERROR: " + e);
- }
- }
- }
- }
-}
diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java
index ff4ec3e68..bb5f5ef78 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();