jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1536832 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/
Date Tue, 29 Oct 2013 17:43:03 GMT
Author: mduerig
Date: Tue Oct 29 17:43:03 2013
New Revision: 1536832

URL: http://svn.apache.org/r1536832
Log:
OAK-1121: Enhance observation mechanism to only listen to cluster local changes
Initial implementation using a marker interface to indicate exclusion of cluster external
events

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ExcludeExternal.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java?rev=1536832&r1=1536831&r2=1536832&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
Tue Oct 29 17:43:03 2013
@@ -143,7 +143,8 @@ public class ChangeProcessor {
                     EventFilter filter = filterRef.get();
                     // FIXME don't rely on toString for session id
                     if (changes != null &&
-                            filter.include(changes.isLocal(contentSession.toString()))) {
+                            filter.includeSessionLocal(changes.isLocal(contentSession.toString()))
&&
+                            filter.includeClusterExternal(changes.getCommitInfo() == null))
{
                         String path = namePathMapper.getOakPath(filter.getPath());
                         ImmutableTree beforeTree = getTree(changes.getBeforeState(), path);
                         ImmutableTree afterTree = getTree(changes.getAfterState(), path);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java?rev=1536832&r1=1536831&r2=1536832&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java
Tue Oct 29 17:43:03 2013
@@ -43,7 +43,8 @@ public class EventFilter {
     private final boolean deep;
     private final String[] uuids;
     private final String[] nodeTypeOakName;
-    private final boolean includeLocal;
+    private final boolean includeSessionLocal;
+    private final boolean includeClusterExternal;
 
     /**
      * Create a new instance of a filter for a certain criterion
@@ -51,24 +52,28 @@ public class EventFilter {
      * @param ntMgr
      * @param eventTypes  event types to include encoded as a bit mask
      * @param path        path to include
-     * @param deep        {@code true} if descendants of {@code path} should be included.
{@code false} otherwise.
+     * @param deep        {@code true} if descendants of {@code path} should be included.
+     *                    {@code false} otherwise.
      * @param uuids       uuids to include
-     * @param nodeTypeName  node type names to include
-     * @param includeLocal  include session local events if {@code true}. Exclude otherwise.
-     * @throws NoSuchNodeTypeException  if any of the node types in {@code nodeTypeName}
does not exist
+     * @param nodeTypeName              node type names to include
+     * @param includeSessionLocal       include session local events if {@code true}.
+     *                                  Exclude otherwise.
+     * @param includeClusterExternal    include cluster external events if {@code true}.
+     *                                  Exclude otherwise.
+     * @throws NoSuchNodeTypeException  if any of the node types in {@code nodeTypeName}
does not
+     *                                  exist
      * @throws RepositoryException      if an error occurs while reading from the node type
manager.
-     * @see javax.jcr.observation.ObservationManager#addEventListener(javax.jcr.observation.EventListener,
-     * int, String, boolean, String[], String[], boolean)
-     */
+     * @see javax.jcr.observation.ObservationManager#addEventListener(javax.jcr.observation.EventListener,
int, String, boolean, String[], String[], boolean) */
     public EventFilter(ReadOnlyNodeTypeManager ntMgr, int eventTypes, String path, boolean
deep, String[] uuids,
-            String[] nodeTypeName, boolean includeLocal) {
+            String[] nodeTypeName, boolean includeSessionLocal, boolean includeClusterExternal)
{
         this.ntMgr = ntMgr;
         this.eventTypes = eventTypes;
         this.path = path;
         this.deep = deep;
         this.uuids = uuids;
         this.nodeTypeOakName = nodeTypeName;
-        this.includeLocal = includeLocal;
+        this.includeSessionLocal = includeSessionLocal;
+        this.includeClusterExternal = includeClusterExternal;
     }
 
     /**
@@ -87,11 +92,20 @@ public class EventFilter {
 
     /**
      * Determine whether session local changes should be included.
-     * @param local  {@code true} for session local changes, {@code false} otherwise.
+     * @param isLocal  {@code true} for session local changes, {@code false} otherwise.
+     * @return  {@code true} if the changes are included with this filter. {@code false}
otherwise.
+     */
+    public boolean includeSessionLocal(boolean isLocal) {
+        return includeSessionLocal || !isLocal;
+    }
+
+    /**
+     * Determine whether cluster external changes should be included.
+     * @param isExternal  {@code true} for cluster external changes, {@code false} otherwise.
      * @return  {@code true} if the changes are included with this filter. {@code false}
otherwise.
      */
-    public boolean include(boolean local) {
-        return includeLocal || !local;
+    public boolean includeClusterExternal(boolean isExternal) {
+        return includeClusterExternal || !isExternal;
     }
 
     /**
@@ -120,7 +134,8 @@ public class EventFilter {
                 .add("deep", deep)
                 .add("uuids", Arrays.toString(uuids))
                 .add("node types", Arrays.toString(nodeTypeOakName))
-                .add("includeLocal", includeLocal)
+                .add("includeSessionLocal", includeSessionLocal)
+                .add("includeClusterExternal", includeClusterExternal)
             .toString();
     }
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ExcludeExternal.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ExcludeExternal.java?rev=1536832&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ExcludeExternal.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ExcludeExternal.java
Tue Oct 29 17:43:03 2013
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ * The presence of this marker interface on a {@link javax.jcr.observation.EventListener}
+ * indicates that cluster external observation events must not be reported to that
+ * event listener.
+ */
+public interface ExcludeExternal {
+}

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java?rev=1536832&r1=1536831&r2=1536832&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
Tue Oct 29 17:43:03 2013
@@ -42,6 +42,7 @@ import org.apache.jackrabbit.oak.namepat
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.plugins.observation.ChangeProcessor;
 import org.apache.jackrabbit.oak.plugins.observation.EventFilter;
+import org.apache.jackrabbit.oak.plugins.observation.ExcludeExternal;
 import org.apache.jackrabbit.oak.plugins.observation.Observable;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.slf4j.Logger;
@@ -104,8 +105,9 @@ public class ObservationManagerImpl impl
     @Override
     public synchronized void addEventListener(EventListener listener, int eventTypes, String
absPath,
             boolean isDeep, String[] uuid, String[] nodeTypeName, boolean noLocal) throws
RepositoryException {
+        boolean includeExternal = !(listener instanceof ExcludeExternal);
         EventFilter filter = new EventFilter(ntMgr, eventTypes, oakPath(absPath), isDeep,
-                uuid, validateNodeTypeNames(nodeTypeName), !noLocal);
+                uuid, validateNodeTypeNames(nodeTypeName), !noLocal, includeExternal);
         ChangeProcessor processor = processors.get(listener);
         if (processor == null) {
             log.info(OBSERVATION, "Registering event listener {} with filter {}", listener,
filter);



Mime
View raw message