Search in sources :

Example 1 with EventFilter

use of org.apache.jackrabbit.spi.EventFilter in project jackrabbit by apache.

the class ObservationManagerImpl method onEvent.

public void onEvent(EventBundle eventBundle) {
    // get active listeners
    Map<EventListener, EventFilter> activeListeners;
    synchronized (subscriptions) {
        ensureReadOnlyMap();
        activeListeners = readOnlySubscriptions;
    }
    for (Map.Entry<EventListener, EventFilter> entry : activeListeners.entrySet()) {
        EventListener listener = entry.getKey();
        EventFilter filter = entry.getValue();
        FilteredEventIterator eventIter = new FilteredEventIterator(eventBundle.getEvents(), eventBundle.isLocal(), filter, resolver, wspManager.getIdFactory());
        if (eventIter.hasNext()) {
            try {
                listener.onEvent(eventIter);
            } catch (Throwable t) {
                log.warn("EventConsumer threw exception: " + t.toString());
                log.debug("Stacktrace: ", t);
            // move on to the next listener
            }
        }
    }
}
Also used : EventListener(javax.jcr.observation.EventListener) EventFilter(org.apache.jackrabbit.spi.EventFilter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with EventFilter

use of org.apache.jackrabbit.spi.EventFilter in project jackrabbit by apache.

the class EventSubscription method setFilters.

/**
     * Sets a new list of event filters for this subscription.
     *
     * @param filters the new filters.
     * @throws RepositoryException if the filters array contains a unknown
     *                             implementation of EventFilters.
     */
void setFilters(EventFilter[] filters) throws RepositoryException {
    // check type
    for (EventFilter filter : filters) {
        if (!(filter instanceof EventFilterImpl)) {
            throw new RepositoryException("Unknown filter implementation");
        }
    }
    List<EventFilter> tmp = new ArrayList<EventFilter>(Arrays.asList(filters));
    this.filters = Collections.unmodifiableList(tmp);
}
Also used : EventFilterImpl(org.apache.jackrabbit.spi.commons.EventFilterImpl) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) EventFilter(org.apache.jackrabbit.spi.EventFilter)

Example 3 with EventFilter

use of org.apache.jackrabbit.spi.EventFilter in project jackrabbit by apache.

the class ObservationManagerImpl method addEventListener.

public void addEventListener(EventListener listener, int eventTypes, String absPath, boolean isDeep, String[] uuids, String[] nodeTypeNames, boolean noLocal) throws RepositoryException {
    EventFilter filter = createEventFilter(eventTypes, absPath, isDeep, uuids, nodeTypeNames, noLocal);
    synchronized (subscriptions) {
        subscriptions.put(listener, filter);
        readOnlySubscriptions = null;
    }
    if (subscriptions.size() == 1) {
        wspManager.addEventListener(this);
    } else {
        wspManager.updateEventFilters();
    }
}
Also used : EventFilter(org.apache.jackrabbit.spi.EventFilter)

Example 4 with EventFilter

use of org.apache.jackrabbit.spi.EventFilter in project jackrabbit by apache.

the class EventSubscription method getEventBundles.

/**
     * @return all the pending event bundles.
     */
EventBundle[] getEventBundles(long timeout) {
    EventBundle[] bundles;
    synchronized (eventBundles) {
        if (eventBundles.isEmpty()) {
            try {
                eventBundles.wait(timeout);
            } catch (InterruptedException e) {
            // continue
            }
        }
        bundles = eventBundles.toArray(new EventBundle[eventBundles.size()]);
        eventBundles.clear();
    }
    EventFilter[] eventFilters = filters.toArray(new EventFilter[filters.size()]);
    // apply filters to bundles
    for (int i = 0; i < bundles.length; i++) {
        List<Event> filteredEvents = new ArrayList<Event>();
        for (Iterator<Event> it = bundles[i].getEvents(); it.hasNext(); ) {
            Event e = it.next();
            // TODO: this is actually not correct. if filters are empty no event should go out
            if (eventFilters == null || eventFilters.length == 0) {
                filteredEvents.add(e);
            } else {
                for (EventFilter eventFilter : eventFilters) {
                    if (eventFilter.accept(e, bundles[i].isLocal())) {
                        filteredEvents.add(e);
                        break;
                    }
                }
            }
        }
        bundles[i] = new EventBundleImpl(filteredEvents, bundles[i].isLocal());
    }
    return bundles;
}
Also used : EventBundleImpl(org.apache.jackrabbit.spi.commons.EventBundleImpl) ArrayList(java.util.ArrayList) Event(org.apache.jackrabbit.spi.Event) EventBundle(org.apache.jackrabbit.spi.EventBundle) EventFilter(org.apache.jackrabbit.spi.EventFilter)

Aggregations

EventFilter (org.apache.jackrabbit.spi.EventFilter)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RepositoryException (javax.jcr.RepositoryException)1 EventListener (javax.jcr.observation.EventListener)1 Event (org.apache.jackrabbit.spi.Event)1 EventBundle (org.apache.jackrabbit.spi.EventBundle)1 EventBundleImpl (org.apache.jackrabbit.spi.commons.EventBundleImpl)1 EventFilterImpl (org.apache.jackrabbit.spi.commons.EventFilterImpl)1