froehlich 02/01/27 09:04:17 Modified: simplestore/src/java/org/apache/commons/simplestore Swap.java SoftRefMemoryStore.java Added: simplestore/src/java/org/apache/commons/simplestore Reachable.java Log: applied more patches from Juozas Baliuka [[EMAIL PROTECTED]] Revision Changes Path 1.2 +2 -9 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/Swap.java Index: Swap.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/Swap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Swap.java 26 Jan 2002 12:00:56 -0000 1.1 +++ Swap.java 27 Jan 2002 17:04:17 -0000 1.2 @@ -18,21 +18,14 @@ * * @author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - * @version $Id: Swap.java,v 1.1 2002/01/26 12:00:56 froehlich Exp $ + * @version $Id: Swap.java,v 1.2 2002/01/27 17:04:17 froehlich Exp $ */ public interface Swap { - - - /** removes and returns the first object from Queue - * @return null if Queue is empty - */ - public Object poll(); - /** Adds object to Queue * @param object not null refence */ - public void add(Object object); + public void add(Object key,Reachable object); } 1.8 +21 -13 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/SoftRefMemoryStore.java Index: SoftRefMemoryStore.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/SoftRefMemoryStore.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SoftRefMemoryStore.java 26 Jan 2002 16:19:20 -0000 1.7 +++ SoftRefMemoryStore.java 27 Jan 2002 17:04:17 -0000 1.8 @@ -20,7 +20,7 @@ * [EMAIL PROTECTED]</a> * @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> - * @version $Id: SoftRefMemoryStore.java,v 1.7 2002/01/26 16:19:20 froehlich Exp $ + * @version $Id: SoftRefMemoryStore.java,v 1.8 2002/01/27 17:04:17 froehlich Exp $ */ public class SoftRefMemoryStore implements Store { @@ -42,11 +42,13 @@ } static class StrongRef extends java.lang.Object{ - Object object; + Reachable object; + Object key; Swap queue; - private StrongRef(Object object, Swap queue ) { + private StrongRef(Object key,Reachable object, Swap queue ) { this.queue = queue;// used in finalize this.object = object;// add strong reference to value + this.key = key; } public Object get(){ @@ -55,16 +57,22 @@ protected void finalize() throws java.lang.Throwable { super.finalize(); - queue.add(object); + queue.add(key,object); } } - private Object makeValue(Object key, Object value,java.lang.ref.ReferenceQueue queue, Swap swap ){ - if( swap == null ){ + private SoftRef makeValue(Object key, Object value,java.lang.ref.ReferenceQueue queue, Swap swap ){ + if( swap == null || value == null ){ return new SoftRef( key, value, queue); } else{ - return new SoftRef( key, new StrongRef( value, swap ), queue); + if ( !( value instanceof Reachable ) ) + throw new java.lang.IllegalStateException("Value not Reachable in Swap "); + Reachable val = (Reachable)value; + StrongRef strong = new StrongRef( key , val, swap ); + SoftRef ref = new SoftRef( key, strong , queue); + val.setReference( strong ); + return ref; } } @@ -89,7 +97,7 @@ // remove unused keys private void removeSoftRef(){ SoftRef ref = (SoftRef)queue.poll(); - + while( ref != null ) { map.remove(ref.key); if(DEBUG) { @@ -106,10 +114,10 @@ } private void internalStoreObject(Object key, Object object) { - SoftRef ref = (SoftRef)makeValue(key,object,queue,swap); - addStrongRef(ref.get()); - map.put(key,ref); - } + SoftRef ref = makeValue(key,object,queue,swap); + addStrongRef(ref.get()); + map.put(key,ref); + } /** * Remove the object associated to the given key. @@ -135,8 +143,8 @@ * Frees some object out of the Store. */ public void free() { - if( strongRefs != null ) - java.util.Arrays.fill(strongRefs,null); + if( strongRefs != null ) + java.util.Arrays.fill(strongRefs,null); removeSoftRef(); } 1.1 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/Reachable.java Index: Reachable.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.commons.simplestore; /** * * @author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]"> * [EMAIL PROTECTED]</a> * @version $Id: Reachable.java,v 1.1 2002/01/27 17:04:17 froehlich Exp $ */ public interface Reachable { /** Must save strong refense on parameter, * This interface is used for values then Store is used with * Swap. * Sample impl : * class MyValueObject implements Reachable{ * Object reference; * Object value; * public MyValueObject( Object value){ * this.value = value; * } * public void setReference(Object reference) { * this.reference = reference; * } * public Object getValue(){ * return value; * } * } * * @param object value object must save strong refernce on parameter. */ public void setReference(Object object); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>