From: rk Date: Tue, 19 Feb 2002 16:44:59 +0000 (+0000) Subject: compilable snapshot of ObjectStore / day two X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=509e10a9eec1c553d212064feb5afba69472b576;p=mir.git compilable snapshot of ObjectStore / day two --- diff --git a/source/mir/storage/store/ObjectStore.java b/source/mir/storage/store/ObjectStore.java index a141e391..26f2b5cf 100755 --- a/source/mir/storage/store/ObjectStore.java +++ b/source/mir/storage/store/ObjectStore.java @@ -28,15 +28,17 @@ package mir.storage.store; */ import java.util.*; +import mir.misc.Logfile; public class ObjectStore { private static ObjectStore INSTANCE=new ObjectStore(); - private static HashMap containerMap=new HashMap(); // StoreIdentifier/StoreContainer + private static HashMap containerMap=new HashMap(); // StoreContainerType/StoreContainer + private static Logfile storeLog; + private static long storeHit=0,storeMiss=0; private ObjectStore() { } - - public ObjectStore getInstance() { return INSTANCE; } + public static ObjectStore getInstance() { return INSTANCE; } public boolean has(StoreIdentifier sid) { @@ -44,28 +46,58 @@ public class ObjectStore { 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 StorableObject use(StoreIdentifier sid) { + StorableObject storeObject=null; + StoreContainer stoc = getStoreContainerForSid( sid ); + if (stoc!=null) storeObject=stoc.use(sid); + if (storeObject==null) storeMiss++; else storeHit++; + return storeObject; } public void add(StoreIdentifier sid) { - // find right container - // if no container create container - // add there + if ( sid!=null && sid.hasReference() ) { + // find the right StoreContainer for sid + StoreContainer stoc = getStoreContainerForSid(sid); + if (stoc==null) { + // we have to make new StoreContainer + StoreContainerType stocType = sid.getStoreContainerType(); + stoc = new StoreContainer(stocType); + containerMap.put(stocType, stoc); + } + stoc.add(sid); + } } - // internal methods for StoreContainer managment + public String toString() { + StringBuffer sb = new StringBuffer("Mir-ObjectStore v_"); + sb.append(version()).append("\n"); + sb.append("\nObjectStore hits : ").append(storeHit); + sb.append("\nObjectStore misses: ").append(storeMiss); + sb.append("\nCurrently ").append(containerMap.size()); + sb.append("\nStoreContainer in use - listing information:\n"); - private StoreContainer getStoreContainerForSid(StoreIdentifier sid){ - // find apropraiate container for a specific sid - return null; + // ask container for information + StoreContainer currentStoc; + for(Iterator it=containerMap.keySet().iterator();it.hasNext();) { + currentStoc=(StoreContainer)it.next(); + sb.append(currentStoc.toString()); + } + + return sb.toString(); } + // internal methods for StoreContainer managment + private StoreContainer getStoreContainerForSid(StoreIdentifier sid){ + // find apropriate container for a specific sid + if (sid!=null) { + StoreContainerType stoc_type = sid.getStoreContainerType(); + if ( containerMap.containsKey(stoc_type) ) + return (StoreContainer)containerMap.get(stoc_type); + } + return null; + } + private String version() { return "prototype_daytwo";} } \ No newline at end of file diff --git a/source/mir/storage/store/ServletStoreInfo.java b/source/mir/storage/store/ServletStoreInfo.java index e7133f27..a74e81e6 100755 --- a/source/mir/storage/store/ServletStoreInfo.java +++ b/source/mir/storage/store/ServletStoreInfo.java @@ -10,13 +10,34 @@ package mir.storage.store; * @version 1.0 */ +import java.io.*; import javax.servlet.http.*; +import javax.servlet.*; public class ServletStoreInfo extends HttpServlet { + ObjectStore ostore = ObjectStore.getInstance(); + /** @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 */ + */ + + public void doGet(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException + { + doPost(req,res); + } + + public void doPost(HttpServletRequest req, HttpServletResponse res) + throws ServletException, UnavailableException, IOException + { + PrintWriter out = res.getWriter(); + out.println("ObjectStore>
\n");
+      out.println(ostore.toString());
+      out.println("\n
"); + out.close(); + } + + } \ No newline at end of file diff --git a/source/mir/storage/store/StorableObject.java b/source/mir/storage/store/StorableObject.java index e732a1c5..de6f4a5c 100755 --- a/source/mir/storage/store/StorableObject.java +++ b/source/mir/storage/store/StorableObject.java @@ -10,6 +10,8 @@ package mir.storage.store; * @version 1.0 */ +import java.util.*; + public interface StorableObject { /** @@ -21,6 +23,7 @@ public interface StorableObject { * @return StoreIdentifier * */ - abstract StoreIdentifier getStoreIdentifier(); + abstract StoreIdentifier getStoreIdentifier(); + abstract Set notifyOnReleaseSet(); } \ No newline at end of file diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java index 0ef70623..e863f000 100755 --- a/source/mir/storage/store/StoreContainer.java +++ b/source/mir/storage/store/StoreContainer.java @@ -21,21 +21,25 @@ public class StoreContainer { private final static int DEFAULT_SIZE=10; - private LinkedList container; - private int maxSize=DEFAULT_SIZE; + private LinkedList container; + private StoreContainerType stocType; + private int maxSize=DEFAULT_SIZE; - public StoreContainer() { - container=new LinkedList(); + private StoreContainer() {}; + + public StoreContainer(StoreContainerType stoc_type) { + this.stocType=stoc_type; + this.container=new LinkedList(); } - public StoreContainer(int maxSize) { + public StoreContainer(StoreContainerType stoc_type, int maxSize) { this(); this.maxSize=maxSize; } - /** @todo methods: release, toString() */ + /** @todo methods: release+propagation */ - public Object use(StoreIdentifier sid) { + public StorableObject use(StoreIdentifier sid) { // find sid in LinkedList or die // move sid to head of linked list // return reference on object @@ -51,4 +55,17 @@ public class StoreContainer { // size ok. } + public void setSize(int size) { + /** @todo check size, if size too big, shrink */ + this.maxSize=size; + } + + 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(); + } + } \ No newline at end of file diff --git a/source/mir/storage/store/StoreContainerType.java b/source/mir/storage/store/StoreContainerType.java new file mode 100755 index 00000000..0ddb034c --- /dev/null +++ b/source/mir/storage/store/StoreContainerType.java @@ -0,0 +1,35 @@ +package mir.storage.store; + +/** + * Title: + * Description: + * Copyright: Copyright (c) 2002 + * Company: + * @author + * @version 1.0 + */ + +import mir.misc.Logfile; + +public class StoreContainerType { + + private final static int STOC_TYPE_UNKNOWN=0; + private final static int STOC_TYPE_ENTITY=1; + private final static int STOC_TYPE_ENTITYLIST=2; + private static Logfile storeLog; + + + private StoreContainerType() { + } + + public static StoreContainerType valueOf(Class stoc_class, int stoc_type) { + /** @todo factory, only gives out types once to make them comparable via == + * check if class is StorableObject */ + return null; + } + + public String toString() { + return ""; + } + +} \ No newline at end of file diff --git a/source/mir/storage/store/StoreIdentifier.java b/source/mir/storage/store/StoreIdentifier.java index fbbf0bd2..5ecf3408 100755 --- a/source/mir/storage/store/StoreIdentifier.java +++ b/source/mir/storage/store/StoreIdentifier.java @@ -8,38 +8,38 @@ package mir.storage.store; * @author rk * @version 1.0 */ - +import java.util.*; 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; + /** @todo move main stuff to storecontainertype */ + private static Logfile storeLog; - private Object reference=null; - private int storeType=STORETYPE_UNKNOWN; + private StoreContainerType stocType=null; + private StorableObject reference=null; 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; + this.stocType = StoreContainerType.valueOf(reference.getClass(), storeType); } public void invalidate() { - this.reference=null; - this.storeType=STORETYPE_UNKNOWN; - this.uniqueIdentifier=null; - - /** @todo here we should propagate the invalidation to other + Set set = reference.notifyOnReleaseSet(); + /** @todo here we should propagate the invalidation all members of Set * @see StoreContainer */ + this.reference=null; + this.uniqueIdentifier=null; + this.stocType=null; } public Object use() { @@ -60,10 +60,11 @@ public class StoreIdentifier { return false; } - + public StoreContainerType getStoreContainerType() { return stocType; } + public boolean hasReference() { return (reference==null) ? false:true; } public String toString() { - return reference.getClass()+"@storetype"+storeType+"." + return reference.getClass()+"@storetype"+stocType.toString()+"." +uniqueIdentifier+" ("+timesUsed+") times used )"; }