private void init() {
        // Create a thread that will read and store DOM Elements.
        Thread thread = new Thread("Outgoing Server Reader") {
            @Override
            public void run() {
                while (open) {
                    Element doc;
                    try {
                        doc = reader.parseDocument().getRootElement();

                        if (doc == null) {
                            // Stop reading the stream since the remote server has sent an end of
                            // stream element and probably closed the connection.
                            closeSession();
                        }
                        else {
                            elements.add(doc);
                        }
                    }
                    catch (IOException e) {
                        String message = "Finishing Outgoing Server Reader. ";
                        if (session != null) {
                            message = message + "Closing session: " + session.toString();
                        }
                        else {
                            message = message + "No session to close.";
                        }
                        Log.debug("OutgoingServerSocketReader: "+message, e);
                        closeSession();
                    }
                    catch (Exception e) {
                        String message = "Finishing Outgoing Server Reader. ";
                        if (session != null) {
                            message = message + "Closing session: " + session.toString();
                        }
                        else {
                            message = message + "No session to close.";
                        }
                        Log.error(message, e);
                        closeSession();
                    }
                }
            }
        };
        thread.setDaemon(true);
        thread.start();
    }
Retrieves and removes the first received element that was stored in the queue, waiting
if necessary up to the specified wait time if no elements are present on this queue.

@param timeout how long to wait before giving up, in units of {@code unit}.
@param unit a {@code TimeUnit} determining how to interpret the {@code timeout} parameter.
@return the head of this queue, or {@code null} if the specified waiting time elapses
        before an element is present.
@throws InterruptedException if interrupted while waiting.
xmppserver/src/main/java/org/jivesoftware/openfire/server/OutgoingServerSocketReader.java