donaldp 2002/08/30 21:31:27
Modified: i18n/src/java/org/apache/avalon/excalibur/i18n
ResourceManager.java
Log:
Made resourceManager store resource mappings using weak-references.
This will allow them to be reclaimed in time.
Revision Changes Path
1.16 +36 -4
jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n/ResourceManager.java
Index: ResourceManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n/ResourceManager.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ResourceManager.java 7 Aug 2002 05:44:03 -0000 1.15
+++ ResourceManager.java 31 Aug 2002 04:31:27 -0000 1.16
@@ -7,6 +7,7 @@
*/
package org.apache.avalon.excalibur.i18n;
+import java.lang.ref.WeakReference;
import java.util.HashMap;
/**
@@ -39,16 +40,47 @@
public static final Resources getBaseResources( final String baseName,
final ClassLoader
classLoader )
{
- //TODO: Make these weak references????
- Resources packet = (Resources)c_resources.get( baseName );
-
+ Resources packet = getCachedResource( baseName );
if( null == packet )
{
packet = new Resources( baseName, classLoader );
- c_resources.put( baseName, packet );
+ putCachedResource( baseName, packet );
}
return packet;
+ }
+
+ /**
+ * Cache specified resource in weak reference.
+ *
+ * @param baseName the resource key
+ * @param resources the resources object
+ */
+ private static final void putCachedResource( final String baseName,
+ final Resources resources )
+ {
+ c_resources.put( baseName,
+ new WeakReference( resources ) );
+ }
+
+ /**
+ * Retrieve cached resource.
+ *
+ * @param baseName the resource key
+ * @return resources the resources object
+ */
+ private static final Resources getCachedResource( final String baseName )
+ {
+ final WeakReference weakReference =
+ (WeakReference)c_resources.get( baseName );
+ if( null == weakReference )
+ {
+ return null;
+ }
+ else
+ {
+ return (Resources)weakReference.get();
+ }
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>