use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit by apache.
the class JackrabbitObservationManagerTest method testDisjunctPaths.
public void testDisjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
JackrabbitObservationManager oManager = (JackrabbitObservationManager) obsMgr;
EventResult listener = new EventResult(log);
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths('/' + testPath + "/a", '/' + testPath + "/x").setEventTypes(NODE_ADDED);
oManager.addEventListener(listener, filter);
try {
Node b = testRootNode.addNode("a").addNode("b");
b.addNode("c");
Node y = testRootNode.addNode("x").addNode("y");
y.addNode("z");
testRootNode.getSession().save();
Event[] added = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
checkNodeAdded(added, new String[] { "a/b", "x/y" }, null);
} finally {
oManager.removeEventListener(listener);
}
}
use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.
the class ObservationTest method filterDisjunctPaths.
@Test
public void filterDisjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
assumeTrue(observationManager instanceof JackrabbitObservationManager);
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
FilterBuilder builder = new FilterBuilder();
builder.condition(builder.any(builder.path(TEST_PATH + "/a/b"), builder.path(TEST_PATH + "/x/y")));
oManager.addEventListener(listener, builder.build());
Node testNode = getNode(TEST_PATH);
Node b = testNode.addNode("a").addNode("b");
b.addNode("c");
Node y = testNode.addNode("x").addNode("y");
y.addNode("z");
listener.expect(b.getPath(), NODE_ADDED);
listener.expect(y.getPath(), NODE_ADDED);
testNode.getSession().save();
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());
}
use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.
the class ObservationTest method disjunctPaths.
@Test
public void disjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
assumeTrue(observationManager instanceof JackrabbitObservationManager);
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths(TEST_PATH + "/a", TEST_PATH + "/x").setEventTypes(NODE_ADDED);
oManager.addEventListener(listener, filter);
Node testNode = getNode(TEST_PATH);
Node b = testNode.addNode("a").addNode("b");
b.addNode("c");
Node y = testNode.addNode("x").addNode("y");
y.addNode("z");
listener.expect(b.getPath(), NODE_ADDED);
listener.expect(y.getPath(), NODE_ADDED);
testNode.getSession().save();
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());
}
use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.
the class ObservationTest method pathExclude.
@Test
public void pathExclude() throws ExecutionException, InterruptedException, RepositoryException {
assumeTrue(observationManager instanceof JackrabbitObservationManager);
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath(TEST_PATH).setIsDeep(true).setExcludedPaths(TEST_PATH + "/c", TEST_PATH + "/d", "/x/y").setEventTypes(ALL_EVENTS);
oManager.addEventListener(listener, filter);
Node n = getNode(TEST_PATH);
listener.expectAdd(listener.expectAdd(listener.expectAdd(n.addNode("a")).addNode("a1")).setProperty("p", "q"));
listener.expectAdd(listener.expectAdd(n.addNode("b")).setProperty("p", "q"));
n.addNode("c").addNode("c1").setProperty("p", "q");
n.addNode("d").setProperty("p", "q");
getAdminSession().save();
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());
}
use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project sling by apache.
the class JcrListenerBaseConfig method register.
/**
* Register a JCR event listener
* @param listener The listener
* @param config The configuration
* @throws RepositoryException If registration fails.
*/
public void register(final EventListener listener, final ObserverConfiguration config) throws RepositoryException {
final ObservationManager mgr = this.session.getWorkspace().getObservationManager();
if (mgr instanceof JackrabbitObservationManager) {
final OakEventFilter filter = FilterFactory.wrap(new JackrabbitEventFilter());
// paths
final Set<String> paths = config.getPaths().toStringSet();
int globCount = 0, pathCount = 0;
for (final String p : paths) {
if (p.startsWith(Path.GLOB_PREFIX)) {
globCount++;
} else {
pathCount++;
}
}
final String[] pathArray = pathCount > 0 ? new String[pathCount] : null;
final String[] globArray = globCount > 0 ? new String[globCount] : null;
pathCount = 0;
globCount = 0;
// create arrays and remove global prefix
for (final String p : paths) {
if (p.startsWith(Path.GLOB_PREFIX)) {
globArray[globCount] = p.substring(Path.GLOB_PREFIX.length());
globCount++;
} else {
pathArray[pathCount] = p;
pathCount++;
}
}
if (globArray != null) {
filter.withIncludeGlobPaths(globArray);
}
if (pathArray != null) {
filter.setAdditionalPaths(pathArray);
}
filter.setIsDeep(true);
// exclude paths
final Set<String> excludePaths = config.getExcludedPaths().toStringSet();
if (!excludePaths.isEmpty()) {
filter.setExcludedPaths(excludePaths.toArray(new String[excludePaths.size()]));
}
// external
filter.setNoExternal(!config.includeExternal());
// types
filter.setEventTypes(this.getTypes(config));
// nt:file handling
filter.withNodeTypeAggregate(new String[] { "nt:file" }, new String[] { "", "jcr:content" });
// anchestor removes
filter.withIncludeAncestorsRemove();
((JackrabbitObservationManager) mgr).addEventListener(listener, filter);
} else {
throw new RepositoryException("Observation manager is not a JackrabbitObservationManager");
}
}
Aggregations