*/
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) {
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
* @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("<html><head><title>ObjectStore></title></head><body><pre>\n");
+ out.println(ostore.toString());
+ out.println("\n</pre></body></html>");
+ out.close();
+ }
+
+
}
\ No newline at end of file
* @version 1.0
*/
+import java.util.*;
+
public interface StorableObject {
/**
* @return StoreIdentifier
*
*/
- abstract StoreIdentifier getStoreIdentifier();
+ abstract StoreIdentifier getStoreIdentifier();
+ abstract Set notifyOnReleaseSet();
}
\ No newline at end of file
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
// 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
--- /dev/null
+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
* @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() {
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 )";
}