Example usage for javax.xml.ws AsyncHandler AsyncHandler

List of usage examples for javax.xml.ws AsyncHandler AsyncHandler

Introduction

In this page you can find the example usage for javax.xml.ws AsyncHandler AsyncHandler.

Prototype

AsyncHandler

Source Link

Usage

From source file:org.apache.cxf.cwiki.SiteExporter.java

public Future<?> loadPage(Element pageSumEl, final Set<String> allPages, final Set<Page> newPages)
        throws Exception {
    Document doc = DOMUtils.newDocument();
    Element el = doc.createElementNS(SOAPNS, "ns1:getPage");
    Element el2 = doc.createElement("in0");
    el.appendChild(el2);//from   w  w w  . j  a v  a 2  s  .  c  o  m
    el2.setTextContent(loginToken);
    el2 = doc.createElement("in1");
    el.appendChild(el2);
    el2.setTextContent(DOMUtils.getChildContent(pageSumEl, "id"));
    doc.appendChild(el);

    //make sure we only fire off about 15-20 or confluence may get a bit overloaded
    while (asyncCount.get() > 15) {
        Thread.sleep(10);
    }
    asyncCount.incrementAndGet();
    Future<?> f = getDispatch().invokeAsync(doc, new AsyncHandler<Document>() {
        public void handleResponse(Response<Document> doc) {
            try {
                Page page = new Page(doc.get(), SiteExporter.this);
                page.setExporter(SiteExporter.this);
                Page oldPage = pages.put(page.getId(), page);
                if (oldPage == null || page.getModifiedTime().compare(oldPage.getModifiedTime()) > 0) {
                    if (!modifiedPages.contains(page)) {
                        modifiedPages.add(page);
                    }
                    if (oldPage == null) {
                        //need to check parents to see if it has a {children} tag so we can re-render
                        newPages.add(page);
                    }
                }
                if (allPages.contains(page.getId())) {
                    allPages.remove(page.getId());
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                asyncCount.decrementAndGet();
            }
        }
    });
    return f;
}