X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fstorage%2Fstore%2FStoreContainer.java;fp=source%2Fmir%2Fstorage%2Fstore%2FStoreContainer.java;h=397179f8dfa63f105c4cf62847ae6c88c18e0bdc;hb=6fb36d4e86dce331db03a398c8a995ee93e348d0;hp=47135308d330a83ed5fa062ba965ffbea07d3dcf;hpb=1149ec9b078b0f9175b9c2d006313e6810e46ffb;p=mir.git diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java index 47135308..397179f8 100755 --- a/source/mir/storage/store/StoreContainer.java +++ b/source/mir/storage/store/StoreContainer.java @@ -28,6 +28,8 @@ public class StoreContainer { private StoreContainerType stocType; private int maxSize=DEFAULT_SIZE; private int uniqueId; + private int addCount=0,removeCount=0,storeOutCount; + private int hitCount=0,missCount=0; private StoreContainer() {}; @@ -43,25 +45,35 @@ public class StoreContainer { } public StorableObject use(StoreIdentifier sid) { - // find sid in LinkedList or die - // move sid to head of linked list - // return reference on object - return null; + int hit = container.indexOf(sid); + if (hit>0) { + StoreIdentifier hitSid = (StoreIdentifier)container.get(hit); + if ( hitSid!=null ) { + hitCount++; + return hitSid.use(); + } + } + missCount++; + return null; } public boolean has(StoreIdentifier sid) { - return true; // yes yes + return container.contains(sid); } public void add(StoreIdentifier sid) { if ( sid != null && sid.hasReference() ) { - //if ( has(sid) ) - // moveToHead(sid); - //else + if ( has(sid) ) { + moveToHead(sid); + System.err.println("OBJECTStore: tried to add sid " + sid.toString() + + " that was already in store."); + } + else { container.addFirst(sid); + shrinkIfNecessary(); + addCount++; + } } - // add to head of linkedlist, if size is exceded throw away tail until - // size ok. } /** @@ -77,6 +89,7 @@ public class StoreContainer { if ( container.contains(sid) ) { sid.invalidate(); container.remove(sid); + removeCount++; } } } @@ -93,21 +106,27 @@ public class StoreContainer { this.maxSize=size; } - private void shrink() { - shrinkToSize(maxSize); - } + private void shrinkIfNecessary() { shrinkToSize(maxSize); } private void shrinkToSize(int size) { - if ( size0) hitRatio=(float)hitCount/(float)divisor; + hitRatio*=100; + StringBuffer sb = new StringBuffer("StoreContainer id: "); sb.append(uniqueId).append(" for "); - sb.append(stocType.toString()).append(" // Current/Max size: "); - sb.append(container.size()).append(" / "); - sb.append(maxSize).append("\n"); - /** @todo list members ? */ + sb.append(stocType.toString()).append("\n [current/maximum size: "); + sb.append(container.size()).append("/").append(maxSize); + sb.append("]\n [added/stored out/removed: ").append(addCount).append("/"); + sb.append(storeOutCount).append("/").append(removeCount).append("]\n [hit/miss/ratio: "); + sb.append(hitCount).append("/").append(missCount).append("/"); + sb.append(hitRatio).append("%]\n"); + + /** @todo list members ? */ return sb.toString(); }