001 package com.khubla.pragmatach.plugin.adminapp; 002 003 import com.khubla.pragmatach.framework.annotation.Controller; 004 import com.khubla.pragmatach.framework.annotation.Route; 005 import com.khubla.pragmatach.framework.annotation.Route.HttpMethod; 006 import com.khubla.pragmatach.framework.annotation.View; 007 import com.khubla.pragmatach.framework.api.PragmatachException; 008 import com.khubla.pragmatach.framework.api.Response; 009 import com.khubla.pragmatach.framework.router.Router; 010 011 /** 012 * @author tome 013 */ 014 @Controller(name = "pragmatachShowRouteCacheController") 015 @View(view = "pragmatach/admin/routecache.html") 016 public class ShowRouteCacheController extends SecuredAdminController { 017 private long size; 018 private long totalHits; 019 private long totalRequests; 020 private float hitRatio; 021 022 @Route(uri = "/pragmatach/admin/routecache/clear", method = HttpMethod.post) 023 public Response clearCache() throws PragmatachException { 024 Router.getRoutecache().clear(); 025 return super.render(); 026 } 027 028 public float getHitRatio() { 029 return hitRatio; 030 } 031 032 public long getSize() { 033 return size; 034 } 035 036 public long getTotalHits() { 037 return totalHits; 038 } 039 040 public long getTotalRequests() { 041 return totalRequests; 042 } 043 044 @Route(uri = "/pragmatach/admin/routecache") 045 public Response render() throws PragmatachException { 046 size = Router.getRoutecache().size(); 047 totalHits = Router.getRoutecache().getTotalHits(); 048 totalRequests = Router.getRoutecache().getTotalRequests(); 049 if (0 != totalRequests) { 050 hitRatio = 100 * ((float) totalHits / (float) totalRequests); 051 } else { 052 hitRatio = 0; 053 } 054 return super.render(); 055 } 056 057 public void setHitRatio(float hitRatio) { 058 this.hitRatio = hitRatio; 059 } 060 061 public void setSize(long size) { 062 this.size = size; 063 } 064 065 public void setTotalHits(long totalHits) { 066 this.totalHits = totalHits; 067 } 068 069 public void setTotalRequests(long totalRequests) { 070 this.totalRequests = totalRequests; 071 } 072 }