use of org.apache.sling.api.resource.observation.ResourceChangeListener in project sling by apache.
the class ResourceChangeListenerWhiteboard method activate.
public void activate(final BundleContext bundleContext, final ResourceProviderTracker resourceProviderTracker, final String[] searchPath) {
this.searchPath = searchPath;
this.resourceProviderTracker = resourceProviderTracker;
this.resourceProviderTracker.setObservationReporterGenerator(this);
this.tracker = new ServiceTracker<>(bundleContext, ResourceChangeListener.class, new ServiceTrackerCustomizer<ResourceChangeListener, ServiceReference<ResourceChangeListener>>() {
@Override
public void removedService(final ServiceReference<ResourceChangeListener> reference, final ServiceReference<ResourceChangeListener> service) {
final ResourceChangeListenerInfo info = listeners.remove(reference);
if (info != null) {
updateProviderTracker();
}
}
@Override
public void modifiedService(final ServiceReference<ResourceChangeListener> reference, final ServiceReference<ResourceChangeListener> service) {
removedService(reference, service);
addingService(reference);
}
@Override
public ServiceReference<ResourceChangeListener> addingService(final ServiceReference<ResourceChangeListener> reference) {
final ResourceChangeListenerInfo info = new ResourceChangeListenerInfo(reference, searchPath);
if (info.isValid()) {
final ResourceChangeListener listener = bundleContext.getService(reference);
if (listener != null) {
info.setListener(listener);
listeners.put(reference, info);
updateProviderTracker();
}
} else {
logger.warn("Ignoring invalid resource change listenr {}", reference);
}
return reference;
}
});
this.tracker.open();
}
use of org.apache.sling.api.resource.observation.ResourceChangeListener in project sling by apache.
the class BasicObservationReporter method reportChanges.
@Override
public void reportChanges(final ObserverConfiguration config, final Iterable<ResourceChange> changes, final boolean distribute) {
if (config != null && config instanceof BasicObserverConfiguration) {
final BasicObserverConfiguration observerConfig = (BasicObserverConfiguration) config;
ResourceChangeListenerInfo previousInfo = null;
List<ResourceChange> filteredChanges = null;
for (final ResourceChangeListenerInfo info : observerConfig.getListeners()) {
if (previousInfo == null || !equals(previousInfo, info)) {
filteredChanges = filterChanges(changes, info);
previousInfo = info;
}
if (!filteredChanges.isEmpty()) {
final ResourceChangeListener listener = info.getListener();
if (listener != null) {
listener.onChange(filteredChanges);
}
}
}
// TODO implement distribute
if (distribute) {
logger.error("Distrubte flag is send for observation events, however distribute is currently not implemented!");
}
}
}
Aggregations