1 package mir.storage.store;
4 * Title: StoreContainer
6 * Description: This is the bucket object for one type of StorableObjects,
7 * mainy a linked list of StoreIdenfiers. On use or creation
8 * an object stored in StoreIdentifier is put to head of the
9 * list. if maximum size of the list is reached, the
10 * StoreIdentifier at the end of the list is released.
12 * Copyright: Copyright (c) 2002
19 import mir.misc.Logfile;
21 public class StoreContainer {
23 private final static int DEFAULT_SIZE=10;
24 private static Logfile storeLog;
25 private static int uniqueCounter=10000;
27 private LinkedList container;
28 private StoreContainerType stocType;
29 private int maxSize=DEFAULT_SIZE;
32 private StoreContainer() {};
34 public StoreContainer(StoreContainerType stoc_type) {
35 this.uniqueId=++uniqueCounter;
36 this.stocType=stoc_type;
37 this.container=new LinkedList();
40 public StoreContainer(StoreContainerType stoc_type, int maxSize) {
45 public StorableObject use(StoreIdentifier sid) {
46 // find sid in LinkedList or die
47 // move sid to head of linked list
48 // return reference on object
52 public boolean has(StoreIdentifier sid) {
53 return true; // yes yes
56 public void add(StoreIdentifier sid) {
57 // add to head of linkedlist, if size is exeded throw away tail until
62 * Method: invalidate(StorableObject sto)
63 * Description: finds @see StorableObject, propagates invalidation to
64 * @see StoreIdentifier and removes StoreIdentifier from
67 public void invalidate(StorableObject sto) {
69 StoreIdentifier sid = sto.getStoreIdentifier();
71 if ( container.contains(sid) ) {
73 container.remove(sid);
81 * Description: readjusts StoreContainer size to value.
84 public void setSize(int size) {
86 if ( size<maxSize && size > container.size() ) {
88 while (size > container.size() ) {
89 StoreIdentifier sid = (StoreIdentifier)container.getLast();
91 container.remove(sid);
99 * Description: gives out statistical Information, viewable via
100 * @see ServletStoreInfo.
104 public String toString() {
105 StringBuffer sb = new StringBuffer("StoreContainer id: ");
106 sb.append(uniqueId).append(" for ");
107 sb.append(stocType.toString()).append("\nCurrent size: ");
108 sb.append(container.size()).append("\nMaximum size:");
109 sb.append(maxSize).append("\n");
110 /** @todo list members ? */
111 return sb.toString();