View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.jcs.jcache.jmx;
20  
21  import javax.cache.Cache;
22  import javax.cache.configuration.CompleteConfiguration;
23  import javax.cache.configuration.Configuration;
24  import javax.cache.management.CacheMXBean;
25  
26  public class JCSCacheMXBean<K, V> implements CacheMXBean
27  {
28      private final Cache<K, V> delegate;
29  
30      public JCSCacheMXBean(final Cache<K, V> delegate)
31      {
32          this.delegate = delegate;
33      }
34  
35      private Configuration<K, V> config()
36      {
37          return delegate.getConfiguration(Configuration.class);
38      }
39  
40      private CompleteConfiguration<K, V> completeConfig()
41      {
42          return delegate.getConfiguration(CompleteConfiguration.class);
43      }
44  
45      @Override
46      public String getKeyType()
47      {
48          return config().getKeyType().getName();
49      }
50  
51      @Override
52      public String getValueType()
53      {
54          return config().getValueType().getName();
55      }
56  
57      @Override
58      public boolean isReadThrough()
59      {
60          try
61          {
62              return completeConfig().isReadThrough();
63          }
64          catch (final Exception e)
65          {
66              return false;
67          }
68      }
69  
70      @Override
71      public boolean isWriteThrough()
72      {
73          try
74          {
75              return completeConfig().isWriteThrough();
76          }
77          catch (final Exception e)
78          {
79              return false;
80          }
81      }
82  
83      @Override
84      public boolean isStoreByValue()
85      {
86          return config().isStoreByValue();
87      }
88  
89      @Override
90      public boolean isStatisticsEnabled()
91      {
92          try
93          {
94              return completeConfig().isStatisticsEnabled();
95          }
96          catch (final Exception e)
97          {
98              return false;
99          }
100     }
101 
102     @Override
103     public boolean isManagementEnabled()
104     {
105         try
106         {
107             return completeConfig().isManagementEnabled();
108         }
109         catch (final Exception e)
110         {
111             return false;
112         }
113     }
114 }