You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/07/10 14:41:27 UTC

svn commit: r792925 - /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java

Author: gnodet
Date: Fri Jul 10 12:41:26 2009
New Revision: 792925

URL: http://svn.apache.org/viewvc?rev=792925&view=rev
Log:
Use a SoftReference to hold schemas so that the memory can be claimed if needed

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java?rev=792925&r1=792924&r2=792925&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/NamespaceHandlerRegistryImpl.java Fri Jul 10 12:41:26 2009
@@ -34,6 +34,8 @@
 import java.util.Iterator;
 import java.util.HashSet;
 import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.lang.ref.Reference;
 
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -72,7 +74,7 @@
     private final Map<URI, NamespaceHandler> handlers;
     private final ServiceTracker tracker;
     private final Map<Listener, Boolean> listeners;
-    private final Map<Set<URI>, Schema> schemas = new LRUMap<Set<URI>, Schema>(10);
+    private final Map<Set<URI>, Reference<Schema>> schemas = new LRUMap<Set<URI>, Reference<Schema>>(10);
     private SchemaFactory schemaFactory;
 
     public NamespaceHandlerRegistryImpl(BundleContext bundleContext) {
@@ -222,7 +224,7 @@
         // they won't be used at all
         for (Set<URI> key : schemas.keySet()) {
             if (key.containsAll(namespaces)) {
-                schema = schemas.get(key);
+                schema = schemas.get(key).get();
                 break;
             }
         }
@@ -249,7 +251,7 @@
                     }
                 }
                 schema = getSchemaFactory().newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
-                schemas.put(namespaces, schema);
+                schemas.put(namespaces, new SoftReference<Schema>(schema));
             } finally {
                 for (StreamSource s : schemaSources) {
                     try {
@@ -280,7 +282,7 @@
         return schemaFactory;
     }
 
-    private static class LRUMap<K,V> extends AbstractMap<K,V> {
+    public static class LRUMap<K,V> extends AbstractMap<K,V> {
 
         private final int bound;
         private final LinkedList<Entry<K,V>> entries = new LinkedList<Entry<K,V>>();