Search in sources :

Example 1 with MessageEvent

use of net.sourceforge.processdash.msg.MessageEvent in project processdash by dtuma.

the class MessageImporterXMLv1 method doImport.

private static void doImport(ArchiveMetricsFileImporter caller, InputStream in, boolean serverMode) throws Exception {
    // read the XML document from the input stream.
    InputStream xmlIn = new NonclosingInputStream(in);
    Document doc = XMLUtils.parse(xmlIn);
    Set<String> serverIDs = new HashSet();
    // Now, find all of the messages in the document
    NodeList messages = doc.getElementsByTagName(MESSAGE_TAG);
    if (messages != null) {
        for (int i = 0; i < messages.getLength(); i++) {
            Element msg = (Element) messages.item(i);
            MessageEvent msgEvent = new MessageEvent(msg);
            if (serverMode) {
                // handle server messages immediately, and keep track of
                // the server message IDs we've seen.
                MessageDispatcher.getInstance().dispatch(msgEvent, false);
                serverIDs.add(msgEvent.getServerId());
            } else {
                // Register a task to dispatch each message later on the
                // background thread.  (Message handling logic is defined
                // by third parties, and we have no guarantee that it will
                // finish in a timely manner.  We can't risk hanging the
                // import operation indefinitely.)
                BackgroundTaskManager.getInstance().addTask(new MessageDispatchTask(msgEvent));
            }
        }
    }
    NodeList nl = doc.getElementsByTagName(DELETE_TAG);
    if (nl != null && nl.getLength() > 0 && caller != null)
        caller.deleteArchiveFileOnCompletion();
    if (serverMode)
        MessageDispatcher.getInstance().setKnownServerMessagesIDs(serverIDs);
}
Also used : FileInputStream(java.io.FileInputStream) NonclosingInputStream(net.sourceforge.processdash.util.NonclosingInputStream) InputStream(java.io.InputStream) MessageEvent(net.sourceforge.processdash.msg.MessageEvent) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) NonclosingInputStream(net.sourceforge.processdash.util.NonclosingInputStream) Document(org.w3c.dom.Document) HashSet(java.util.HashSet)

Aggregations

FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 MessageEvent (net.sourceforge.processdash.msg.MessageEvent)1 NonclosingInputStream (net.sourceforge.processdash.util.NonclosingInputStream)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1