Author: stefanegli
Date: Mon Nov 21 14:29:15 2016
New Revision: 1770692

URL: http://svn.apache.org/viewvc?rev=1770692&view=rev
Log:
OAK-5134 : temporarily - until 1.6 - making prefiltering test mode configurable 
via osgi

Added:
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessorPrefilterTestConfig.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java?rev=1770692&r1=1770691&r2=1770692&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
 Mon Nov 21 14:29:15 2016
@@ -116,8 +116,9 @@ class ChangeProcessor implements Filteri
     
     /** The test mode can be used to just verify if prefiltering would have
      * correctly done its job and warn if that's not the case.
+     * @deprecated remove this before 1.6 - see OAK-5136
      */
-    private static final boolean PREFILTERING_TESTMODE;
+    private static boolean PREFILTERING_TESTMODE;
     
     // OAK-4533: make DELAY_THRESHOLD and MAX_DELAY adjustable - using 
System.properties for now
     static {
@@ -143,18 +144,15 @@ class ChangeProcessor implements Filteri
         }
         DELAY_THRESHOLD = delayThreshold;
         MAX_DELAY = maxDelay;
-
-        final String prefilteringTestModeStr = 
System.getProperty("oak.observation.prefilteringTestMode");
-        boolean prefilteringTestModeBool = false; // default is enabled
-        try {
-            if (prefilteringTestModeStr != null && 
prefilteringTestModeStr.length() != 0) {
-                prefilteringTestModeBool = 
Boolean.parseBoolean(prefilteringTestModeStr);
-                LOG.info("<clinit> using oak.observation.prefilteringTestMode 
= " + prefilteringTestModeBool);
-            }
-        } catch(RuntimeException e) {
-            LOG.warn("<clinit> could not parse 
oak.observation.prefilteringTestMode, using default (" + 
prefilteringTestModeBool + "): " + e, e);
-        }
-        PREFILTERING_TESTMODE = prefilteringTestModeBool;
+    }
+    
+    /**
+     * @deprecated remove this before 1.6 - see OAK-5136
+     * @param testMode
+     */
+    static void setPrefilteringTestMode(boolean testMode) {
+        PREFILTERING_TESTMODE = testMode;
+        LOG.info("setPrefilteringTestMode: PREFILTERING_TESTMODE = " + 
PREFILTERING_TESTMODE);
     }
     
     private static final AtomicInteger COUNTER = new AtomicInteger();

Added: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessorPrefilterTestConfig.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessorPrefilterTestConfig.java?rev=1770692&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessorPrefilterTestConfig.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessorPrefilterTestConfig.java
 Mon Nov 21 14:29:15 2016
@@ -0,0 +1,94 @@
+/*
+ * 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.jcr.observation;
+
+import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toBoolean;
+
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Temporary class to be removed before 1.6 which allows to turn on/off
+ * the prefiltering test mode via an osgi-config, rather than via
+ * a System.property (the two ways overlap - but the osgi one, if configured, 
wins)
+ * TODO: remove me before 1.6
+ * @deprecated to be removed before 1.6
+ */
+@Component(
+        policy = ConfigurationPolicy.OPTIONAL,
+        immediate = true,
+        metatype = true,
+        label = "Apache Jackrabbit Oak Change Processor Prefilter TestConfig",
+        description = "Temporary config used for testing ChangeProcessor 
prefiltering."
+)
+public class ChangeProcessorPrefilterTestConfig {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(ChangeProcessorPrefilterTestConfig.class);
+
+    private static final boolean DEFAULT_TESTMODE = false;
+    @Property(boolValue = DEFAULT_TESTMODE, label = "turns on or off the 
prefiltering test mode", 
+            description = "When set to true it puts prefiltering in a test 
mode. In the test mode the"
+                    + " prefilter is still evaluated but not applied - instead 
the result (whether or not"
+                    + " any events were delivered to the listener) is compared 
with the outcome of prefiltering."
+                    + " If prefiltering and normal filtering mismatch this is 
reported in as a log.warn."
+                    + " When set to false it leaves prefiltering in normal 
mode. Default is "
+            + DEFAULT_TESTMODE)
+    private static final String PROP_TESTMODE = "prefiltering.testmode";
+    
+    private boolean prefilteringTestmode = DEFAULT_TESTMODE;
+
+    @Activate
+    protected void activate(ComponentContext context, Map<String, ?> config) {
+        reconfig(config);
+        LOG.info("activate: prefilteringTestmode=" + prefilteringTestmode);
+        setTestMode();
+    }
+
+    @Modified
+    protected void modified(final Map<String, Object> config) {
+        reconfig(config);
+        LOG.info("modified: prefilteringTestmode=" + prefilteringTestmode);
+        setTestMode();
+    }
+    
+    private void reconfig(Map<String, ?> config) {
+        prefilteringTestmode = toBoolean(config.get(PROP_TESTMODE), 
DEFAULT_TESTMODE);
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        prefilteringTestmode = DEFAULT_TESTMODE;
+        LOG.info("deactivate: prefilteringTestmode=" + prefilteringTestmode + 
" (default)");
+        setTestMode();
+    }
+
+    private void setTestMode() {
+        ChangeProcessor.setPrefilteringTestMode(prefilteringTestmode);
+    }
+
+}

Propchange: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessorPrefilterTestConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to