Search in sources :

Example 31 with ResourceChange

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

the class FileMonitorTest method testUpdateFile.

@Test
public void testUpdateFile() throws Exception {
    List<ResourceChange> changes = resourceListener.getChanges();
    assertTrue(changes.isEmpty());
    File file1a = new File(tempDir, "folder1/file1a.txt");
    FileUtils.touch(file1a);
    Thread.sleep(WAIT_INTERVAL);
    assertEquals(1, changes.size());
    assertChange(changes, "/fs-test/folder1/file1a.txt", ChangeType.CHANGED);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Example 32 with ResourceChange

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

the class FileMonitorTest method testRemoveContent.

@Test
public void testRemoveContent() throws Exception {
    List<ResourceChange> changes = resourceListener.getChanges();
    assertTrue(changes.isEmpty());
    File file1a = new File(tempDir, "folder2/content.json");
    file1a.delete();
    Thread.sleep(WAIT_INTERVAL);
    assertEquals(2, changes.size());
    assertChange(changes, "/fs-test/folder2", ChangeType.CHANGED);
    assertChange(changes, "/fs-test/folder2/content", ChangeType.REMOVED);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Example 33 with ResourceChange

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

the class FileVaultFileMonitorTest method testRemoveContentDotXmlOnly.

@Test
public void testRemoveContentDotXmlOnly() throws Exception {
    List<ResourceChange> changes = resourceListener.getChanges();
    assertTrue(changes.isEmpty());
    File file = new File(tempDir, "jcr_root/content/samples/en/.content.xml");
    file.delete();
    Thread.sleep(WAIT_INTERVAL);
    assertEquals(2, changes.size());
    assertChange(changes, "/content/samples/en", ChangeType.CHANGED);
    // this second event is not fully correct, but this is a quite special case, accept it for now 
    assertChange(changes, "/content/samples/en", ChangeType.REMOVED);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Example 34 with ResourceChange

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

the class FileMonitorTest method testAddContent.

@Test
public void testAddContent() throws Exception {
    List<ResourceChange> changes = resourceListener.getChanges();
    assertTrue(changes.isEmpty());
    File file1c = new File(tempDir, "folder1/file1c.json");
    FileUtils.write(file1c, "{\"prop1\":\"value1\",\"child1\":{\"prop2\":\"value1\"}}");
    Thread.sleep(WAIT_INTERVAL);
    assertEquals(3, changes.size());
    assertChange(changes, "/fs-test/folder1", ChangeType.CHANGED);
    assertChange(changes, "/fs-test/folder1/file1c", ChangeType.ADDED);
    assertChange(changes, "/fs-test/folder1/file1c/child1", ChangeType.ADDED);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Example 35 with ResourceChange

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

the class ResourceBackedPojoChangeMonitor method onChange.

@Override
public void onChange(@Nonnull List<ResourceChange> changes) {
    for (ResourceChange change : changes) {
        String path = change.getPath();
        ResourceChange.ChangeType changeType = change.getType();
        switch(changeType) {
            case CHANGED:
                if (slyJavaUseMap.containsKey(path)) {
                    slyJavaUseMap.put(path, System.currentTimeMillis());
                }
                break;
            case REMOVED:
                if (slyJavaUseMap.containsKey(path)) {
                    slyJavaUseMap.remove(path);
                }
                break;
            default:
                break;
        }
        LOG.debug("Java Use Object {} was {}.", path, changeType.toString());
    }
}
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