You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/09/02 10:05:51 UTC
svn commit: r991844 - in /sling/trunk:
bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
launchpad/builder/src/main/bundles/list.xml
Author: cziegeler
Date: Thu Sep 2 08:05:50 2010
New Revision: 991844
URL: http://svn.apache.org/viewvc?rev=991844&view=rev
Log:
SLING-1720 : Classloader cache is not synced
Modified:
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
sling/trunk/launchpad/builder/src/main/bundles/list.xml
Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java?rev=991844&r1=991843&r2=991844&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java (original)
+++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java Thu Sep 2 08:05:50 2010
@@ -140,7 +140,7 @@ public final class DynamicRepositoryClas
* @see #NOT_FOUND_RESOURCE
* @see #findClassLoaderResource(String)
*/
- private final Map<String, ClassLoaderResource> cache = new HashMap<String, ClassLoaderResource>();
+ private final Map<String, ClassLoaderResource> cache = new HashMap<String, ClassLoaderResource>();
/**
* Flag indicating whether the {@link #destroy()} method has already been
@@ -261,16 +261,20 @@ public final class DynamicRepositoryClas
// clear the cache of loaded resources and flush cached class
// introspections of the JavaBean framework
- final Iterator<ClassLoaderResource> ci = cache.values().iterator();
- while ( ci.hasNext() ) {
- final ClassLoaderResource res = ci.next();
- if (res.getLoadedClass() != null) {
- Introspector.flushFromCaches(res.getLoadedClass());
- res.setLoadedClass(null);
+ synchronized ( cache ) {
+ final Iterator<ClassLoaderResource> ci = cache.values().iterator();
+ while ( ci.hasNext() ) {
+ final ClassLoaderResource res = ci.next();
+ if (res.getLoadedClass() != null) {
+ Introspector.flushFromCaches(res.getLoadedClass());
+ res.setLoadedClass(null);
+ }
}
+ cache.clear();
+ }
+ synchronized ( modTimeCache ) {
+ modTimeCache.clear();
}
- cache.clear();
- modTimeCache.clear();
}
//---------- URLClassLoader overwrites -------------------------------------
@@ -389,10 +393,12 @@ public final class DynamicRepositoryClas
* destroyed.
*/
private void cleanCache() {
- final Iterator<ClassLoaderResource> ci = this.cache.values().iterator();
- while (ci.hasNext()) {
- if (ci.next() == NOT_FOUND_RESOURCE) {
- ci.remove();
+ synchronized ( cache ) {
+ final Iterator<ClassLoaderResource> ci = this.cache.values().iterator();
+ while (ci.hasNext()) {
+ if (ci.next() == NOT_FOUND_RESOURCE) {
+ ci.remove();
+ }
}
}
}
@@ -515,30 +521,32 @@ public final class DynamicRepositoryClas
* destroyed.
*/
private ClassLoaderResource findClassLoaderResource(String name) {
-
+ ClassLoaderResource res = null;
// check for cached resources first
- ClassLoaderResource res = cache.get(name);
- if (res == NOT_FOUND_RESOURCE) {
- log.debug("Resource '{}' known to not exist in class path", name);
- return null;
- } else if (res == null) {
- // walk the repository list and try to find the resource
- for (int i = 0; i < repository.length; i++) {
- final ClassPathEntry cp = repository[i];
- log.debug("Checking {}", cp);
-
- res = cp.getResource(name);
- if (res != null) {
- log.debug("Found resource in {}, created ", res, new Date(
- res.getLastModificationTime()));
- cache.put(name, res);
- break;
- }
- }
- if ( res == null ) {
- log.debug("No classpath entry contains {}", name);
- cache.put(name, NOT_FOUND_RESOURCE);
+ synchronized ( cache ) {
+ res = cache.get(name);
+ if (res == NOT_FOUND_RESOURCE) {
+ log.debug("Resource '{}' known to not exist in class path", name);
return null;
+ } else if (res == null) {
+ // walk the repository list and try to find the resource
+ for (int i = 0; i < repository.length; i++) {
+ final ClassPathEntry cp = repository[i];
+ log.debug("Checking {}", cp);
+
+ res = cp.getResource(name);
+ if (res != null) {
+ log.debug("Found resource in {}, created ", res, new Date(
+ res.getLastModificationTime()));
+ cache.put(name, res);
+ break;
+ }
+ }
+ if ( res == null ) {
+ log.debug("No classpath entry contains {}", name);
+ cache.put(name, NOT_FOUND_RESOURCE);
+ return null;
+ }
}
}
// if it could be found, we register it with the caches
@@ -547,7 +555,9 @@ public final class DynamicRepositoryClas
Property prop = res.getExpiryProperty();
if (prop != null) {
try {
- modTimeCache.put(prop.getPath(), res);
+ synchronized ( modTimeCache ) {
+ modTimeCache.put(prop.getPath(), res);
+ }
} catch (RepositoryException re) {
log.warn("Cannot register the resource " + res +
" for expiry", re);
@@ -669,7 +679,10 @@ public final class DynamicRepositoryClas
log.debug(
"onEvent: Item {} has been modified, checking with cache", path);
- ClassLoaderResource resource = modTimeCache.get(path);
+ final ClassLoaderResource resource;
+ synchronized ( modTimeCache ) {
+ resource = modTimeCache.get(path);
+ }
if (resource != null) {
log.debug("pageModified: Expiring cache entry {}", resource);
expireResource(resource);
Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=991844&r1=991843&r2=991844&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Thu Sep 2 08:05:50 2010
@@ -111,7 +111,7 @@
<bundle>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.jcr.classloader</artifactId>
- <version>3.1.2</version>
+ <version>3.1.3-SNAPSHOT</version>
</bundle>
<bundle>
<groupId>org.apache.sling</groupId>