baliuka 02/02/10 02:00:12
Modified: simplestore/src/java/org/apache/commons/simplestore
SoftRefMemoryStore.java Store.java
SynchronizedStore.java
simplestore/src/sample/org/apache/commons/simplestore/persistence
PersistenceManager.java TransactionImpl.java
simplestore/src/test/org/apache/commons/simplestore
TestSoftRefMemoryStore.java
Removed: simplestore/src/java/org/apache/commons/simplestore
Reachable.java Swap.java
Log:
Removed some unused code
Revision Changes Path
1.11 +13 -46
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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SoftRefMemoryStore.java 9 Feb 2002 18:45:11 -0000 1.10
+++ SoftRefMemoryStore.java 10 Feb 2002 10:00:12 -0000 1.11
@@ -68,7 +68,7 @@
* [EMAIL PROTECTED]</a>
*@author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- *@version $Id: SoftRefMemoryStore.java,v 1.10 2002/02/09 18:45:11 froehlich Exp
$
+ *@version $Id: SoftRefMemoryStore.java,v 1.11 2002/02/10 10:00:12 baliuka Exp $
*/
public class SoftRefMemoryStore
implements Store {
@@ -79,7 +79,7 @@
private int m_current = 0;
private Map m_map;
private ReferenceQueue m_queue = new ReferenceQueue();
- private Swap m_swap;
+
/**
* Creates new SoftRefMemoryStore
@@ -88,8 +88,8 @@
*@param swap Description of Parameter
*@param maxStrongRefCount Description of Parameter
*/
- protected SoftRefMemoryStore(Map map, Swap swap, int maxStrongRefCount) {
- this.m_swap = swap;
+ protected SoftRefMemoryStore(Map map, int maxStrongRefCount) {
+
this.m_map = map;
if (maxStrongRefCount < 0) {
@@ -102,8 +102,8 @@
}
}
- public static Store getInstance(Map map, Swap swap, int maxStrongRef) {
- return new SynchronizedStore(new SoftRefMemoryStore(map, swap,
maxStrongRef));
+ public static Store getInstance(Map map, int maxStrongRef) {
+ return new SynchronizedStore(new SoftRefMemoryStore(map, maxStrongRef));
}
/**
@@ -118,14 +118,9 @@
SoftRef ref = (SoftRef) m_map.get(key);
if (ref != null) {
- Object value = ref.get();
-
- if (value != null && value instanceof StrongRef) {
- object = ((StrongRef) value).object;
- } else {
- object = value;
- }
+ object = ref.get();
}
+
addStrongRef(object);
return object;
}
@@ -178,19 +173,10 @@
m_map.clear();
}
- private SoftRef makeValue(Object key, Object value, ReferenceQueue queue, Swap
swap) {
- if (swap == null || value == null) {
+ private SoftRef makeValue(Object key, Object value, ReferenceQueue queue) {
+
return new SoftRef(key, value, queue);
- } else {
- 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;
- }
+
}
// remove unused keys
@@ -214,7 +200,7 @@
}
private void internalStoreObject(Object key, Object object) {
- SoftRef ref = makeValue(key, object, m_queue, m_swap);
+ SoftRef ref = makeValue(key, object, m_queue);
addStrongRef(ref.get());
m_map.put(key, ref);
}
@@ -228,25 +214,6 @@
}
}
- static class StrongRef extends Object {
- Reachable object;
- Object key;
- 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() {
- return object;
- }
-
- protected void finalize() throws Throwable {
- super.finalize();
- queue.add(key, object);
- }
- }
+
}
1.12 +1 -8
jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/Store.java
Index: Store.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/Store.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Store.java 9 Feb 2002 18:45:11 -0000 1.11
+++ Store.java 10 Feb 2002 10:00:12 -0000 1.12
@@ -59,22 +59,15 @@
*
* @author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- * @version $Id: Store.java,v 1.11 2002/02/09 18:45:11 froehlich Exp $
+ * @version $Id: Store.java,v 1.12 2002/02/10 10:00:12 baliuka Exp $
*/
public interface Store {
-
- void clear();
Object get(Object key);
- boolean isEmpty();
-
void put(Object key, Object value);
Object remove(Object key);
- boolean containsKey(Object key);
-
- int size();
}
1.6 +2 -29
jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/SynchronizedStore.java
Index: SynchronizedStore.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/SynchronizedStore.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SynchronizedStore.java 9 Feb 2002 18:45:11 -0000 1.5
+++ SynchronizedStore.java 10 Feb 2002 10:00:12 -0000 1.6
@@ -64,7 +64,7 @@
* [EMAIL PROTECTED]</a>
*@author Gerhard Froehlich <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- *@version $Id: SynchronizedStore.java,v 1.5 2002/02/09 18:45:11 froehlich Exp $
+ *@version $Id: SynchronizedStore.java,v 1.6 2002/02/10 10:00:12 baliuka Exp $
*/
final class SynchronizedStore
implements Store {
@@ -95,12 +95,7 @@
}
}
- public boolean isEmpty() {
- synchronized (store) {
- return store.isEmpty();
- }
- }
-
+
/**
* Remove the object associated to the given key.
*
@@ -113,17 +108,6 @@
}
}
- /**
- * Indicates if the given key is associated to a contained object.
- *
- *@param key the Key Object
- *@return
- */
- public boolean containsKey(Object key) {
- synchronized (store) {
- return store.containsKey(key);
- }
- }
public void put(Object key, Object value) {
synchronized (store) {
@@ -131,16 +115,5 @@
}
}
- public int size() {
- synchronized (store) {
- return store.size();
- }
- }
-
- public void clear() {
- synchronized (store) {
- store.clear();
- }
- }
}
1.4 +2 -2
jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/PersistenceManager.java
Index: PersistenceManager.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/PersistenceManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PersistenceManager.java 9 Feb 2002 18:51:43 -0000 1.3
+++ PersistenceManager.java 10 Feb 2002 10:00:12 -0000 1.4
@@ -59,7 +59,7 @@
/**
*@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- *@version $Id: PersistenceManager.java,v 1.3 2002/02/09 18:51:43 froehlich Exp $
+ *@version $Id: PersistenceManager.java,v 1.4 2002/02/10 10:00:12 baliuka Exp $
*/
public class PersistenceManager {
@@ -70,7 +70,7 @@
private Storage storage;
private TransactionManager transactionManager;
- private Store store = SoftRefMemoryStore.getInstance(new java.util.HashMap(),
null, 0xFF);
+ private Store store = SoftRefMemoryStore.getInstance(new java.util.HashMap(),
0xFF);
/**
* Creates new PersiatenceManager
1.3 +2 -2
jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/TransactionImpl.java
Index: TransactionImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/simplestore/src/sample/org/apache/commons/simplestore/persistence/TransactionImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TransactionImpl.java 9 Feb 2002 18:51:43 -0000 1.2
+++ TransactionImpl.java 10 Feb 2002 10:00:12 -0000 1.3
@@ -58,12 +58,12 @@
/**
*@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- *@version $Id: TransactionImpl.java,v 1.2 2002/02/09 18:51:43 froehlich Exp $
+ *@version $Id: TransactionImpl.java,v 1.3 2002/02/10 10:00:12 baliuka Exp $
*/
public class TransactionImpl implements InternalTransaction {
- private static Store instances = SoftRefMemoryStore.getInstance(new
java.util.HashMap(), null, 0x00);
+ private static Store instances = SoftRefMemoryStore.getInstance(new
java.util.HashMap(), 0x00);
int threadId = getCurrentThreadId();
InternalTransaction transaction;
1.10 +7 -46
jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSoftRefMemoryStore.java
Index: TestSoftRefMemoryStore.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSoftRefMemoryStore.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestSoftRefMemoryStore.java 9 Feb 2002 19:19:01 -0000 1.9
+++ TestSoftRefMemoryStore.java 10 Feb 2002 10:00:12 -0000 1.10
@@ -65,7 +65,7 @@
* [EMAIL PROTECTED]</a>
*@author Juozas Baliuka <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
- *@version $Id: TestSoftRefMemoryStore.java,v 1.9 2002/02/09 19:19:01 froehlich
Exp $
+ *@version $Id: TestSoftRefMemoryStore.java,v 1.10 2002/02/10 10:00:12 baliuka
Exp $
*/
public class TestSoftRefMemoryStore extends TestStore {
@@ -88,27 +88,11 @@
}
public Store makeStore() {
- Swap swap =
- new Swap() {
- // this means GC decided memory is low and
- // SoftRefMemoryStore decided object is "old"
- // value wrapper calls this method from finalize
- // Queue implementation can write object to swap here
- // It can use JMS to send Object Message
- public void add(Object key, Reachable object) {
- System.out.println(key + " Object added to swap " +
object.toString().substring(0, 20));
- }
- // do nothing at this time, becouse we added no object to Qeue at
this time
- // Queue implementation can add objects to Batch, then this method
can be usd to test Queue
- // It can use Thread in stand alone application to execute Batch
-
-
- };
- SoftRefMemoryStore store = new SoftRefMemoryStore(new HashMap(ITERATIONS),
swap, MAX_STRONG_REFS);
+ SoftRefMemoryStore store = new SoftRefMemoryStore(new HashMap(ITERATIONS),
MAX_STRONG_REFS);
return store;
}
- public void testSwaping() {
+ public void testStore() {
assertTrue("try to set ITERATIONS > MAX_STRONG_REFS ", ITERATIONS >
MAX_STRONG_REFS);
@@ -116,12 +100,9 @@
java.util.Arrays.fill(testObject, '.');
Object key = new Integer(0);
Object value = new String(testObject);
- ValueObject valueObj = new ValueObject(value);
- store.put(key, valueObj);
+ store.put(key, value);
for (int i = 1; i < ITERATIONS; i++) {
- Object obj = new String(testObject);
- obj = new ValueObject(obj);
- store.put(new Integer(i), obj);
+ store.put(new Integer(i), new String(testObject));
_testGet(i);
}
// get something
@@ -129,7 +110,7 @@
i < ITERATIONS / 2; i++) {
_testGet(i);
}
- assertEquals("Lost Strong Referense in cache", store.get(key), valueObj);
+ assertEquals("Lost Strong Referense in cache", store.get(key), value);
}
@@ -160,26 +141,6 @@
}
}
- public static class ValueObject implements Reachable {
- Object reference;
- Object value;
-
- public ValueObject(Object value) {
- this.value = value;
- }
-
- public void setReference(Object reference) {
- this.reference = reference;
- }
-
- public String toString() {
- return value != null ? value.toString() : null;
- }
-
- Object getValue() {
- return value;
- }
-
- }
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>