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
}
}
}
}
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);
}
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();
}
}
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;
}
Aggregations