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   * <p>
29   * Only the composite cache knows what the hit count across all auxiliaries is.
30   */
31  public class CacheStats
32      extends Stats
33      implements ICacheStats
34  {
35      /** Don't change. */
36      private static final long serialVersionUID = 529914708798168590L;
37  
38      /** The region */
39      private String regionName = null;
40  
41      /** What that auxiliaries are reporting. */
42      private IStats[] auxStats = null;
43  
44      /** stats */
45      private IStatElement[] stats = null;
46  
47      /**
48       * Stats are for a region, though auxiliary data may be for more.
49       * <p>
50       * @return The region name
51       */
52      public String getRegionName()
53      {
54          return regionName;
55      }
56  
57      /**
58       * Stats are for a region, though auxiliary data may be for more.
59       * <p>
60       * @param name - The region name
61       */
62      public void setRegionName( String name )
63      {
64          regionName = name;
65      }
66  
67      /**
68       * @return IStats[]
69       */
70      public IStats[] getAuxiliaryCacheStats()
71      {
72          return auxStats;
73      }
74  
75      /**
76       * @param stats
77       */
78      public void setAuxiliaryCacheStats( IStats[] stats )
79      {
80          auxStats = stats;
81      }
82  
83      /**
84       * This returns data about the auxiliaries, such as hit count. Only the composite cache knows
85       * what the hit count across all auxiliaries is.
86       * <p>
87       * @return IStatElement[]
88       */
89      @Override
90      public IStatElement[] getStatElements()
91      {
92          return stats;
93      }
94  
95      /**
96       * @param stats
97       */
98      @Override
99      public void setStatElements( IStatElement[] stats )
100     {
101         this.stats = stats;
102     }
103 
104     /**
105      * @return readable string that can be logged.
106      */
107     @Override
108     public String toString()
109     {
110         StringBuffer buf = new StringBuffer();
111 
112         buf.append( "Region Name = " + regionName );
113 
114         if ( stats != null )
115         {
116             for ( int i = 0; i < stats.length; i++ )
117             {
118                 buf.append( "\n" );
119                 buf.append( stats[i] );
120             }
121         }
122 
123         if ( auxStats != null )
124         {
125             for ( int i = 0; i < auxStats.length; i++ )
126             {
127                 buf.append( "\n" );
128                 buf.append( "---------------------------" );
129                 buf.append( auxStats[i] );
130             }
131         }
132 
133         return buf.toString();
134     }
135 }