Search in sources :

Example 1 with EventDiscovery

use of org.apache.jackrabbit.webdav.observation.EventDiscovery in project jackrabbit by apache.

the class SubscriptionImpl method discoverEvents.

/**
 * Returns a {@link org.apache.jackrabbit.webdav.observation.EventDiscovery} object listing all events that were
 * recorded since the last call to this method and clears the list of event
 * bundles.
 *
 * @param timeout time in milliseconds to wait at most for events if none
 *                are present currently.
 * @return object listing all events that were recorded.
 * @see #onEvent(EventIterator)
 */
synchronized EventDiscovery discoverEvents(long timeout) {
    EventDiscovery ed = new EventDiscovery();
    if (eventBundles.isEmpty() && timeout > 0) {
        try {
            wait(timeout);
        } catch (InterruptedException e) {
        // continue and possibly return empty event discovery
        }
    }
    for (EventBundle eb : eventBundles) {
        ed.addEventBundle(eb);
    }
    // clear list
    eventBundles.clear();
    return ed;
}
Also used : EventDiscovery(org.apache.jackrabbit.webdav.observation.EventDiscovery) EventBundle(org.apache.jackrabbit.webdav.observation.EventBundle)

Example 2 with EventDiscovery

use of org.apache.jackrabbit.webdav.observation.EventDiscovery in project jackrabbit by apache.

the class RepositoryServiceImpl method poll.

private EventBundle[] poll(String uri, String subscriptionId, long timeout, SessionInfoImpl sessionInfo) throws RepositoryException {
    HttpPoll request = null;
    try {
        request = new HttpPoll(uri, subscriptionId, timeout);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        EventDiscovery disc = request.getResponseBodyAsEventDiscovery(response);
        EventBundle[] events;
        if (disc.isEmpty()) {
            events = new EventBundle[0];
        } else {
            Element discEl = disc.toXml(DomUtil.createDocument());
            ElementIterator it = DomUtil.getChildren(discEl, ObservationConstants.N_EVENTBUNDLE);
            List<EventBundle> bundles = new ArrayList<EventBundle>();
            while (it.hasNext()) {
                Element bundleElement = it.nextElement();
                String value = DomUtil.getAttribute(bundleElement, ObservationConstants.XML_EVENT_LOCAL, null);
                // check if it matches a batch id recently submitted
                boolean isLocal = false;
                if (value != null) {
                    isLocal = Boolean.parseBoolean(value);
                }
                bundles.add(new EventBundleImpl(buildEventList(bundleElement, sessionInfo, uri), isLocal));
            }
            events = bundles.toArray(new EventBundle[bundles.size()]);
        }
        return events;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (ParserConfigurationException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) EventBundle(org.apache.jackrabbit.spi.EventBundle) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) HttpPoll(org.apache.jackrabbit.webdav.client.methods.HttpPoll) EventDiscovery(org.apache.jackrabbit.webdav.observation.EventDiscovery) EventBundleImpl(org.apache.jackrabbit.spi.commons.EventBundleImpl) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with EventDiscovery

use of org.apache.jackrabbit.webdav.observation.EventDiscovery in project jackrabbit by apache.

the class AbstractWebdavServlet method doPoll.

/**
 * The POLL method
 *
 * @param request
 * @param response
 * @param resource
 * @throws IOException
 * @throws DavException
 */
protected void doPoll(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    if (!(resource instanceof ObservationResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    EventDiscovery ed = ((ObservationResource) resource).poll(request.getSubscriptionId(), request.getPollTimeout());
    response.sendPollResponse(ed);
}
Also used : EventDiscovery(org.apache.jackrabbit.webdav.observation.EventDiscovery) ObservationResource(org.apache.jackrabbit.webdav.observation.ObservationResource)

Aggregations

EventDiscovery (org.apache.jackrabbit.webdav.observation.EventDiscovery)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 HttpResponse (org.apache.http.HttpResponse)1 EventBundle (org.apache.jackrabbit.spi.EventBundle)1 EventBundleImpl (org.apache.jackrabbit.spi.commons.EventBundleImpl)1 DavException (org.apache.jackrabbit.webdav.DavException)1 HttpPoll (org.apache.jackrabbit.webdav.client.methods.HttpPoll)1 EventBundle (org.apache.jackrabbit.webdav.observation.EventBundle)1 ObservationResource (org.apache.jackrabbit.webdav.observation.ObservationResource)1 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)1 Element (org.w3c.dom.Element)1