diff options
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/ConnectionOut.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/ConnectionOut.java | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java b/src/main/java/com/juick/xmpp/s2s/ConnectionOut.java index 2626b926..8e543843 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()); } } } |