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=47135308d330a83ed5fa062ba965ffbea07d3dcf;hb=1149ec9b078b0f9175b9c2d006313e6810e46ffb;hp=897cf78bea63106191f039c6eeb1d420b6371955;hpb=0a0c4d83471bdab28a17d42f9efb74c25ca84681;p=mir.git diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java index 897cf78b..47135308 100755 --- a/source/mir/storage/store/StoreContainer.java +++ b/source/mir/storage/store/StoreContainer.java @@ -20,95 +20,109 @@ import mir.misc.Logfile; public class StoreContainer { - private final static int DEFAULT_SIZE=10; - private static Logfile storeLog; - private static int uniqueCounter=10000; + private final static int DEFAULT_SIZE=10; + private static Logfile storeLog; + private static int uniqueCounter=10000; - private LinkedList container; - private StoreContainerType stocType; - private int maxSize=DEFAULT_SIZE; - private int uniqueId; + private LinkedList container; + private StoreContainerType stocType; + private int maxSize=DEFAULT_SIZE; + private int uniqueId; - private StoreContainer() {}; + private StoreContainer() {}; - public StoreContainer(StoreContainerType stoc_type) { - this.uniqueId=++uniqueCounter; - this.stocType=stoc_type; - this.container=new LinkedList(); - } + public StoreContainer(StoreContainerType stoc_type) { + this.uniqueId=++uniqueCounter; + this.stocType=stoc_type; + this.container=new LinkedList(); + } - public StoreContainer(StoreContainerType stoc_type, int maxSize) { - this(); - this.maxSize=maxSize; - } + public StoreContainer(StoreContainerType stoc_type, int maxSize) { + this(); + this.maxSize=maxSize; + } - public StorableObject use(StoreIdentifier sid) { - // find sid in LinkedList or die - // move sid to head of linked list - // return reference on object - return null; - } + public StorableObject use(StoreIdentifier sid) { + // find sid in LinkedList or die + // move sid to head of linked list + // return reference on object + return null; + } - public boolean has(StoreIdentifier sid) { - return true; // yes yes - } + public boolean has(StoreIdentifier sid) { + return true; // yes yes + } - public void add(StoreIdentifier sid) { - // add to head of linkedlist, if size is exeded throw away tail until - // size ok. - } + public void add(StoreIdentifier sid) { + if ( sid != null && sid.hasReference() ) { + //if ( has(sid) ) + // moveToHead(sid); + //else + container.addFirst(sid); + } + // add to head of linkedlist, if size is exceded throw away tail until + // size ok. + } - /** - * Method: invalidate(StorableObject sto) - * Description: finds @see StorableObject, propagates invalidation to - * @see StoreIdentifier and removes StoreIdentifier from - * list. - */ - public void invalidate(StorableObject sto) { - if (sto!=null) { - StoreIdentifier sid = sto.getStoreIdentifier(); - if (sid!=null) { - if ( container.contains(sid) ) { - sid.invalidate(); - container.remove(sid); - } - } - } - } + /** + * Method: invalidate(StorableObject sto) + * Description: finds @see StorableObject, propagates invalidation to + * @see StoreIdentifier and removes StoreIdentifier from + * list. + */ + public void invalidate(StorableObject sto) { + if (sto!=null) { + StoreIdentifier sid = sto.getStoreIdentifier(); + if (sid!=null) { + if ( container.contains(sid) ) { + sid.invalidate(); + container.remove(sid); + } + } + } + } - /** - * Method: setSize - * Description: readjusts StoreContainer size to value. - * - */ - public void setSize(int size) { - if (size <0) return; - if ( size container.size() ) { - // shrink - while (size > container.size() ) { - StoreIdentifier sid = (StoreIdentifier)container.getLast(); - sid.release(); - container.remove(sid); - } - } - this.maxSize=size; - } + /** + * Method: setSize + * Description: readjusts StoreContainer size to value. + * + */ + public void setSize(int size) { + if (size <0) return; + shrinkToSize(size); + this.maxSize=size; + } - /** - * Method: toString() - * Description: gives out statistical Information, viewable via - * @see ServletStoreInfo. - * - * @return String - */ - public String toString() { - StringBuffer sb = new StringBuffer("StoreContainer id: "); - sb.append(uniqueId).append(" for "); - sb.append(stocType.toString()).append("\nCurrent size: "); - sb.append(container.size()).append("\nMaximum size:"); - sb.append(maxSize).append("\n"); - /** @todo list members ? */ - return sb.toString(); + private void shrink() { + shrinkToSize(maxSize); + } + + private void shrinkToSize(int size) { + if ( size