*/
import java.util.*;
-import mir.misc.Logfile;
+import javax.servlet.http.*;
+import mir.misc.*;
public class StoreContainer {
private LinkedList container;
private StoreContainerType stocType;
- private int maxSize=DEFAULT_SIZE;
- private int uniqueId;
+ private int maxSize=DEFAULT_SIZE, uniqueId;
private int addCount=0,removeCount=0,storeOutCount;
private int hitCount=0,missCount=0;
+ private static ObjectStore o_store = ObjectStore.getInstance();
- private StoreContainer() {};
+ // avoid construction without parameters
+ private StoreContainer() {};
public StoreContainer(StoreContainerType stoc_type) {
this.uniqueId=++uniqueCounter;
this.stocType=stoc_type;
this.container=new LinkedList();
+ int defaultSize = stoc_type.getDefaultSize();
+ String confProperty = stoc_type.getConfPrefix()+".DefaultSize";
+ String confedSize = o_store.getConfProperty(confProperty);
+ if ( confedSize!=null ) {
+ this.maxSize = StringUtil.parseInt (confedSize, defaultSize);
+ }
}
public StoreContainer(StoreContainerType stoc_type, int maxSize) {
this.maxSize=maxSize;
}
+
+
public synchronized StorableObject use(StoreIdentifier sid) {
int hit = container.indexOf(sid);
- if (hit>0) {
+ if (hit>=0) {
StoreIdentifier hitSid = (StoreIdentifier)container.get(hit);
if ( hitSid!=null ) {
hitCount++;
* @return String
*/
public String toString() {
+ return toHtml(null);
+ }
+
+ public String toHtml(HttpServletRequest req) {
+ boolean showingContent=false;
float hitRatio=0;
long divisor=hitCount+missCount;
if (divisor>0) hitRatio=(float)hitCount/(float)divisor;
StringBuffer sb = new StringBuffer("StoreContainer id: ");
sb.append(uniqueId).append(" for ");
- sb.append(stocType.toString()).append("\n [current/maximum size: ");
+ sb.append(stocType.toString());
+ if ( req!=null ) {
+ String show = req.getParameter("stoc_show");
+ if ( show!=null && show.equals(""+uniqueId) ) {
+ // show all entries in container
+ sb.append(" [<b>showing</b>]");
+ showingContent=true;
+ }
+ else
+ sb.append(" [<a href=\"?stoc_show="+uniqueId+"\">show</a>]");
+ }
+ sb.append("\n [current/maximum size: ");
sb.append(container.size()).append("/").append(maxSize);
sb.append("]\n [added/stored out/removed: ").append(addCount).append("/");
sb.append(storeOutCount).append("/").append(removeCount).append("]\n [hit/miss/ratio: ");
sb.append(hitCount).append("/").append(missCount).append("/");
sb.append(hitRatio).append("%]\n");
- /** @todo list members ? */
+ if (showingContent) {
+ sb.append(" <b>Container contains following references:</b>\n ");
+ ListIterator it = container.listIterator();
+ while ( it.hasNext() ) {
+ StoreIdentifier sid = (StoreIdentifier)it.next();
+ sb.append(sid.toString()).append("\n ");
+ }
+ sb.append("<b>End of List</b>\n\n");
+
+ }
+
return sb.toString();
}