From: rk Date: Mon, 18 Feb 2002 23:14:38 +0000 (+0000) Subject: object store - first draft work in progress X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=f3d8c1c0aeffa80f5eace78c5b362be5c8572671;p=mir.git object store - first draft work in progress --- diff --git a/source/mir/storage/store/ObjectStore.java b/source/mir/storage/store/ObjectStore.java new file mode 100755 index 00000000..a141e391 --- /dev/null +++ b/source/mir/storage/store/ObjectStore.java @@ -0,0 +1,71 @@ +package mir.storage.store; + +/** + * Title: ObjectStore for StorableObjects + * Description: ObjectStore holds a Map of @see StoreContainer for all possible + * @see StoreIdentifier. + * + * @see StorageIdentifier - identitfies one object in the ObjectStore + * i.e. in its apropriate bucket. It holds a unique identifier + * of an Object and a reference on the Object. + * + * @see StoreContainer - "Buckets" to store different types of Objects + * in one Container. These buckets are cofigurable via + * config.properties. + * + * @see StorableObjects - Interface Object have to implement to + * be handled by the ObjectStore + * + * @see ServletStoreInfo - Maintenance Servlet for ObjectStore. + * Displays information about current content of the + * ObjectStore. + * + * + * Copyright: Copyright (c) 2002 + * Company: indy + * @author rk + * @version 1.0 + */ + +import java.util.*; + +public class ObjectStore { + + private static ObjectStore INSTANCE=new ObjectStore(); + private static HashMap containerMap=new HashMap(); // StoreIdentifier/StoreContainer + + private ObjectStore() { } + + public ObjectStore getInstance() { return INSTANCE; } + + + public boolean has(StoreIdentifier sid) { + StoreContainer stoc = getStoreContainerForSid( sid ); + return ( stoc != null && stoc.has(sid) ) ? true:false; + } + + public Object use(StoreIdentifier sid) { + if ( has(sid) ) { + StoreContainer stoc = getStoreContainerForSid( sid ); + return stoc.use(sid); + } + return null; + } + + public void add(StoreIdentifier sid) { + // find right container + // if no container create container + // add there + } + + // internal methods for StoreContainer managment + + + private StoreContainer getStoreContainerForSid(StoreIdentifier sid){ + // find apropraiate container for a specific sid + return null; + } + + + +} \ No newline at end of file diff --git a/source/mir/storage/store/ServletStoreInfo.java b/source/mir/storage/store/ServletStoreInfo.java new file mode 100755 index 00000000..e7133f27 --- /dev/null +++ b/source/mir/storage/store/ServletStoreInfo.java @@ -0,0 +1,22 @@ +package mir.storage.store; + +/** + * Title: ServletStoreInfo + * Description: Servlet displays information about the Object store. + * + * Copyright: Copyright (c) 2002 + * Company: + * @author + * @version 1.0 + */ + +import javax.servlet.http.*; + +public class ServletStoreInfo extends HttpServlet { + + /** @todo servlet displays infos for ObjectStore + * additionally some task could be controlled: gc, and change of + * size of the @see StoreContainer in use. + * + * methods: doPost, doGet returning htmlpage */ +} \ No newline at end of file diff --git a/source/mir/storage/store/StorableObject.java b/source/mir/storage/store/StorableObject.java new file mode 100755 index 00000000..e732a1c5 --- /dev/null +++ b/source/mir/storage/store/StorableObject.java @@ -0,0 +1,26 @@ +package mir.storage.store; + +/** + * Title: Interface StorableObject + * Description: Interface all Objects need to implement to be storable in the + * ObjectStore. + * Copyright: Copyright (c) 2002 + * Company: indy + * @author rk + * @version 1.0 + */ + +public interface StorableObject { + + /** + * Method getStoreIdentifier() forces StorableObjects to return a StoreIdentifier. + * if an Object implements this, it can be stored in ObjectStore. The ObjectStore. + * @see StoreIdentifier for a description of values needed for implementing + * getStoreIdentifier() + * + * @return StoreIdentifier + * + */ + abstract StoreIdentifier getStoreIdentifier(); + +} \ No newline at end of file diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java new file mode 100755 index 00000000..0ef70623 --- /dev/null +++ b/source/mir/storage/store/StoreContainer.java @@ -0,0 +1,54 @@ +package mir.storage.store; + +/** + * Title: StoreContainer + * + * Description: This is the bucket object for one type of StorableObjects, + * mainy a linked list of StoreIdenfiers. On use or creation + * an object stored in StoreIdentifier is put to head of the + * list. if maximum size of the list is reached, the + * StoreIdentifier at the end of the list is released. + * + * Copyright: Copyright (c) 2002 + * Company: indy + * @author //rk + * @version 1.0 + */ + +import java.util.*; + +public class StoreContainer { + + private final static int DEFAULT_SIZE=10; + + private LinkedList container; + private int maxSize=DEFAULT_SIZE; + + public StoreContainer() { + container=new LinkedList(); + } + + public StoreContainer(int maxSize) { + this(); + this.maxSize=maxSize; + } + + /** @todo methods: release, toString() */ + + public Object 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 void add(StoreIdentifier sid) { + // add to head of linkedlist, if size is exeded throw away tail until + // size ok. + } + +} \ No newline at end of file diff --git a/source/mir/storage/store/StoreIdentifier.java b/source/mir/storage/store/StoreIdentifier.java new file mode 100755 index 00000000..fbbf0bd2 --- /dev/null +++ b/source/mir/storage/store/StoreIdentifier.java @@ -0,0 +1,71 @@ +package mir.storage.store; + +/** + * Title: Class StoreIdentifier + * Description: + * Copyright: Copyright (c) 2002 + * Company: indy + * @author rk + * @version 1.0 + */ + +import mir.misc.Logfile; + +public class StoreIdentifier { + + private final static int STORETYPE_UNKNOWN=0; + private final static int STORETYPE_ENTITY=1; + private final static int STORETYPE_ENTITYLIST=2; + private static Logfile storeLog; + + private Object reference=null; + private int storeType=STORETYPE_UNKNOWN; + private String uniqueIdentifier=null; // id for Entity & sql for EntityList + private long timesUsed; + + /** @todo initialize logfile */ + private StoreIdentifier() {} + + public StoreIdentifier(StorableObject reference, int storeType, String uniqueIdentifier) { + this.reference=reference; + this.storeType=storeType; + this.uniqueIdentifier=uniqueIdentifier; + } + + public void invalidate() { + this.reference=null; + this.storeType=STORETYPE_UNKNOWN; + this.uniqueIdentifier=null; + + /** @todo here we should propagate the invalidation to other + * @see StoreContainer */ + + } + + public Object use() { + timesUsed++; + return reference; + } + + /** + * Method equals for comparison between two identifier + * + * @return true if yes otherwise false + * + */ + public boolean equals(StoreIdentifier sid) { + // compare al relevant fields, most likely difference first + /** @todo doubecheck with book */ + + return false; + } + + + + public String toString() { + return reference.getClass()+"@storetype"+storeType+"." + +uniqueIdentifier+" ("+timesUsed+") times used )"; + } + + +} \ No newline at end of file