You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/11/12 16:27:04 UTC

svn commit: r1541102 - in /sling/whiteboard/bdelacretaz/feature-flags: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/extensions/ src/main/java/org/apache/sli...

Author: bdelacretaz
Date: Tue Nov 12 15:27:04 2013
New Revision: 1541102

URL: http://svn.apache.org/r1541102
Log:
SLING-3148 - feature flags prototype

Added:
    sling/whiteboard/bdelacretaz/feature-flags/   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/pom.xml   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/src/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlags.java   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlagsProvider.java   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsDemoServlet.java   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsImpl.java   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RandomProvider.java   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RequestHeaderProvider.java   (with props)
    sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/ResourcePathProvider.java   (with props)

Propchange: sling/whiteboard/bdelacretaz/feature-flags/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Nov 12 15:27:04 2013
@@ -0,0 +1,14 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+derby.log
+jackrabbit
+sling
+

Added: sling/whiteboard/bdelacretaz/feature-flags/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/pom.xml?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/pom.xml (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/pom.xml Tue Nov 12 15:27:04 2013
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>18</version>
+    </parent>
+    
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.extensions.featureflags</artifactId>
+    <version>0.9.9-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Apache Sling Feature Flags prototype</name>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.apache.sling.extensions.featureflags.api</Export-Package>
+                        <Private-Package>org.apache.sling.extensions.featureflags.impl.*</Private-Package>
+                        <Sling-Initial-Content>SLING-CONTENT</Sling-Initial-Content>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.json</artifactId>
+            <version>2.0.6</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

Propchange: sling/whiteboard/bdelacretaz/feature-flags/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlags.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlags.java?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlags.java (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlags.java Tue Nov 12 15:27:04 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.sling.extensions.featureflags.api;
+
+import java.util.Collection;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+
+/** Simple feature flags service for Sling.
+ *  Uses {@link FeatureFlagsProvider} services
+ *  for the actual enabled/disabled decisions.
+ */
+public interface FeatureFlags {
+    /** True if the given feature flag is enabled for supplied request */
+    boolean isEnabled(String featureFlagName, SlingHttpServletRequest request);
+    
+    /** Get the list of active feature flags */
+    Collection<String> getFlagNames();
+}

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlags.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlags.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlagsProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlagsProvider.java?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlagsProvider.java (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlagsProvider.java Tue Nov 12 15:27:04 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.sling.extensions.featureflags.api;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+
+/** Service that implements the actual decision of
+ *  enabling a feature flag or not.
+ *  Not meant to be used directly, use 
+ *  {@link FeatureFlags} instead.
+ */
+public interface FeatureFlagsProvider {
+    /** True if the given feature flag is enabled for supplied request 
+     *  @return null means "don't care", otherwise Boolean indicates
+     *      whether the feature is enabled for supplied request
+     * */
+    boolean isEnabled(String featureFlagName, SlingHttpServletRequest request);
+    
+    /** Get the list of flag names that this provider supports */
+    String [] getFlagNames();
+}

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlagsProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/api/FeatureFlagsProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsDemoServlet.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsDemoServlet.java?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsDemoServlet.java (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsDemoServlet.java Tue Nov 12 15:27:04 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.sling.extensions.featureflags.impl;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.sling.SlingServlet;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.io.JSONWriter;
+import org.apache.sling.extensions.featureflags.api.FeatureFlags;
+
+@SuppressWarnings("serial")
+@SlingServlet(extensions="json",selectors="featureflags",resourceTypes="sling/servlet/default")
+public class FeatureFlagsDemoServlet extends SlingSafeMethodsServlet {
+
+    @Reference
+    private FeatureFlags featureFlags;
+    
+    @Override
+    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) 
+    throws ServletException, IOException {
+        response.setContentType("application/json");
+        response.setCharacterEncoding("UTF-8");
+        try {
+            final JSONWriter w = new JSONWriter(response.getWriter());
+            w.setTidy(true);
+            w.object();
+            w.key("featureFlags");
+            w.object();
+            for(String name : featureFlags.getFlagNames()) {
+                w.key(name).value(featureFlags.isEnabled(name, request));
+            }
+            w.endObject();
+            w.endObject();
+        } catch(JSONException je) {
+            throw (IOException)new IOException("JSONException in doGet").initCause(je);
+        }
+        response.getWriter().flush();
+    }
+}
\ No newline at end of file

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsDemoServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsDemoServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsImpl.java?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsImpl.java (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsImpl.java Tue Nov 12 15:27:04 2013
@@ -0,0 +1,111 @@
+/*
+ * 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.sling.extensions.featureflags.impl;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.extensions.featureflags.api.FeatureFlags;
+import org.apache.sling.extensions.featureflags.api.FeatureFlagsProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Implementation of the {@link FeatureFlags} service,
+ */
+@Component
+@Service(value=FeatureFlags.class)
+public class FeatureFlagsImpl implements FeatureFlags {
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    private final Map<String, FeatureFlagsProvider> providers = new HashMap<String, FeatureFlagsProvider>();
+    private ServiceTracker providersTracker;
+    private int lastTrackerCount = -1;
+    private BundleContext bundleContext;
+    
+    /** True if the given feature flag is enabled for supplied request */
+    public boolean isEnabled(String featureFlagName, SlingHttpServletRequest request) {
+        maybeLoadProviders();
+        
+        final FeatureFlagsProvider provider = providers.get(featureFlagName);
+        
+        if(provider == null) {
+            log.warn("No provider found for feature flag {}", featureFlagName);
+            return false;
+        }
+        
+        return provider.isEnabled(featureFlagName, request);
+    }
+    
+    public Collection<String> getFlagNames() {
+        maybeLoadProviders();
+        return Collections.unmodifiableSet(providers.keySet());
+    }
+
+    @Activate
+    protected void activate(ComponentContext ctx) {
+        bundleContext = ctx.getBundleContext();
+        providers.clear();
+        providersTracker = new ServiceTracker(bundleContext, FeatureFlagsProvider.class.getName(), null);
+        lastTrackerCount = -1;
+        providersTracker.open();
+    }
+    
+    @Deactivate
+    protected void deactivate(ComponentContext ctx) {
+        providersTracker.close();
+        providers.clear();
+        bundleContext = null;
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void maybeLoadProviders() {
+        if(providersTracker.getTrackingCount() != lastTrackerCount) {
+            synchronized (this) {
+                lastTrackerCount = providersTracker.getTrackingCount();
+                providers.clear();
+                final ServiceReference [] refs = providersTracker.getServiceReferences();
+                if(refs != null && refs.length > 0) {
+                    final List<ServiceReference> sorted = Arrays.asList(refs);
+                    Collections.sort(sorted);
+                    for(ServiceReference ref : sorted) {
+                        final FeatureFlagsProvider p = (FeatureFlagsProvider)bundleContext.getService(ref);
+                        for(String name : p.getFlagNames()) {
+                            // TODO warn for collisions?
+                            providers.put(name,  p);
+                        }
+                    }
+                }
+            }
+            log.info("FeatureFlagsProviders list reloaded: {}", providers);
+        }
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/FeatureFlagsImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RandomProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RandomProvider.java?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RandomProvider.java (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RandomProvider.java Tue Nov 12 15:27:04 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.sling.extensions.featureflags.impl.providers;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.extensions.featureflags.api.FeatureFlagsProvider;
+
+@Component
+@Service
+@Property(name="service.ranking", intValue=200)
+public class RandomProvider implements FeatureFlagsProvider {
+    public boolean isEnabled(String featureFlagName, SlingHttpServletRequest request) {
+        // TODO this is just a simplistic example meant to demonstrate the concept...
+        return Math.random() > 0.5;
+    }
+    
+    public String [] getFlagNames() {
+        return new String[] { "random.feature" };
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RandomProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RandomProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RequestHeaderProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RequestHeaderProvider.java?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RequestHeaderProvider.java (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RequestHeaderProvider.java Tue Nov 12 15:27:04 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.sling.extensions.featureflags.impl.providers;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.extensions.featureflags.api.FeatureFlagsProvider;
+
+@Component
+@Service
+@Property(name="service.ranking", intValue=300)
+public class RequestHeaderProvider implements FeatureFlagsProvider {
+    public static final String NAME = "request.header";
+    public static final String HEADER_NAME = "X-sling-feature";
+
+    public boolean isEnabled(String featureFlagName, SlingHttpServletRequest request) {
+        // TODO this is just a simplistic example meant to demonstrate the concept...
+        return request.getHeader(HEADER_NAME) != null;
+    }
+    
+    public String [] getFlagNames() {
+        return new String[] { "request.header.feature" };
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RequestHeaderProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/RequestHeaderProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/ResourcePathProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/ResourcePathProvider.java?rev=1541102&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/ResourcePathProvider.java (added)
+++ sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/ResourcePathProvider.java Tue Nov 12 15:27:04 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.sling.extensions.featureflags.impl.providers;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.extensions.featureflags.api.FeatureFlagsProvider;
+
+@Component
+@Service
+@Property(name="service.ranking", intValue=100)
+public class ResourcePathProvider implements FeatureFlagsProvider {
+    public static final String NAME = "resource.path.feature";
+
+    public boolean isEnabled(String featureFlagName, SlingHttpServletRequest request) {
+        return request.getResource().getPath().contains("/tmp/");
+    }
+    
+    public String [] getFlagNames() {
+        return new String[] { "resource.path.feature" };
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/ResourcePathProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/feature-flags/src/main/java/org/apache/sling/extensions/featureflags/impl/providers/ResourcePathProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL