001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.jcs.jcache.jmx; 020 021import javax.cache.Cache; 022import javax.cache.configuration.CompleteConfiguration; 023import javax.cache.configuration.Configuration; 024import javax.cache.management.CacheMXBean; 025 026public class JCSCacheMXBean<K, V> implements CacheMXBean 027{ 028 private final Cache<K, V> delegate; 029 030 public JCSCacheMXBean(final Cache<K, V> delegate) 031 { 032 this.delegate = delegate; 033 } 034 035 private Configuration<K, V> config() 036 { 037 return delegate.getConfiguration(Configuration.class); 038 } 039 040 private CompleteConfiguration<K, V> completeConfig() 041 { 042 return delegate.getConfiguration(CompleteConfiguration.class); 043 } 044 045 @Override 046 public String getKeyType() 047 { 048 return config().getKeyType().getName(); 049 } 050 051 @Override 052 public String getValueType() 053 { 054 return config().getValueType().getName(); 055 } 056 057 @Override 058 public boolean isReadThrough() 059 { 060 try 061 { 062 return completeConfig().isReadThrough(); 063 } 064 catch (final Exception e) 065 { 066 return false; 067 } 068 } 069 070 @Override 071 public boolean isWriteThrough() 072 { 073 try 074 { 075 return completeConfig().isWriteThrough(); 076 } 077 catch (final Exception e) 078 { 079 return false; 080 } 081 } 082 083 @Override 084 public boolean isStoreByValue() 085 { 086 return config().isStoreByValue(); 087 } 088 089 @Override 090 public boolean isStatisticsEnabled() 091 { 092 try 093 { 094 return completeConfig().isStatisticsEnabled(); 095 } 096 catch (final Exception e) 097 { 098 return false; 099 } 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}