View Javadoc

1   package org.apache.jcs.admin;
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.CacheConstants;
23  import org.apache.jcs.engine.control.CompositeCache;
24  
25  /***
26   * Stores info on a cache region for the template
27   */
28  public class CacheRegionInfo
29  {
30      /*** The cache region we are getting info on. */
31      CompositeCache cache = null;
32  
33      /*** number of bytes counted so far, will be a total of all items. */
34      long byteCount = 0;
35  
36      /***
37       * @return the underlying region
38       */
39      public CompositeCache getCache()
40      {
41          return this.cache;
42      }
43  
44      /***
45       * @return total byte count
46       */
47      public long getByteCount()
48      {
49          return this.byteCount;
50      }
51  
52      /***
53       * @return a status string
54       */
55      public String getStatus()
56      {
57          int status = this.cache.getStatus();
58  
59          return ( status == CacheConstants.STATUS_ALIVE
60                                                        ? "ALIVE"
61                                                        : status == CacheConstants.STATUS_DISPOSED
62                                                                                                  ? "DISPOSED"
63                                                                                                  : status == CacheConstants.STATUS_ERROR
64                                                                                                                                         ? "ERROR"
65                                                                                                                                         : "UNKNOWN" );
66      }
67  
68      /***
69       * Return the stats for the region.
70       * <p>
71       * @return String
72       */
73      public String getStats()
74      {
75          return this.cache.getStats();
76      }
77  
78      /***
79       * @return string info on the region
80       */
81      public String toString()
82      {
83          StringBuffer buf = new StringBuffer();
84          buf.append( "\nCacheRegionInfo " );
85          if ( getCache() != null )
86          {
87              buf.append( "\n CacheName [" + getCache().getCacheName() + "]" );
88              buf.append( "\n Status [" + getStatus() + "]" );
89          }
90          buf.append( "\n ByteCount [" + getByteCount() + "]" );
91  
92          return buf.toString();
93      }
94  }