Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

CacheStatistics.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): ______________________________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.cache;
00026 
00027 import org.objectweb.cjdbc.common.util.Stats;
00028 
00029 /**
00030  * This class handles the statistics for request caches.
00031  * 
00032  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00033  * @version 1.0
00034  */
00035 public class CacheStatistics
00036 {
00037   // Cache statistics
00038   private Stats select;
00039   private Stats hits;
00040   private Stats insert;
00041   private Stats update;
00042   private Stats uncacheable;
00043   private Stats delete;
00044   private Stats unknown;
00045   private Stats remove;
00046   private Stats create;
00047   private Stats drop;
00048 
00049   /**
00050    * Creates a new CacheStatistics object.
00051    */
00052   public CacheStatistics()
00053   {
00054     select = new Stats("select");
00055     hits = new Stats("hits");
00056     insert = new Stats("insert");
00057     update = new Stats("update");
00058     uncacheable = new Stats("uncacheable");
00059     delete = new Stats("delete");
00060     unknown = new Stats("unknown");
00061     remove = new Stats("remove");
00062     create = new Stats("create");
00063     drop = new Stats("drop");
00064   }
00065 
00066   /**
00067    * Resets all stats to zero.
00068    */
00069   public void reset()
00070   {
00071     select.reset();
00072     hits.reset();
00073     insert.reset();
00074     update.reset();
00075     uncacheable.reset();
00076     delete.reset();
00077     unknown.reset();
00078     remove.reset();
00079     create.reset();
00080     drop.reset();
00081   }
00082 
00083   /**
00084    * Returns the create.
00085    * 
00086    * @return an <code>int</code> value
00087    */
00088   public int getCreate()
00089   {
00090     return create.getCount();
00091   }
00092 
00093   /**
00094    * Returns the delete.
00095    * 
00096    * @return an <code>int</code> value
00097    */
00098   public int getDelete()
00099   {
00100     return delete.getCount();
00101   }
00102 
00103   /**
00104    * Returns the drop.
00105    * 
00106    * @return an <code>int</code> value
00107    */
00108   public int getDrop()
00109   {
00110     return drop.getCount();
00111   }
00112 
00113   /**
00114    * Returns the hits.
00115    * 
00116    * @return an <code>int</code> value
00117    */
00118   public int getHits()
00119   {
00120     return hits.getCount();
00121   }
00122 
00123   /**
00124    * Returns the insert.
00125    * 
00126    * @return an <code>int</code> value
00127    */
00128   public int getInsert()
00129   {
00130     return insert.getCount();
00131   }
00132 
00133   /**
00134    * Returns the remove.
00135    * 
00136    * @return an <code>int</code> value
00137    */
00138   public int getRemove()
00139   {
00140     return remove.getCount();
00141   }
00142 
00143   /**
00144    * Returns the select.
00145    * 
00146    * @return an <code>int</code> value
00147    */
00148   public int getSelect()
00149   {
00150     return select.getCount();
00151   }
00152 
00153   /**
00154    * Returns the unknown.
00155    * 
00156    * @return an <code>int</code> value
00157    */
00158   public int getUnknown()
00159   {
00160     return unknown.getCount();
00161   }
00162 
00163   /**
00164    * Returns the update.
00165    * 
00166    * @return an <code>int</code> value
00167    */
00168   public int getUpdate()
00169   {
00170     return update.getCount();
00171   }
00172 
00173   /**
00174    * Returns the uncacheable.
00175    * 
00176    * @return an <code>int</code> value
00177    */
00178   public int getUncacheable()
00179   {
00180     return uncacheable.getCount();
00181   }
00182 
00183   /**
00184    * Increments the create count.
00185    */
00186   public void addCreate()
00187   {
00188     create.incrementCount();
00189   }
00190 
00191   /**
00192    * Increments the delete count.
00193    */
00194   public void addDelete()
00195   {
00196     delete.incrementCount();
00197   }
00198 
00199   /**
00200    * Increments the drop count.
00201    */
00202   public void addDrop()
00203   {
00204     drop.incrementCount();
00205   }
00206 
00207   /**
00208    * Increments the hits count.
00209    */
00210   public void addHits()
00211   {
00212     hits.incrementCount();
00213   }
00214 
00215   /**
00216    * Increments the insert count.
00217    */
00218   public void addInsert()
00219   {
00220     insert.incrementCount();
00221   }
00222 
00223   /**
00224    * Increments the remove count.
00225    */
00226   public void addRemove()
00227   {
00228     remove.incrementCount();
00229   }
00230 
00231   /**
00232    * Increments the select count.
00233    */
00234   public void addSelect()
00235   {
00236     select.incrementCount();
00237   }
00238 
00239   /**
00240    * Increments the unkwnown count.
00241    */
00242   public void addUnknown()
00243   {
00244     unknown.incrementCount();
00245   }
00246 
00247   /**
00248    * Increments the update count.
00249    */
00250   public void addUpdate()
00251   {
00252     update.incrementCount();
00253   }
00254 
00255   /**
00256    * Increments the uncacheable count.
00257    */
00258   public void addUncacheable()
00259   {
00260     uncacheable.incrementCount();
00261   }
00262 
00263   /**
00264    * Retrieve cache statistics as a table
00265    * 
00266    * @return an array of String containing the different cache values, like
00267    *         number of select, number of hits ...
00268    */
00269   public String[] getCacheStatsData()
00270   {
00271     String[] stats = new String[11];
00272     stats[0] = "" + getSelect();
00273     stats[1] = "" + getHits();
00274     stats[2] = "" + getInsert();
00275     stats[3] = "" + getUpdate();
00276     stats[4] = "" + getUncacheable();
00277     stats[5] = "" + getDelete();
00278     stats[6] = "" + getUnknown();
00279     stats[7] = "" + getRemove();
00280     stats[8] = "" + getCreate();
00281     stats[9] = "" + getDrop();
00282     stats[10] = "" + getCacheHitRatio();
00283     return stats;
00284   }
00285 
00286   /**
00287    * Get percentage of hits
00288    * 
00289    * @return hits / select
00290    */
00291   public long getCacheHitRatio()
00292   {
00293     if (select.getCount() == 0)
00294       return 0;
00295     else
00296       return (long) ((float) hits.getCount() / (float) select.getCount() * 100.0);
00297   }
00298 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1