Search in sources :

Example 11 with Whiteboard

use of org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard in project jackrabbit-oak by apache.

the class OakTest method closeAsyncIndexers.

@Test
public void closeAsyncIndexers() throws Exception {
    final AtomicReference<AsyncIndexUpdate> async = new AtomicReference<AsyncIndexUpdate>();
    Whiteboard wb = new DefaultWhiteboard() {

        @Override
        public <T> Registration register(Class<T> type, T service, Map<?, ?> properties) {
            if (service instanceof AsyncIndexUpdate) {
                async.set((AsyncIndexUpdate) service);
            }
            return super.register(type, service, properties);
        }
    };
    Oak oak = new Oak().with(new OpenSecurityProvider()).with(wb).withAsyncIndexing("foo-async", 5);
    ContentRepository repo = oak.createContentRepository();
    ((Closeable) repo).close();
    assertNotNull(async.get());
    assertTrue(async.get().isClosed());
    assertNull(WhiteboardUtils.getService(wb, AsyncIndexUpdate.class));
}
Also used : DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Closeable(java.io.Closeable) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) AsyncIndexUpdate(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate) AtomicReference(java.util.concurrent.atomic.AtomicReference) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Map(java.util.Map) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Test(org.junit.Test)

Example 12 with Whiteboard

use of org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard in project jackrabbit-oak by apache.

the class ObservationTest method run.

@Override
public void run(Iterable<RepositoryFixture> fixtures) {
    for (RepositoryFixture fixture : fixtures) {
        if (fixture.isAvailable(1)) {
            System.out.format("%s: Observation throughput benchmark%n", fixture);
            try {
                final AtomicReference<Whiteboard> whiteboardRef = new AtomicReference<Whiteboard>();
                Repository[] cluster;
                if (fixture instanceof OakRepositoryFixture) {
                    cluster = ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {

                        @Override
                        public Jcr customize(Oak oak) {
                            whiteboardRef.set(oak.getWhiteboard());
                            return new Jcr(oak);
                        }
                    });
                } else {
                    cluster = fixture.setUpCluster(1);
                }
                try {
                    run(cluster[0], whiteboardRef.get());
                } finally {
                    fixture.tearDownCluster();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Repository(javax.jcr.Repository) OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) RepositoryFixture(org.apache.jackrabbit.oak.fixture.RepositoryFixture) Oak(org.apache.jackrabbit.oak.Oak) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) AtomicReference(java.util.concurrent.atomic.AtomicReference) JcrCreator(org.apache.jackrabbit.oak.fixture.JcrCreator) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) RepositoryException(javax.jcr.RepositoryException) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with Whiteboard

use of org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard in project jackrabbit-oak by apache.

the class AtomicCounterEditorTest method singleNodeAsync.

@Test
public void singleNodeAsync() throws CommitFailedException, InterruptedException, ExecutionException {
    NodeStore store = new MemoryNodeStore();
    MyExecutor exec1 = new MyExecutor();
    Whiteboard board = new DefaultWhiteboard();
    EditorHook hook1 = new EditorHook(new TestableACEProvider(CLUSTER_1, exec1, store, board));
    NodeBuilder builder, root;
    PropertyState p;
    board.register(CommitHook.class, EmptyHook.INSTANCE, null);
    root = store.getRoot().builder();
    builder = root.child("c");
    builder = setMixin(builder);
    builder = incrementBy(builder, INCREMENT_BY_1);
    store.merge(root, hook1, CommitInfo.EMPTY);
    // as we're providing all the information we expect the counter not to be consolidated for
    // as long as the scheduled process has run
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue(builder.exists());
    p = builder.getProperty(PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PROP_COUNTER);
    assertNull(p);
    // executing the consolidation
    exec1.execute();
    // fetching the latest store state to see the changes
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue("the counter node should exists", builder.exists());
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId(), PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId()), 1);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) LongPropertyState(org.apache.jackrabbit.oak.plugins.memory.LongPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 14 with Whiteboard

use of org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard in project jackrabbit-oak by apache.

the class AtomicCounterEditorTest method noHookInWhiteboard.

@Test
public void noHookInWhiteboard() throws CommitFailedException, InterruptedException, ExecutionException {
    NodeStore store = new MemoryNodeStore();
    MyExecutor exec1 = new MyExecutor();
    Whiteboard board = new DefaultWhiteboard();
    EditorHook hook1 = new EditorHook(new TestableACEProvider(CLUSTER_1, exec1, store, board));
    NodeBuilder builder, root;
    PropertyState p;
    root = store.getRoot().builder();
    builder = root.child("c");
    builder = setMixin(builder);
    builder = incrementBy(builder, INCREMENT_BY_1);
    store.merge(root, hook1, CommitInfo.EMPTY);
    // as we're providing all the information we expect the counter not to be consolidated for
    // as long as the scheduled process has run
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue(builder.exists());
    p = builder.getProperty(PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PROP_COUNTER);
    assertEquals(1, p.getValue(LONG).longValue());
    assertTrue("without a registered hook it should have fell to sync", exec1.isEmpty());
    // fetching the latest store state to see the changes
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue("the counter node should exists", builder.exists());
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId(), PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId()), 1);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) LongPropertyState(org.apache.jackrabbit.oak.plugins.memory.LongPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 15 with Whiteboard

use of org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard in project jackrabbit-oak by apache.

the class HybridIndexClusterIT method getFixture.

@Override
protected NodeStoreFixture getFixture() {
    return new DocumentMemoryFixture() {

        @Override
        public NodeStore createNodeStore(int clusterNodeId) {
            JournalPropertyHandlerFactory tracker = new JournalPropertyHandlerFactory();
            Whiteboard wb = clusterNodeId == 1 ? nswb1 : nswb2;
            tracker.start(wb);
            return new DocumentMK.Builder().setDocumentStore(documentStore).setJournalPropertyHandlerFactory(tracker).setAsyncDelay(0).getNodeStore();
        }
    };
}
Also used : JournalPropertyHandlerFactory(org.apache.jackrabbit.oak.plugins.document.JournalPropertyHandlerFactory) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) DocumentMemoryFixture(org.apache.jackrabbit.oak.fixture.DocumentMemoryFixture) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard)

Aggregations

Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)25 DefaultWhiteboard (org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard)11 Test (org.junit.Test)10 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)9 Activate (org.apache.felix.scr.annotations.Activate)7 Oak (org.apache.jackrabbit.oak.Oak)3 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)3 Closeable (java.io.Closeable)2 Hashtable (java.util.Hashtable)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Repository (javax.jcr.Repository)2 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 CacheStatsMBean (org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean)2 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)2 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)2 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)2 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 BundleContext (org.osgi.framework.BundleContext)2