Search in sources :

Example 6 with FilterProvider

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider in project jackrabbit-oak by apache.

the class ObservationTest method includeGlobPaths.

@Test
public void includeGlobPaths() throws Exception {
    Node testNode = getNode(TEST_PATH);
    testNode.addNode("a1").addNode("b").addNode("c");
    testNode.addNode("a2").addNode("b").addNode("c");
    testNode.getSession().save();
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a2/**");
    oManager.addEventListener(listener, filter);
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a2");
    testNode.getNode("a1").getNode("b").remove();
    listener.expectRemove(testNode.getNode("a2").getNode("b")).remove();
    testNode.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    Node a3 = testNode.addNode("a3");
    Node foo = a3.addNode("bar").addNode("foo");
    testNode.getSession().save();
    filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    // filter.setAbsPath(TEST_PATH + "/a3/bar/foo/x");
    filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a3/**/x");
    oManager.addEventListener(listener, filter);
    cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a3");
    Node x = foo.addNode("x");
    listener.expect(x.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    testNode.getSession().save();
    Thread.sleep(1000);
    missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a3/**/y");
    oManager.addEventListener(listener, filter);
    cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a3");
    Node y = foo.addNode("y");
    listener.expect(y.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    testNode.getSession().save();
    Thread.sleep(1000);
    missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 7 with FilterProvider

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider in project jackrabbit-oak by apache.

the class ChangeProcessor method evalPrefilter.

/**
 * Evaluate the prefilter for a given commit.
 * @param changeSet
 *
 * @return a FilterResult indicating either inclusion, exclusion or
 *         inclusion-due-to-skipping. The latter is used to reflect
 *         prefilter evaluation better in statistics (as it could also have
 *         been reported just as include)
 */
private FilterResult evalPrefilter(NodeState root, CommitInfo info, ChangeSet changeSet) {
    if (info == null) {
        return FilterResult.PREFILTERING_SKIPPED;
    }
    if (root == null) {
        // we can't do any diffing etc, so just not exclude it
        return FilterResult.PREFILTERING_SKIPPED;
    }
    final FilterProvider fp = filterProvider.get();
    // FIXME don't rely on toString for session id
    if (!fp.includeCommit(contentSession.toString(), info)) {
        // 'classic' (and cheap pre-) filtering
        return FilterResult.EXCLUDE;
    }
    if (changeSet == null) {
        // go through prefiltering)
        return FilterResult.PREFILTERING_SKIPPED;
    }
    final ChangeSetFilter prefilter = fp;
    if (prefilter.excludes(changeSet)) {
        return FilterResult.EXCLUDE;
    } else {
        return FilterResult.INCLUDE;
    }
}
Also used : ChangeSetFilter(org.apache.jackrabbit.oak.plugins.observation.filter.ChangeSetFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider)

Example 8 with FilterProvider

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider in project jackrabbit-oak by apache.

the class ChangeProcessor method contentChanged.

@Override
public void contentChanged(@Nonnull NodeState before, @Nonnull NodeState after, @Nonnull CommitInfo info) {
    // OAK-5160 before is now guaranteed to be non-null
    checkNotNull(before);
    checkNotNull(after);
    checkNotNull(info);
    try {
        long start = PERF_LOGGER.start();
        FilterProvider provider = filterProvider.get();
        // FIXME don't rely on toString for session id
        if (provider.includeCommit(contentSession.toString(), info)) {
            EventFilter filter = provider.getFilter(before, after);
            EventIterator events = new EventQueue(namePathMapper, info, before, after, provider.getSubTrees(), Filters.all(filter, VISIBLE_FILTER), provider.getEventAggregator());
            long time = System.nanoTime();
            boolean hasEvents = events.hasNext();
            tracker.recordProducerTime(System.nanoTime() - time, TimeUnit.NANOSECONDS);
            if (hasEvents && runningMonitor.enterIf(running)) {
                if (commitRateLimiter != null) {
                    commitRateLimiter.beforeNonBlocking();
                }
                try {
                    CountingIterator countingEvents = new CountingIterator(events);
                    eventListener.onEvent(countingEvents);
                    countingEvents.updateCounters(eventCount, eventDuration);
                } finally {
                    if (commitRateLimiter != null) {
                        commitRateLimiter.afterNonBlocking();
                    }
                    runningMonitor.leave();
                }
            }
        }
        PERF_LOGGER.end(start, 100, "Generated events (before: {}, after: {})", before, after);
    } catch (Exception e) {
        LOG.warn("Error while dispatching observation events for " + tracker, e);
    }
}
Also used : EventIterator(javax.jcr.observation.EventIterator) EventFilter(org.apache.jackrabbit.oak.plugins.observation.filter.EventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider)

Example 9 with FilterProvider

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider in project jackrabbit-oak by apache.

the class ObservationTest method doTestFileWithGlobs.

private void doTestFileWithGlobs(String globPath, String... expectedSubTrees) throws RepositoryException, ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, AccessDeniedException, ReferentialIntegrityException, InvalidItemStateException, InterruptedException, ExecutionException {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withIncludeGlobPaths(globPath);
    oManager.addEventListener(listener, filter);
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertArrayEquals(expectedSubTrees, Iterables.toArray(filterProvider.getSubTrees(), String.class));
    Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
    Node bar = parent.addNode("bar", "nt:unstructured");
    Node zetDotJsp = bar.addNode("zet.jsp", "nt:unstructured");
    listener.expect(zetDotJsp.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    parent.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
    Session session = getAdminSession();
    session.getRootNode().getNode("parent").remove();
    session.save();
    oManager.removeEventListener(listener);
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) Session(javax.jcr.Session)

Example 10 with FilterProvider

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider in project jackrabbit-oak by apache.

the class ObservationTest method doTestAggregate6.

private void doTestAggregate6(OakEventFilter oef, String[] expectedSubTrees, String[] expectedPrefilterPaths) throws Exception {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    oManager.addEventListener(listener, oef);
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), expectedSubTrees);
    ChangeSetFilterImpl changeSetFilter = (ChangeSetFilterImpl) PrivateAccessor.getField(filterProvider, "changeSetFilter");
    assertNotNull(changeSetFilter);
    assertMatches(changeSetFilter.getRootIncludePaths(), expectedPrefilterPaths);
    Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
    Node bar = parent.addNode("bar", "nt:unstructured");
    Node zetDotJsp = bar.addNode("zet.jsp", "nt:unstructured");
    listener.expect(zetDotJsp.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node c = bar.addNode("c", "nt:unstructured");
    Node fooDotJsp = c.addNode("foo.jsp", "oak:Unstructured");
    listener.expect(fooDotJsp.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node jcrContent = fooDotJsp.addNode("jcr:content", "nt:unstructured");
    jcrContent.setProperty("jcr:data", "foo");
    listener.expectAdd(jcrContent);
    listener.expect(jcrContent.getPath() + "/jcr:data", "/parent/bar/c/foo.jsp", PROPERTY_ADDED);
    parent.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
    // OAK-5096 : this is what OAK-5096 is all about: when you change
    // the property jcr:content/jcr:data it should be reported with
    // identifier of the aggregate - even though it is not in the original glob path
    jcrContent.setProperty("jcr:data", "bar");
    listener.expect(jcrContent.getPath() + "/jcr:data", "/parent/bar/c/foo.jsp", PROPERTY_CHANGED);
    parent.getSession().save();
    Thread.sleep(1000);
    missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
    // cleanup
    Session session = getAdminSession();
    session.getRootNode().getNode("parent").remove();
    session.save();
    oManager.removeEventListener(listener);
}
Also used : ChangeSetFilterImpl(org.apache.jackrabbit.oak.plugins.observation.filter.ChangeSetFilterImpl) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) Session(javax.jcr.Session)

Aggregations

FilterProvider (org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider)10 Node (javax.jcr.Node)7 Event (javax.jcr.observation.Event)7 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)7 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)6 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)5 Test (org.junit.Test)5 Session (javax.jcr.Session)2 EventIterator (javax.jcr.observation.EventIterator)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 ItemExistsException (javax.jcr.ItemExistsException)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Property (javax.jcr.Property)1 ReferentialIntegrityException (javax.jcr.ReferentialIntegrityException)1 RepositoryException (javax.jcr.RepositoryException)1 LockException (javax.jcr.lock.LockException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1