use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class LuceneIndexProviderService method registerObserver.
private void registerObserver(BundleContext bundleContext, Map<String, ?> config) {
boolean enableAsyncIndexOpen = PropertiesUtil.toBoolean(config.get(PROP_ASYNC_INDEX_OPEN), true);
Observer observer = indexProvider;
if (enableAsyncIndexOpen) {
backgroundObserver = new BackgroundObserver(indexProvider, getExecutorService(), 5);
observer = backgroundObserver;
oakRegs.add(registerMBean(whiteboard, BackgroundObserverMBean.class, backgroundObserver.getMBean(), BackgroundObserverMBean.TYPE, "LuceneIndexConfigObserver queue stats"));
log.info("Registering the LuceneIndexProvider as a BackgroundObserver");
}
regs.add(bundleContext.registerService(Observer.class.getName(), observer, null));
}
use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method createRepository.
@Override
protected ContentRepository createRepository() {
IndexCopier copier = createIndexCopier();
editorProvider = new LuceneIndexEditorProvider(copier, new ExtractedTextCache(10 * FileUtils.ONE_MB, 100));
provider = new LuceneIndexProvider(copier);
nodeStore = new MemoryNodeStore();
return new Oak(nodeStore).with(new InitialContent()).with(new OpenSecurityProvider()).with((QueryIndexProvider) provider).with((Observer) provider).with(editorProvider).with(optionalEditorProvider).with(new PropertyIndexEditorProvider()).with(new NodeTypeIndexProvider()).createContentRepository();
}
use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class LuceneIndexTest method luceneWithFSDirectory.
@Test
public void luceneWithFSDirectory() throws Exception {
//Issue is not reproducible with MemoryNodeBuilder and
//MemoryNodeState as they cannot determine change in childNode without
//entering
NodeStore nodeStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
tracker = new IndexTracker();
((Observable) nodeStore).addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
tracker.update(root);
}
});
builder = nodeStore.getRoot().builder();
//Also initialize the NodeType registry required for Lucene index to work
builder.setChildNode(JCR_SYSTEM, INITIAL_CONTENT.getChildNode(JCR_SYSTEM));
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
NodeBuilder idxb = newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo", "foo2"), null);
idxb.setProperty(PERSISTENCE_NAME, PERSISTENCE_FILE);
idxb.setProperty(PERSISTENCE_PATH, getIndexDir());
nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
builder = nodeStore.getRoot().builder();
builder.setProperty("foo", "bar");
NodeState indexed = nodeStore.merge(builder, HOOK, CommitInfo.EMPTY);
assertQuery(tracker, indexed, "foo", "bar");
builder = nodeStore.getRoot().builder();
builder.setProperty("foo2", "bar2");
indexed = nodeStore.merge(builder, HOOK, CommitInfo.EMPTY);
assertQuery(tracker, indexed, "foo2", "bar2");
}
use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class CompositeNodeStore method merge.
@Override
public NodeState merge(NodeBuilder builder, CommitHook commitHook, CommitInfo info) throws CommitFailedException {
checkArgument(builder instanceof CompositeNodeBuilder);
CompositeNodeBuilder nodeBuilder = (CompositeNodeBuilder) builder;
if (!PathUtils.denotesRoot(nodeBuilder.getPath())) {
throw new IllegalArgumentException();
}
// run commit hooks and apply the changes to the builder instance
NodeState processed = commitHook.processCommit(getRoot(), rebase(nodeBuilder), info);
processed.compareAgainstBaseState(builder.getNodeState(), new ApplyDiff(nodeBuilder));
assertNoChangesOnReadOnlyMounts(nodeBuilder);
// apply the accumulated changes on individual NodeStore instances
Map<MountedNodeStore, NodeState> resultStates = newHashMap();
for (MountedNodeStore mountedNodeStore : ctx.getAllMountedNodeStores()) {
NodeStore nodeStore = mountedNodeStore.getNodeStore();
NodeBuilder partialBuilder = nodeBuilder.getBuilders().get(mountedNodeStore);
NodeState result = nodeStore.merge(partialBuilder, EmptyHook.INSTANCE, info);
resultStates.put(mountedNodeStore, result);
}
CompositeNodeState newRoot = createRootNodeState(resultStates);
for (Observer observer : observers) {
observer.contentChanged(newRoot, info);
}
return newRoot;
}
use of org.apache.jackrabbit.oak.spi.commit.Observer in project jackrabbit-oak by apache.
the class ExternalIndexObserverTest method builder.
@Test
public void builder() throws Exception {
ExternalObserverBuilder builder = new ExternalObserverBuilder(queue, tracker, NOOP, MoreExecutors.sameThreadExecutor(), 10);
Observer o = builder.build();
o.contentChanged(INITIAL_CONTENT, CommitInfo.EMPTY_EXTERNAL);
verifyZeroInteractions(queue);
}
Aggregations