Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/FilteringObserver.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/FilteringObserver.java (nonexistent) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/FilteringObserver.java (working copy) @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.plugins.observation; + +import java.io.Closeable; +import java.io.IOException; +import java.util.concurrent.Executor; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.google.common.base.Predicate; + +import org.apache.jackrabbit.oak.spi.commit.BackgroundObserver; +import org.apache.jackrabbit.oak.spi.commit.CommitContext; +import org.apache.jackrabbit.oak.spi.commit.CommitInfo; +import org.apache.jackrabbit.oak.spi.commit.Observer; +import org.apache.jackrabbit.oak.spi.state.NodeState; + +import static org.apache.jackrabbit.oak.plugins.observation.ChangeCollectorProvider.COMMIT_CONTEXT_OBSERVATION_CHANGESET; + +public abstract class FilteringObserver implements Observer, Closeable { + + private final static CommitInfo NOOP_CHANGE = new CommitInfo( + CommitInfo.OAK_UNKNOWN, CommitInfo.OAK_UNKNOWN); + + private final BackgroundObserver backgroundObserver; + + private final Predicate isNoop; + + private NodeState lastNoop; + + public FilteringObserver(Executor executor, + int queueLength, + Predicate isNoop) { + this.backgroundObserver = new BackgroundObserver(new Dispatcher(), executor, queueLength); + this.isNoop = isNoop; + } + + public abstract void contentChanged(@Nonnull NodeState before, + @Nonnull NodeState after, + @Nullable CommitInfo info); + + @Override + public final void contentChanged(@Nonnull NodeState root, + @Nullable CommitInfo info) { + if (isNoop.apply(getChangeSet(info))) { + lastNoop = root; + return; + } + // current change is not an noop + if (lastNoop != null) { + // report up to previous noop + backgroundObserver.contentChanged(lastNoop, NOOP_CHANGE); + lastNoop = null; + } + backgroundObserver.contentChanged(root, info); + } + + @Override + public void close() { + backgroundObserver.close(); + } + + private static ChangeSet getChangeSet(CommitInfo info) { + if (info == null) { + return null; + } + CommitContext context = (CommitContext) info.getInfo().get(CommitContext.NAME); + if (context == null) { + return null; + } + return (ChangeSet) context.get(COMMIT_CONTEXT_OBSERVATION_CHANGESET); + } + + private final class Dispatcher implements Observer { + + private NodeState before; + + @Override + public void contentChanged(@Nonnull NodeState root, + @Nullable CommitInfo info) { + if (info != NOOP_CHANGE) { + FilteringObserver.this.contentChanged(before, root, info); + } + before = root; + } + } +} Property changes on: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/FilteringObserver.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property