Search in sources :

Example 16 with Observer

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));
}
Also used : BackgroundObserver(org.apache.jackrabbit.oak.spi.commit.BackgroundObserver) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) LocalIndexObserver(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.LocalIndexObserver) BackgroundObserver(org.apache.jackrabbit.oak.spi.commit.BackgroundObserver) BackgroundObserverMBean(org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean)

Example 17 with Observer

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();
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) NodeTypeIndexProvider(org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)

Example 18 with Observer

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");
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Observable(org.apache.jackrabbit.oak.spi.commit.Observable) Test(org.junit.Test)

Example 19 with Observer

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;
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 20 with Observer

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);
}
Also used : Observer(org.apache.jackrabbit.oak.spi.commit.Observer) Test(org.junit.Test)

Aggregations

Observer (org.apache.jackrabbit.oak.spi.commit.Observer)21 Test (org.junit.Test)8 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)6 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 SimpleCredentials (javax.jcr.SimpleCredentials)4 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)4 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)4 QueryIndexProvider (org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Oak (org.apache.jackrabbit.oak.Oak)3 LuceneIndexProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider)3 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)3 Observable (org.apache.jackrabbit.oak.spi.commit.Observable)3 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 InitialContent (org.apache.jackrabbit.oak.InitialContent)2