use of org.apache.jackrabbit.spi.EventBundle in project jackrabbit by apache.
the class WorkspaceManager method onEventReceived.
// --------------------------------------------------------------------------
/**
* Called when local or external events occurred. This method is called after
* changes have been applied to the repository.
*
* @param eventBundles the event bundles generated by the repository service
* as the effect of an local or external change.
* @param lstnrs Array of internal event listeners
* @throws InterruptedException if this thread is interrupted while waiting
* for the {@link #updateSync}.
*/
private void onEventReceived(EventBundle[] eventBundles, InternalEventListener[] lstnrs) throws InterruptedException {
if (log.isDebugEnabled()) {
log.debug("received {} event bundles.", eventBundles.length);
for (EventBundle eventBundle : eventBundles) {
log.debug("IsLocal: {}", eventBundle.isLocal());
for (Iterator<Event> it = eventBundle.getEvents(); it.hasNext(); ) {
Event e = it.next();
String type;
switch(e.getType()) {
case Event.NODE_ADDED:
type = "NodeAdded";
break;
case Event.NODE_REMOVED:
type = "NodeRemoved";
break;
case Event.PROPERTY_ADDED:
type = "PropertyAdded";
break;
case Event.PROPERTY_CHANGED:
type = "PropertyChanged";
break;
case Event.PROPERTY_REMOVED:
type = "PropertyRemoved";
break;
case Event.NODE_MOVED:
type = "NodeMoved";
break;
case Event.PERSIST:
type = "Persist";
break;
default:
type = "Unknown";
}
log.debug(" {}; {}", e.getPath(), type);
}
}
}
// do not deliver events while an operation executes
updateSync.acquire();
try {
// notify listener
for (EventBundle eventBundle : eventBundles) {
for (InternalEventListener lstnr : lstnrs) {
try {
lstnr.onEvent(eventBundle);
} catch (Exception e) {
log.warn("Exception in event polling thread: " + e);
log.debug("Dump:", e);
}
}
}
} finally {
updateSync.release();
}
}
use of org.apache.jackrabbit.spi.EventBundle in project jackrabbit by apache.
the class EventSubscription method createEventBundle.
// --------------------------------< internal >------------------------------
private void createEventBundle(javax.jcr.observation.EventIterator events, boolean isLocal) {
// do not create events when disposed
if (disposed) {
return;
}
List<Event> spiEvents = new ArrayList<Event>();
while (events.hasNext()) {
try {
Event spiEvent = eventFactory.fromJCREvent(events.nextEvent());
spiEvents.add(spiEvent);
} catch (Exception ex) {
log.warn("Unable to create SPI Event: " + ex);
}
}
EventBundle bundle = new EventBundleImpl(spiEvents, isLocal);
synchronized (eventBundles) {
eventBundles.add(bundle);
eventBundles.notify();
}
}
use of org.apache.jackrabbit.spi.EventBundle in project jackrabbit by apache.
the class EventJournalImpl method refill.
// ----------------------------< internal >----------------------------------
private void refill() {
try {
EventBundle bundle = wspMgr.getEvents(filter, lastTimestamp);
for (Event e : bundle) {
buffer.add(e);
lastTimestamp = e.getDate();
}
} catch (RepositoryException e) {
log.warn("Exception while refilling event journal buffer", e);
}
}
use of org.apache.jackrabbit.spi.EventBundle 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();
}
}
}
use of org.apache.jackrabbit.spi.EventBundle 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