use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class ProcessorManagerImpl method onChange.
@Override
public void onChange(final List<ResourceChange> changes) {
for (final ResourceChange change : changes) {
// check if the event handles something in the search paths
String path = change.getPath();
int foundPos = -1;
for (final String sPath : this.searchPath) {
if (path.startsWith(sPath)) {
foundPos = sPath.length();
break;
}
}
boolean handled = false;
if (foundPos != -1) {
// now check if this is a rewriter config
// relative path after the search path
final int firstSlash = path.indexOf('/', foundPos);
final int pattern = path.indexOf(CONFIG_PATH, foundPos);
// only if firstSlash and pattern are at the same position, this might be a rewriter config
if (firstSlash == pattern && firstSlash != -1) {
// the node should be a child of CONFIG_PATH
if (path.length() > pattern + CONFIG_PATH.length() && path.charAt(pattern + CONFIG_PATH.length()) == '/') {
// if a child resource is changed, make sure we have the correct path
final int slashPos = path.indexOf('/', pattern + CONFIG_PATH.length() + 1);
if (slashPos != -1) {
path = path.substring(0, slashPos);
}
// we should do the update async as we don't want to block the event delivery
final String configPath = path;
final Thread t = new Thread() {
@Override
public void run() {
if (change.getType() == ChangeType.REMOVED) {
removeProcessor(configPath);
} else {
updateProcessor(configPath);
}
}
};
t.start();
handled = true;
}
}
}
if (!handled && change.getType() == ChangeType.REMOVED) {
final Thread t = new Thread() {
@Override
public void run() {
checkRemoval(change.getPath());
}
};
t.start();
}
}
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class BasicObservationReporter method filterChanges.
/**
* Filter the change list based on the resource change listener, only type and external needs to be checkd.
* @param changes The list of changes
* @param config The resource change listener info
* @return The filtered list.
*/
private List<ResourceChange> filterChanges(final Iterable<ResourceChange> changes, final ResourceChangeListenerInfo config) {
final ResourceChangeListImpl filtered = new ResourceChangeListImpl(this.searchPath);
for (final ResourceChange c : changes) {
if (matches(c, config)) {
filtered.add(c);
}
}
filtered.lock();
return filtered;
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class ResourceProviderTracker method postResourceProviderChange.
/**
* Post a change event for a resource provider change
* @param type The change type
* @param info The resource provider
*/
private void postResourceProviderChange(final ProviderEvent event) {
final ObservationReporter or = this.providerReporter;
if (or != null) {
final ResourceChange change = new ResourceChange(event.isAdd ? ChangeType.PROVIDER_ADDED : ChangeType.PROVIDER_REMOVED, event.path, false);
or.reportChanges(Collections.singletonList(change), false);
}
}
use of org.apache.sling.api.resource.observation.ResourceChange 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!");
}
}
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class SlingServletResolver method onChange.
@Override
public void onChange(final List<ResourceChange> changes) {
boolean flushCache = false;
for (final ResourceChange change : changes) {
// if the path of the event is a sub path of a search path
// we flush the whole cache
final String path = change.getPath();
int index = 0;
while (!flushCache && index < searchPaths.length) {
if (path.startsWith(this.searchPaths[index])) {
flushCache = true;
}
index++;
}
if (flushCache) {
flushCache();
// we can stop looping
break;
}
}
}
Aggregations