LP#1703411: Move OpenSRF XMPP attrs to subelement
[opensrf-equinox.git] / src / java / org / opensrf / net / xmpp / XMPPReader.java
index 3c06b11..cd620a6 100644 (file)
@@ -7,7 +7,7 @@ import java.util.Queue;
 import java.io.InputStream;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.Date;
-
+import org.opensrf.util.Logger;
 
 /**
  * Slim XMPP Stream reader.  This reader only understands enough XMPP
@@ -118,7 +118,7 @@ public class XMPPReader implements Runnable {
      * Each reader should have exactly one dependent session thread. 
      */
     private synchronized void notifyCoreEvent() {
-        notify();
+        notifyAll();
     }
 
 
@@ -133,11 +133,13 @@ public class XMPPReader implements Runnable {
     public synchronized long waitCoreEvent(long timeout) {
 
         if(msgQueue.peek() != null || timeout == 0) return 0;
-
         long start = new Date().getTime();
+
         try{
-            if(timeout < 0) wait();
-            else wait(timeout);
+            if(timeout < 0) 
+                wait();
+            else 
+                wait(timeout);
         } catch(InterruptedException ie) {}
 
         return new Date().getTime() - start;
@@ -153,7 +155,6 @@ public class XMPPReader implements Runnable {
 
     /**
      * Parses XML data from the provided XMPP stream.
-     * @param inStream The stream to parse.
      */
     public void read() {
 
@@ -208,6 +209,8 @@ public class XMPPReader implements Runnable {
                            msg.setBody(msgBody.toString());
                            msg.setThread(msgThread.toString());
 
+                           Logger.internal("xmpp message from="+msgFrom+" " + msg.getBody());
+
                            msgQueue.offer(msg);
                            resetBuffers(); 
                            notifyCoreEvent();
@@ -245,6 +248,14 @@ public class XMPPReader implements Runnable {
             return;
         }
 
+        if("opensrf".equals(name)) {
+            /** add a special case for the opensrf "router_from" attribute */
+            String rf = reader.getAttributeValue(null, "router_from");
+            if( rf != null )
+                msgFrom = rf;
+            return;
+        }
+
         if("body".equals(name)) {
             xmlState = XMLState.IN_BODY;
             return;