public class StoreContainer {
- private final static int DEFAULT_SIZE=10;
+ 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 static Logfile storeLog;
+ private LinkedList container;
+ private StoreContainerType stocType;
+ private int maxSize=DEFAULT_SIZE;
+ private int uniqueId;
- private StoreContainer() {};
+ private StoreContainer() {};
- public StoreContainer(StoreContainerType stoc_type) {
- 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;
+ }
- /** @todo methods: release+propagation */
+ 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) {
+ 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.
+ }
- public void add(StoreIdentifier sid) {
- // add to head of linkedlist, if size is exeded 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: setSize
- * Description: readjusts StoreContainer size to value.
- *
- */
- public void setSize(int size) {
- /** @todo check size, if size too big, shrink */
- 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 for ");
- sb.append(stocType.toString()).append("\nCurrent size: ");
- sb.append(container.size()).append("\nMaximum size:");
- sb.append(maxSize).append("\n");
- return sb.toString();
+ private void shrink() {
+ shrinkToSize(maxSize);
+ }
+
+ private void shrinkToSize(int size) {
+ if ( size<maxSize && size < container.size() ) {
+ // shrink
+ while (size < container.size() ) {
+ StoreIdentifier sid = (StoreIdentifier)container.getLast();
+ sid.release();
+ container.remove(sid);
+ }
+ }
}
+ /**
+ * 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(" // Current/Max size: ");
+ sb.append(container.size()).append(" / ");
+ sb.append(maxSize).append("\n");
+ /** @todo list members ? */
+ return sb.toString();
+ }
+
}
\ No newline at end of file