Search in sources :

Example 36 with ResourceChange

use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.

the class JobSchedulerImpl method onChange.

/**
     * @see org.apache.sling.api.resource.observation.ResourceChangeListener#onChange(java.util.List)
     */
@Override
public void onChange(List<ResourceChange> changes) {
    for (final ResourceChange change : changes) {
        if (change.getPath() != null && change.getPath().startsWith(this.configuration.getScheduledJobsPath(true))) {
            if (change.getType() == ResourceChange.ChangeType.REMOVED) {
                // removal
                logger.debug("Remove scheduled job {}", change.getPath());
                this.scheduledJobHandler.handleRemove(change.getPath());
            } else {
                // add or update
                logger.debug("Add or update scheduled job {}, event {}", change.getPath(), change.getType());
                this.scheduledJobHandler.handleAddUpdate(change.getPath());
            }
        }
    }
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange)

Example 37 with ResourceChange

use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.

the class ScriptCacheImpl method onChange.

@Override
public void onChange(@Nonnull List<ResourceChange> list) {
    for (final ResourceChange change : list) {
        Runnable eventTask = new Runnable() {

            @Override
            public void run() {
                String path = change.getPath();
                writeLock.lock();
                try {
                    final boolean removed = internalMap.remove(path) != null;
                    LOGGER.debug("Detected script change for {} - removed entry from the cache.", path);
                    if (!removed && change.getType() == ChangeType.REMOVED) {
                        final String prefix = path + "/";
                        final Set<String> removal = new HashSet<>();
                        for (final Map.Entry<String, SoftReference<CachedScript>> entry : internalMap.entrySet()) {
                            if (entry.getKey().startsWith(prefix)) {
                                removal.add(entry.getKey());
                            }
                        }
                        for (final String key : removal) {
                            internalMap.remove(key);
                            LOGGER.debug("Detected removal for {} - removed entry {} from the cache.", path, key);
                        }
                    }
                } finally {
                    writeLock.unlock();
                }
            }
        };
        threadPool.execute(eventTask);
    }
}
Also used : SoftReference(java.lang.ref.SoftReference) ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) CachingMap(org.apache.sling.scripting.core.impl.helper.CachingMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 38 with ResourceChange

use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.

the class XSSFilterImpl method onChange.

@Override
public void onChange(@Nonnull List<ResourceChange> resourceChanges) {
    for (ResourceChange change : resourceChanges) {
        if (change.getPath().endsWith(DEFAULT_POLICY_PATH)) {
            logger.info("Detected policy file change ({}) at {}. Updating default handler.", change.getType().name(), change.getPath());
            updateDefaultHandler();
        }
    }
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange)

Aggregations

ResourceChange (org.apache.sling.api.resource.observation.ResourceChange)38 Test (org.junit.Test)20 File (java.io.File)17 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 Event (org.osgi.service.event.Event)2 ImmutableList (com.google.common.collect.ImmutableList)1 SoftReference (java.lang.ref.SoftReference)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Event (javax.jcr.observation.Event)1 JackrabbitEvent (org.apache.jackrabbit.api.observation.JackrabbitEvent)1