incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1460424 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/resource/ jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ resour...
Date Sun, 24 Mar 2013 18:59:52 GMT
Author: cziegeler
Date: Sun Mar 24 18:59:52 2013
New Revision: 1460424

URL: http://svn.apache.org/r1460424
Log:
SLING-2796 :  Support refreshing of resource providers 

Added:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
  (with props)
Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java

Added: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java?rev=1460424&view=auto
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
(added)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
Sun Mar 24 18:59:52 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.api.resource;
+
+
+
+/**
+ * A resource provider might return the state when it was created and not
+ * update to the latest state.
+ * If the provider supports updating to the latest state, it should
+ * implement this method.
+ *
+ * This interface is only supported if the provider has been create through
+ * a {@link ResourceProviderFactory}.
+ *
+ * @see ResourceProviderFactory#getResourceProvider(java.util.Map)
+ * @see ResourceProviderFactory#getAdministrativeResourceProvider(java.util.Map)
+ *
+ * @since 2.3.0
+ */
+public interface RefreshableResourceProvider extends ResourceProvider {
+
+    /**
+     * The provider is updated to reflect the latest state.
+     * Resources which have changes pending are not discarded.
+     */
+    void refresh();
+}

Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java?rev=1460424&r1=1460423&r2=1460424&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
Sun Mar 24 18:59:52 2013
@@ -623,4 +623,12 @@ public interface ResourceResolver extend
      * @since 2.3
      */
     boolean isResourceType(final Resource resource, final String resourceType);
+
+    /**
+     * The resolver is updated to reflect the latest state.
+     * Resources which have changes pending are not discarded.
+     * @since 2.3
+     */
+    void refresh();
+
 }

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1460424&r1=1460423&r2=1460424&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
Sun Mar 24 18:59:52 2013
@@ -45,6 +45,7 @@ import org.apache.sling.api.resource.Mod
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.QueriableResourceProvider;
 import org.apache.sling.api.resource.QuerySyntaxException;
+import org.apache.sling.api.resource.RefreshableResourceProvider;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -70,6 +71,7 @@ public class JcrResourceProvider
                DynamicResourceProvider,
                AttributableResourceProvider,
                QueriableResourceProvider,
+               RefreshableResourceProvider,
                ModifyingResourceProvider {
 
     /** column name for node path */
@@ -503,4 +505,15 @@ public class JcrResourceProvider
         }
         return false;
     }
+
+    /**
+     * @see org.apache.sling.api.resource.RefreshableResourceProvider#refresh()
+     */
+    public void refresh() {
+        try {
+            this.session.refresh(true);
+        } catch (final RepositoryException ignore) {
+            log.warn("Unable to refresh session.", ignore);
+        }
+    }
 }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1460424&r1=1460423&r2=1460424&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Sun Mar 24 18:59:52 2013
@@ -1164,4 +1164,11 @@ public class ResourceResolverImpl extend
         }
         return result;
     }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceResolver#refresh()
+     */
+    public void refresh() {
+        this.context.refresh();
+    }
 }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java?rev=1460424&r1=1460423&r2=1460424&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java
Sun Mar 24 18:59:52 2013
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.apache.sling.api.resource.DynamicResourceProvider;
 import org.apache.sling.api.resource.ModifyingResourceProvider;
 import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.RefreshableResourceProvider;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
 
@@ -41,6 +42,9 @@ public class ResourceResolverContext {
     /** A set of all dynamic providers (for closing them later on) */
     private final Set<DynamicResourceProvider> dynamicProviders = new HashSet<DynamicResourceProvider>();
 
+    /** A set of all refreshable providers */
+    private final Set<RefreshableResourceProvider> refreshableProviders = new HashSet<RefreshableResourceProvider>();
+
     /** A set of all modifying providers */
     private final Set<ModifyingResourceProvider> modifyingProviders = new HashSet<ModifyingResourceProvider>();
 
@@ -87,6 +91,9 @@ public class ResourceResolverContext {
         if (provider instanceof ModifyingResourceProvider) {
             this.modifyingProviders.add((ModifyingResourceProvider) provider);
         }
+        if (provider instanceof RefreshableResourceProvider) {
+            this.refreshableProviders.add((RefreshableResourceProvider)provider);
+        }
     }
 
     /**
@@ -121,6 +128,7 @@ public class ResourceResolverContext {
         }
         this.dynamicProviders.clear();
         this.providers.clear();
+        this.refreshableProviders.clear();
     }
 
     /**
@@ -152,4 +160,13 @@ public class ResourceResolverContext {
         }
         return false;
     }
+
+    /**
+     * Refresh
+     */
+    public void refresh() {
+        for(final RefreshableResourceProvider provider : this.refreshableProviders) {
+            provider.refresh();
+        }
+    }
 }



Mime
View raw message