From: erickson Date: Sat, 28 Jul 2007 17:41:32 +0000 (+0000) Subject: synchronizing the initial xmpp login to prevent thread race condition on authentication X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f154c49e7f18b2f12d1ea724b7230621e7886665;p=opensrf%2Fbjwebb.git synchronizing the initial xmpp login to prevent thread race condition on authentication git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1064 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/java/org/opensrf/net/xmpp/XMPPSession.java b/src/java/org/opensrf/net/xmpp/XMPPSession.java index e8b639e..11e0c7d 100644 --- a/src/java/org/opensrf/net/xmpp/XMPPSession.java +++ b/src/java/org/opensrf/net/xmpp/XMPPSession.java @@ -113,29 +113,33 @@ public class XMPPSession { thread.setDaemon(true); thread.start(); - /* send the initial jabber message */ - sendConnect(); - reader.waitCoreEvent(10000); + synchronized(reader) { + /* send the initial jabber message */ + sendConnect(); + reader.waitCoreEvent(10000); + } if( reader.getXMPPStreamState() != XMPPReader.XMPPStreamState.CONNECT_RECV ) throw new XMPPException("unable to connect to jabber server"); - /* send the basic auth message */ - sendBasicAuth(); /* XXX add support for other auth mechanisms */ - reader.waitCoreEvent(10000); - if(!connected()) + synchronized(reader) { + /* send the basic auth message */ + sendBasicAuth(); + reader.waitCoreEvent(10000); + } + if(!connected()) throw new XMPPException("Authentication failed"); } /** Sends the initial jabber message */ private void sendConnect() { - writer.printf(JABBER_CONNECT, host); reader.setXMPPStreamState(XMPPReader.XMPPStreamState.CONNECT_SENT); + writer.printf(JABBER_CONNECT, host); } /** Send the basic auth message */ private void sendBasicAuth() { - writer.printf(JABBER_BASIC_AUTH, username, password, resource); reader.setXMPPStreamState(XMPPReader.XMPPStreamState.AUTH_SENT); + writer.printf(JABBER_BASIC_AUTH, username, password, resource); }