View Javadoc

1   package org.apache.jcs.engine.stats;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.jcs.engine.stats.behavior.ICacheStats;
23  import org.apache.jcs.engine.stats.behavior.IStatElement;
24  import org.apache.jcs.engine.stats.behavior.IStats;
25  
26  /***
27   * This class stores cache historical and statistics data for a region.
28   *
29   * Only the composite cache knows what the hit count across all auxiliaries is.
30   *
31   * @author aaronsm
32   *
33   */
34  public class CacheStats
35      extends Stats
36      implements ICacheStats
37  {
38      private static final long serialVersionUID = 529914708798168590L;
39  
40      private String regionName = null;
41  
42      private IStats[] auxStats = null;
43  
44      private IStatElement[] stats = null;
45  
46      /*
47       * (non-Javadoc)
48       *
49       * @see org.apache.jcs.engine.stats.behavior.ICacheStats#getRegionName()
50       */
51      public String getRegionName()
52      {
53          return regionName;
54      }
55  
56      /*
57       * (non-Javadoc)
58       *
59       * @see org.apache.jcs.engine.stats.behavior.ICacheStats#setRegionName(java.lang.String)
60       */
61      public void setRegionName( String name )
62      {
63          regionName = name;
64      }
65  
66      /*
67       * (non-Javadoc)
68       *
69       * @see org.apache.jcs.engine.stats.behavior.ICacheStats#getAuxiliaryCacheStats()
70       */
71      public IStats[] getAuxiliaryCacheStats()
72      {
73          return auxStats;
74      }
75  
76      /*
77       * (non-Javadoc)
78       *
79       * @see org.apache.jcs.engine.stats.behavior.ICacheStats#setAuxiliaryCacheStats(org.apache.jcs.engine.stats.behavior.IAuxiliaryCacheStats[])
80       */
81      public void setAuxiliaryCacheStats( IStats[] stats )
82      {
83          auxStats = stats;
84      }
85  
86      /***
87       * This returns data about the auxiliaries, such as hit count. Only the
88       * composite cache knows what the hit count across all auxiliaries is.
89       * @return IStatElement[]
90       */
91      public IStatElement[] getStatElements()
92      {
93          return stats;
94      }
95  
96      /*
97       * (non-Javadoc)
98       *
99       * @see org.apache.jcs.engine.stats.behavior.IStats#setStatElements(org.apache.jcs.engine.stats.behavior.IStatElement[])
100      */
101     public void setStatElements( IStatElement[] stats )
102     {
103         this.stats = stats;
104     }
105 
106     /*
107      * (non-Javadoc)
108      *
109      * @see java.lang.Object#toString()
110      */
111     public String toString()
112     {
113         StringBuffer buf = new StringBuffer();
114 
115         buf.append( "Region Name = " + regionName );
116 
117         if ( stats != null )
118         {
119             for ( int i = 0; i < stats.length; i++ )
120             {
121                 buf.append( "\n" );
122                 buf.append( stats[i] );
123             }
124         }
125 
126         if ( auxStats != null )
127         {
128             for ( int i = 0; i < auxStats.length; i++ )
129             {
130                 buf.append( "\n" );
131                 buf.append( "---------------------------" );
132                 buf.append( auxStats[i] );
133             }
134         }
135 
136         return buf.toString();
137     }
138 }