czwartek, kwietnia 11, 2013

Massively parallel BW XML processing

1. Create Java Code parsing XML and finding appropriate nodes, with asynchronous requests creation and response handling:

Document doc = XmlHelper.getDocumentBuilder().parse(new InputSource(new StringReader(xml)));

List<Node> matchingParentNodes = XmlHelper.getNestedElementsByTagNs(doc, "http://namespace.example.com", "EntityNode");
int cnt = matchingParentNodes.size();
final CountDownLatch gate = new CountDownLatch(cnt);

for (Node node : matchingParentNodes) {
    final Message m = new Message();
    m.param1 = XmlHelper.getNodeValueNs(node, "Param1");
    m.cookie = node;
    m.requestReply(timeoutMillis, new MessageCallback() {
        @Override
        public void onMessage(Message resp) {
            Node owner = (Node) resp.cookie;
    XmlHelper.setNodeValueNs(owner, "Param2", resp.param2);
    gate.countDown();
        }
    });
}

gate.await(timeoutMillis, TimeUnit.MILLISECONDS);
if (gate.getCount() != 0)
    throw new RuntimeException("Not all subrequests "+gate.getCount()+" of "+matchingParentNodes.size()+" has been handled in given time "+timeoutMillis+"ms");

return XmlHelper.nodeToString(doc);

2. Java Event Starter reads Messages from LinkedBlockingQueue and handles single record.


0 komentarze: