All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.objectify.util.MemcacheStatsServlet Maven / Gradle / Ivy

Go to download

*** THIS VERSION UPLOADED FOR USE WITH CEDAR-COMMON, TO AVOID DEPENDENCIES ON GOOGLE CODE-BASED MAVEN REPOSITORIES. *** The simplest convenient interface to the Google App Engine datastore

The newest version!
/*
 */

package com.googlecode.objectify.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.NumberFormat;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.impl.EntityMemcacheStats;
import com.googlecode.objectify.impl.EntityMemcacheStats.Stat;

/**
 * 

If you are using the ObjectifyService static factory, you can mount this servlet to see the * memcache stats for an instance. This is nothing fancy, but it should give you an idea of what's * going on.

* * @author Jeff Schnitzer */ public class MemcacheStatsServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * If you aren't using ObjectifyService, you can extend the servlet and override this method. */ protected EntityMemcacheStats getMemcacheStats() { return ObjectifyService.factory().getMemcacheStats(); } /** */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Map stats = getMemcacheStats().getStats(); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println(""); out.println(" "); out.println(" "); // css? we don't need no stinkin' css out.println(" "); out.println(" "); out.println(" "); NumberFormat percentFmt = NumberFormat.getPercentInstance(); percentFmt.setMaximumFractionDigits(2); for (Map.Entry entry: stats.entrySet()) { out.println(""); out.println(" "); out.println(" "); out.println(" "); out.println(" "); out.println(""); } out.println("
HitsMissesPercentKind
" + entry.getValue().getHits() + "" + entry.getValue().getMisses() + "" + percentFmt.format(entry.getValue().getPercent()) + "" + entry.getKey() + "
"); out.println(" "); out.println(""); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy