@Override @Nullable public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) throws CommitFailedException { if (OrderedIndex.TYPE.equals(type)) { if (hit() % threshold == 0) { if (callback instanceof ContextAwareCallback) { LOG.warn(DEPRECATION_MESSAGE, ((ContextAwareCallback)callback).getIndexingContext().getIndexPath()); } else { LOG.warn(OrderedIndex.DEPRECATION_MESSAGE, definition); } } } return null; }
@Override @CheckForNull public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException { if (OrderedIndex.TYPE.equals(type)) { if (hit() % threshold == 0) { if (callback instanceof ContextAwareCallback) { LOG.warn(DEPRECATION_MESSAGE, ((ContextAwareCallback)callback).getIndexingContext().getIndexPath()); } else { LOG.warn(OrderedIndex.DEPRECATION_MESSAGE, definition); } } } return null; }
@Override @Nullable public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) throws CommitFailedException { if (OrderedIndex.TYPE.equals(type)) { if (hit() % threshold == 0) { if (callback instanceof ContextAwareCallback) { LOG.warn(DEPRECATION_MESSAGE, ((ContextAwareCallback)callback).getIndexingContext().getIndexPath()); } else { LOG.warn(OrderedIndex.DEPRECATION_MESSAGE, definition); } } } return null; }
@Override public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) { lastIndexingContext = ((ContextAwareCallback)callback).getIndexingContext(); return super.getIndexEditor(type, definition, root, callback); } }
@Nullable @Override public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) throws CommitFailedException { ContextAwareCallback ccb = (ContextAwareCallback) callback; if (semaphore != null && ccb.getIndexingContext().isAsync()) { semaphore.acquireUninterruptibly(); } return null; }
@Override public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) { Editor editor = super.getIndexEditor(type, definition, root, callback); if (editor != null){ this.callback = callback; if (callback instanceof ContextAwareCallback){ IndexingContext context = ((ContextAwareCallback) callback).getIndexingContext(); callbacks.put(context.getIndexPath(), context); } } return editor; }
@Override public Editor getIndexEditor(@NotNull String type, @NotNull NodeBuilder definition, @NotNull NodeState root, @NotNull IndexUpdateCallback callback) { IndexingContext context = ((ContextAwareCallback)callback).getIndexingContext(); if (indexPathToFail != null && indexPathToFail.equals(context.getIndexPath())){ RuntimeException e = new RuntimeException(); context.indexUpdateFailed(e); throw e; } return super.getIndexEditor(type, definition, root, callback); }
checkArgument(callback instanceof ContextAwareCallback, "callback instance not of type " + "ContextAwareCallback [%s]", callback); IndexingContext indexingContext = ((ContextAwareCallback)callback).getIndexingContext(); BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback(); indexingContext.registerIndexCommitCallback(blobDeletionCallback);
checkArgument(callback instanceof ContextAwareCallback, "callback instance not of type " + "ContextAwareCallback [%s]", callback); IndexingContext indexingContext = ((ContextAwareCallback)callback).getIndexingContext(); BlobDeletionCallback blobDeletionCallback = activeDeletedBlobCollector.getBlobDeletionCallback(); indexingContext.registerIndexCommitCallback(blobDeletionCallback);
@Test public void contextAwareCallback_async() throws Exception{ NodeState before = builder.getNodeState(); NodeBuilder idx = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); idx.setProperty("async", asList("sync", "async"), Type.STRINGS); NodeState after = builder.getNodeState(); CallbackCapturingProvider provider = new CallbackCapturingProvider(); EditorHook hook = new EditorHook(new IndexUpdateProvider(provider, "async", false)); hook.processCommit(before, after, CommitInfo.EMPTY); assertTrue(((ContextAwareCallback)provider.callback).getIndexingContext().isAsync()); }
IndexingContext context = contextualCallback.getIndexingContext();
@Test public void indexUpdateToleratesMalignCommitProgressCallback() throws Exception { final IndexUpdateCallback noop = new IndexUpdateCallback() { @Override public void indexUpdate() { } }; NodeState before = builder.getNodeState(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); NodeState after = builder.getNodeState(); CallbackCapturingProvider provider = new CallbackCapturingProvider(); IndexUpdate indexUpdate = new IndexUpdate(provider, null, after, builder, noop); indexUpdate.enter(before, after); ContextAwareCallback contextualCallback = (ContextAwareCallback) provider.callback; IndexingContext context = contextualCallback.getIndexingContext(); context.registerIndexCommitCallback(new IndexCommitCallback() { @Override public void commitProgress(IndexProgress indexProgress) { throw new NullPointerException("Malign callback"); } }); indexUpdate.commitProgress(IndexCommitCallback.IndexProgress.COMMIT_SUCCEDED); }
@Test public void contextAwareCallback() throws Exception{ NodeState before = builder.getNodeState(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null); NodeState after = builder.getNodeState(); CallbackCapturingProvider provider = new CallbackCapturingProvider(); EditorHook hook = new EditorHook(new IndexUpdateProvider(provider)); CommitInfo info = new CommitInfo("foo", "bar"); NodeState indexed = hook.processCommit(before, after, info); assertNotNull(provider.callback); assertThat(provider.callback, instanceOf(ContextAwareCallback.class)); ContextAwareCallback contextualCallback = (ContextAwareCallback) provider.callback; IndexingContext context = contextualCallback.getIndexingContext(); assertNotNull(context); assertEquals("/oak:index/rootIndex", context.getIndexPath()); assertTrue(context.isReindexing()); assertFalse(context.isAsync()); assertSame(info, context.getCommitInfo()); before = indexed; builder = indexed.builder(); builder.child("a").setProperty("foo", "bar"); after = builder.getNodeState(); hook.processCommit(before, after, info); assertFalse(((ContextAwareCallback)provider.callback).getIndexingContext().isReindexing()); }