From: rk Date: Thu, 21 Feb 2002 19:23:24 +0000 (+0000) Subject: starting to test object store X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=1149ec9b078b0f9175b9c2d006313e6810e46ffb;p=mir.git starting to test object store --- diff --git a/source/mir/servlet/ServletModuleDispatch.java b/source/mir/servlet/ServletModuleDispatch.java index 76570e06..ee84259b 100755 --- a/source/mir/servlet/ServletModuleDispatch.java +++ b/source/mir/servlet/ServletModuleDispatch.java @@ -16,67 +16,68 @@ import mir.misc.*; */ public final class ServletModuleDispatch { - static Logfile theLog; + private static Logfile theLog; + private static final Class[] SIGNATURE = + { HttpServletRequest.class, HttpServletResponse.class }; - static { - theLog = Logfile.getInstance("/tmp/smod.dispatch"); - } - /** - * privater Konstruktor, um versehentliche Instantiierung zu verhindern - */ - private ServletModuleDispatch () { - } + static { + theLog = Logfile.getInstance("/tmp/smod.dispatch"); + } - /** - * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule - * mit dem per HttpServletRequest angegebenen Paramter do auf. - * Ist kein Parameter angegeben, so wird versucht, in die defaultAction - * des ServletModules zu springen. - * - * @param req Http-Request, das vom Dispatcher an die Methode des - * ServletModules durchgereicht wird - * @param res Http-Response, die vom Dispatcher an die Methode des - * ServletModules durchgereicht wird - * @param sMod ServletModule, an das dispatched wird. - * @param mod Name des Modules als String (für Logfile) - */ + /** + * privater Konstruktor, um versehentliche Instantiierung zu verhindern + */ + private ServletModuleDispatch () { + } - public static void dispatch(ServletModule sMod, HttpServletRequest req, - HttpServletResponse res) throws ServletModuleException, ServletModuleUserException - { - //sMod.predeliver(req,res); + /** + * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule + * mit dem per HttpServletRequest angegebenen Paramter do auf. + * Ist kein Parameter angegeben, so wird versucht, in die defaultAction + * des ServletModules zu springen. + * + * @param req Http-Request, das vom Dispatcher an die Methode des + * ServletModules durchgereicht wird + * @param res Http-Response, die vom Dispatcher an die Methode des + * ServletModules durchgereicht wird + * @param sMod ServletModule, an das dispatched wird. + * @param mod Name des Modules als String (für Logfile) + */ - String doParam = req.getParameter("do"); - theLog.printInfo("SerletModuleDispatch: " + sMod.toString() + " with method " + doParam); - if (doParam == null) { - if (sMod.defaultAction() != null) doParam = sMod.defaultAction(); - else throw new ServletModuleException("no parameter do supplied!"); - } + public static void dispatch(ServletModule sMod, HttpServletRequest req, + HttpServletResponse res) throws ServletModuleException, ServletModuleUserException + { + //sMod.predeliver(req,res); - Class[] params= { HttpServletRequest.class, HttpServletResponse.class}; + String doParam = req.getParameter("do"); + theLog.printInfo("SerletModuleDispatch: " + sMod.toString() + " with method " + doParam); + if (doParam == null) { + if (sMod.defaultAction() != null) doParam = sMod.defaultAction(); + else throw new ServletModuleException("no parameter do supplied!"); + } - try { - Method method = sMod.getClass().getMethod(doParam,params); - if (method != null) { - method.invoke(sMod,new Object[] {req,res} ); - return; - } - else theLog.printDebugInfo("method lookup unsuccesful"); - } - catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());} - catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());} - catch ( InvocationTargetException e) { - if (e.getTargetException().getClass().getName().equals("mir.servlet.ServletModuleUserException")) { - throw new ServletModuleUserException(((ServletModuleUserException)e.getTargetException()).getMsg()); - } else { - e.printStackTrace(); - throw new ServletModuleException(e.getTargetException().toString()); - } - } - catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());} - //catch ( ServletModuleException e ) { throw new ServletModuleException(e.toString()); } + try { + Method method = sMod.getClass().getMethod(doParam,SIGNATURE); + if (method != null) { + method.invoke(sMod,new Object[] {req,res} ); + return; + } + else theLog.printDebugInfo("method lookup unsuccesful"); + } + catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());} + catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());} + catch ( InvocationTargetException e) { + if (e.getTargetException().getClass().getName().equals("mir.servlet.ServletModuleUserException")) { + throw new ServletModuleUserException(((ServletModuleUserException)e.getTargetException()).getMsg()); + } else { + e.printStackTrace(); + throw new ServletModuleException(e.getTargetException().toString()); + } + } + catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());} - throw new ServletModuleException("delivery failed! -- "); - } + //hopefully we don't get here ... + throw new ServletModuleException("delivery failed! -- "); + } } diff --git a/source/mir/storage/store/ObjectStore.java b/source/mir/storage/store/ObjectStore.java index 86f2c4a7..844ad1a6 100755 --- a/source/mir/storage/store/ObjectStore.java +++ b/source/mir/storage/store/ObjectStore.java @@ -35,145 +35,145 @@ import mir.misc.Logfile; public class ObjectStore { - private static ObjectStore INSTANCE=new ObjectStore(); - private static HashMap containerMap=new HashMap(); // StoreContainerType/StoreContainer - private static Logfile storeLog; - private static long storeHit=0,storeMiss=0; - private static Class storableObjectInterface=StorableObject.class; - - private ObjectStore() { - } - public static ObjectStore getInstance() { return INSTANCE; } - - - /** - * Method: use - * Description: The ObjectStore tries to find the @see StoreIdentifier sid - * and returns the stored Object. - * - * @return StorableObject is null when no StorableObject for the - * StoreIdentifier sid is found. - */ - 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; - } - - /** - * Method: add - * Description: A StoreIdentifier is added to the ObjectStore, if it - * contains a reference to a @see StorableObject. - */ - public void add(StoreIdentifier sid) { - 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); - } - } - - /** - * Method: toString() - * Description: Displays statistical information about the ObjectStore. - * Further information is gathered from all @see StoreContainer - * - * @return String - */ - 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"); - - // 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(); - } - - /** - * Method: invalidate(StorableObject sto) - * Description: ObjectStore is notified of change of a @see StorableObject - * sto and invalidates all relevant cache entries. - */ - - public void invalidate(StorableObject sto) { - // propagate invalidation to StoreContainer - if (sto!=null) { - StoreIdentifier sid = sto.getStoreIdentifier(); - if (sto!=null) { - StoreContainer stoc = getStoreContainerForSid(sid); - stoc.invalidate(sto); - } - } - } - - // internal methods for StoreContainer managment - - /** - * Method: getStoreContainerForSid - * Description: private method to find the right @see StoreContainer for - * the @see StoreIdentifier sid. - * - * @return StoreContainer is null when no Container is found. - */ - 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; - } - - /** - * Method: implementsStorableObject - * Description: internall helper method to find out if a class implements - * interface StorableObject. - * - * @return true if yes, otherwise no. - */ - private final static boolean implementsStorableObject(Class aClass) { - if (aClass!=null) { - Class[] interfaces = aClass.getInterfaces(); - if (interfaces.length>0) { - for (int i=0;i0) { + for (int i=0;i container.size() ) { - // shrink - while (size > container.size() ) { - StoreIdentifier sid = (StoreIdentifier)container.getLast(); - sid.release(); - container.remove(sid); - } - } - 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 id: "); - sb.append(uniqueId).append(" for "); - sb.append(stocType.toString()).append("\nCurrent size: "); - sb.append(container.size()).append("\nMaximum size:"); - sb.append(maxSize).append("\n"); - /** @todo list members ? */ - return sb.toString(); + private void shrink() { + shrinkToSize(maxSize); + } + + private void shrinkToSize(int size) { + if ( size