Sfoglia il codice sorgente

fix: Cache#get - call to relase

Ranides Atterwim 9 anni fa
parent
commit
ad853add7b

+ 4 - 4
assira/src/main/java/net/ranides/assira/collection/lists/NativeArrayList.java

@@ -52,9 +52,9 @@ public final class NativeArrayList {
 	public static <Auto> List<Auto> $wrap(Object array, int offset, int length) {
 		return (List)wrap(array, offset, length);
 	}
-	
-    
-    private static final class NativeList extends AbstractList<Object> implements Serializable {
+
+
+    public static final class NativeList extends AbstractList<Object> implements Serializable {
         
         private static final long serialVersionUID = 1L;
 		
@@ -107,7 +107,7 @@ public final class NativeArrayList {
 		
     }
 
-	private static final class IntegerList extends AIntList {
+    public static final class IntegerList extends AIntList {
         
         private static final long serialVersionUID = 1L;
 		

+ 6 - 4
assira/src/main/java/net/ranides/assira/collection/maps/Cache.java

@@ -115,6 +115,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
     @Override
     public V get(Object key) {
         synchronized(this) {
+            map.release();
             V result = map.getValue(key);
             if (null != result) {
                 list.hold(result);
@@ -125,6 +126,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
     
     public V get(K key, Supplier<V> supplier) {
         synchronized(this) {
+            map.release();
             V result = map.getValue(key);
             if (null == result) {
                 map.putValue(key, result = supplier.get());
@@ -242,7 +244,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
     
     @SuppressWarnings("unchecked")
     private static <TK> TK asKey(Reference<?> ref) {
-        return (ref != null) ? ((KRef<TK,?>)ref).key : null;
+        return ((KRef<TK,?>)ref).key;
     }
     
     private static class KRef<K,V> extends SoftReference<V> {
@@ -288,7 +290,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
         }
         
         @Override
-        protected boolean removeEldestEntry(Entry<K, TRef<K,V>> eldest) {
+        protected boolean removeEldestEntry(Map.Entry<K, TRef<K,V>> eldest) {
             return this.size() > maxsize || eldest.getValue().time.isAfter(Instant.now());
         }
         
@@ -299,7 +301,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
                 while ( null != (ref = queue.poll()) ) { remove( asKey(ref) ); }
                 
                 Instant now = Instant.now();
-                Iterator<Entry<K, TRef<K, V>>> iterator = entrySet().iterator();
+                Iterator<Map.Entry<K, TRef<K, V>>> iterator = entrySet().iterator();
                 while(iterator.hasNext()) {
                     if(iterator.next().getValue().time.isBefore(now)) {
                         break;
@@ -341,7 +343,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
         }
         
         @Override
-        protected boolean removeEldestEntry(Entry<K, KRef<K,V>> eldest) {
+        protected boolean removeEldestEntry(Map.Entry<K, KRef<K,V>> eldest) {
             return this.size() > maxsize;
         }