Author: fmeschbe
Date: Fri Apr 3 08:16:42 2009
New Revision: 761559
URL: http://svn.apache.org/viewvc?rev=761559&view=rev
Log:
SLING-911 synchronize provider (un)registration and define a new exception
to purvey the existing resource provider with the same path for duplicate
registrations
Added:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryException.java
(with props)
Modified:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
Modified:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=761559&r1=761558&r2=761559&view=diff
==============================================================================
---
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
(original)
+++
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
Fri Apr 3 08:16:42 2009
@@ -40,6 +40,7 @@
import org.apache.sling.jcr.resource.internal.helper.MapEntries;
import org.apache.sling.jcr.resource.internal.helper.Mapping;
import org.apache.sling.jcr.resource.internal.helper.ResourceProviderEntry;
+import
org.apache.sling.jcr.resource.internal.helper.ResourceProviderEntryException;
import
org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderEntry;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
@@ -501,18 +502,25 @@
ResourceProvider provider = (ResourceProvider)
componentContext.locateService(
"ResourceProvider", reference);
- for (String root : roots) {
- // cut off trailing slash
- if (root.endsWith("/") && root.length() > 1) {
- root = root.substring(0, root.length() - 1);
- }
+ // synchronized insertion of new resource providers into
+ // the tree to not inadvertandly loose an entry
+ synchronized (this) {
+
+ for (String root : roots) {
+ // cut off trailing slash
+ if (root.endsWith("/") && root.length() > 1) {
+ root = root.substring(0, root.length() - 1);
+ }
- try {
- rootProviderEntry.addResourceProvider(root, provider);
- } catch (IllegalStateException ise) {
- log.error(
- "bindResourceProvider: A ResourceProvider for {}
is already registered",
- root);
+ try {
+ rootProviderEntry.addResourceProvider(root,
+ provider);
+ } catch (ResourceProviderEntryException rpee) {
+ log.error(
+ "bindResourceProvider: Cannot register
ResourceProvider {} for {}: ResourceProvider {} is already registered",
+ new Object[] { provider, root,
+ rpee.getExisting().getResourceProvider()
});
+ }
}
}
}
@@ -522,16 +530,22 @@
protected void unbindResourceProvider(ServiceReference reference) {
String[] roots =
OsgiUtil.toStringArray(reference.getProperty(ResourceProvider.ROOTS));
if (roots != null && roots.length > 0) {
- for (String root : roots) {
- // cut off trailing slash
- if (root.endsWith("/") && root.length() > 1) {
- root = root.substring(0, root.length() - 1);
- }
- // TODO: Do not remove this path, if another resource
- // owns it. This may be the case if adding the provider
- // yielded an IllegalStateException
- rootProviderEntry.removeResourceProvider(root);
+ // synchronized insertion of new resource providers into
+ // the tree to not inadvertandly loose an entry
+ synchronized (this) {
+
+ for (String root : roots) {
+ // cut off trailing slash
+ if (root.endsWith("/") && root.length() > 1) {
+ root = root.substring(0, root.length() - 1);
+ }
+
+ // TODO: Do not remove this path, if another resource
+ // owns it. This may be the case if adding the provider
+ // yielded an ResourceProviderEntryException
+ rootProviderEntry.removeResourceProvider(root);
+ }
}
}
}
Modified:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java?rev=761559&r1=761558&r2=761559&view=diff
==============================================================================
---
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
(original)
+++
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
Fri Apr 3 08:16:42 2009
@@ -221,10 +221,22 @@
};
}
+ /**
+ * Adds the given resource provider into the tree for the given prefix.
+ *
+ * @return <code>true</code> if the provider could be entered into the
+ * subtree below this entry. Otherwise <code>false</code> is
+ * returned.
+ * @throws ResourceProviderEntryException if a resource provider for the
+ * given prefix has already been registered at or below this
+ * entry.
+ */
public boolean addResourceProvider(String prefix, ResourceProvider
provider) {
if (prefix.equals(this.path)) {
- throw new IllegalStateException(
- "ResourceProviderEntry for prefix already exists");
+
+ throw new ResourceProviderEntryException(
+ "ResourceProviderEntry for prefix already exists", this);
+
} else if (prefix.startsWith(this.prefix)) {
// consider relative path for further checks
Added:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryException.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryException.java?rev=761559&view=auto
==============================================================================
---
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryException.java
(added)
+++
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryException.java
Fri Apr 3 08:16:42 2009
@@ -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.jcr.resource.internal.helper;
+
+/**
+ * The <code>ResourceProviderEntryException</code> is thrown to indicate a
+ * resource provider has already been registered for a given prefix path.
+ */
+public class ResourceProviderEntryException extends IllegalArgumentException {
+
+ private final ResourceProviderEntry existing;
+
+ ResourceProviderEntryException(String message, ResourceProviderEntry
existing) {
+ super(message);
+ this.existing = existing;
+ }
+
+ public ResourceProviderEntry getExisting() {
+ return existing;
+ }
+}
Propchange:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntryException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url