JCSCacheMXBean.java

  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.jcs3.jcache.jmx;

  20. import javax.cache.Cache;
  21. import javax.cache.configuration.CompleteConfiguration;
  22. import javax.cache.configuration.Configuration;
  23. import javax.cache.management.CacheMXBean;

  24. public class JCSCacheMXBean<K, V> implements CacheMXBean
  25. {
  26.     private final Cache<K, V> delegate;

  27.     public JCSCacheMXBean(final Cache<K, V> delegate)
  28.     {
  29.         this.delegate = delegate;
  30.     }

  31.     private Configuration<K, V> config()
  32.     {
  33.         return delegate.getConfiguration(Configuration.class);
  34.     }

  35.     private CompleteConfiguration<K, V> completeConfig()
  36.     {
  37.         return delegate.getConfiguration(CompleteConfiguration.class);
  38.     }

  39.     @Override
  40.     public String getKeyType()
  41.     {
  42.         return config().getKeyType().getName();
  43.     }

  44.     @Override
  45.     public String getValueType()
  46.     {
  47.         return config().getValueType().getName();
  48.     }

  49.     @Override
  50.     public boolean isReadThrough()
  51.     {
  52.         try
  53.         {
  54.             return completeConfig().isReadThrough();
  55.         }
  56.         catch (final Exception e)
  57.         {
  58.             return false;
  59.         }
  60.     }

  61.     @Override
  62.     public boolean isWriteThrough()
  63.     {
  64.         try
  65.         {
  66.             return completeConfig().isWriteThrough();
  67.         }
  68.         catch (final Exception e)
  69.         {
  70.             return false;
  71.         }
  72.     }

  73.     @Override
  74.     public boolean isStoreByValue()
  75.     {
  76.         return config().isStoreByValue();
  77.     }

  78.     @Override
  79.     public boolean isStatisticsEnabled()
  80.     {
  81.         try
  82.         {
  83.             return completeConfig().isStatisticsEnabled();
  84.         }
  85.         catch (final Exception e)
  86.         {
  87.             return false;
  88.         }
  89.     }

  90.     @Override
  91.     public boolean isManagementEnabled()
  92.     {
  93.         try
  94.         {
  95.             return completeConfig().isManagementEnabled();
  96.         }
  97.         catch (final Exception e)
  98.         {
  99.             return false;
  100.         }
  101.     }
  102. }