/core/src/main/java/org/infinispan/cache/impl/AbstractDelegatingCache.java

https://github.com/wburns/infinispan · Java · 641 lines · 505 code · 112 blank · 24 comment · 3 complexity · ff14d7e85dfd236a52e924b1d26ba43e MD5 · raw file

  1. package org.infinispan.cache.impl;
  2. import java.lang.annotation.Annotation;
  3. import java.util.Map;
  4. import java.util.Properties;
  5. import java.util.Set;
  6. import java.util.concurrent.CompletableFuture;
  7. import java.util.concurrent.CompletionStage;
  8. import java.util.concurrent.TimeUnit;
  9. import java.util.function.BiConsumer;
  10. import java.util.function.BiFunction;
  11. import java.util.function.Function;
  12. import org.infinispan.AdvancedCache;
  13. import org.infinispan.Cache;
  14. import org.infinispan.CacheCollection;
  15. import org.infinispan.CacheSet;
  16. import org.infinispan.configuration.format.PropertyFormatter;
  17. import org.infinispan.filter.KeyFilter;
  18. import org.infinispan.jmx.annotations.DataType;
  19. import org.infinispan.jmx.annotations.DisplayType;
  20. import org.infinispan.jmx.annotations.MBean;
  21. import org.infinispan.jmx.annotations.ManagedAttribute;
  22. import org.infinispan.jmx.annotations.ManagedOperation;
  23. import org.infinispan.lifecycle.ComponentStatus;
  24. import org.infinispan.manager.EmbeddedCacheManager;
  25. import org.infinispan.notifications.cachelistener.filter.CacheEventConverter;
  26. import org.infinispan.notifications.cachelistener.filter.CacheEventFilter;
  27. /**
  28. * This is a convenient base class for implementing a cache delegate. The only constructor takes a {@link Cache}
  29. * argument, to which each method call is delegated. One can extend this class and override the method sub-set it is
  30. * interested in. There is also an similar implementation for {@link org.infinispan.AdvancedCache}: {@link
  31. * org.infinispan.cache.impl.AbstractDelegatingAdvancedCache}.
  32. *
  33. * @author Mircea.Markus@jboss.com
  34. * @see org.infinispan.cache.impl.AbstractDelegatingAdvancedCache
  35. */
  36. @MBean(objectName = CacheImpl.OBJECT_NAME, description = "Component that represents an individual cache instance.")
  37. public abstract class AbstractDelegatingCache<K, V> implements Cache<K, V> {
  38. private final Cache<K, V> cache;
  39. public AbstractDelegatingCache(Cache<K, V> cache) {
  40. this.cache = cache;
  41. if (cache == null) throw new IllegalArgumentException("Delegate cache cannot be null!");
  42. }
  43. @Override
  44. public void putForExternalRead(K key, V value) {
  45. cache.putForExternalRead(key, value);
  46. }
  47. @Override
  48. public void putForExternalRead(K key, V value, long lifespan, TimeUnit unit) {
  49. cache.putForExternalRead(key, value, lifespan, unit);
  50. }
  51. @Override
  52. public void putForExternalRead(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  53. cache.putForExternalRead(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  54. }
  55. @Override
  56. public void evict(K key) {
  57. cache.evict(key);
  58. }
  59. @Override
  60. public org.infinispan.configuration.cache.Configuration getCacheConfiguration() {
  61. return cache.getCacheConfiguration();
  62. }
  63. @Override
  64. public boolean startBatch() {
  65. return cache.startBatch();
  66. }
  67. @Override
  68. public void endBatch(boolean successful) {
  69. cache.endBatch(successful);
  70. }
  71. @Override
  72. public String getName() {
  73. return cache.getName();
  74. }
  75. @ManagedAttribute(
  76. description = "Returns the cache name",
  77. displayName = "Cache name",
  78. dataType = DataType.TRAIT,
  79. displayType = DisplayType.SUMMARY
  80. )
  81. public String getCacheName() {
  82. return getName() + "(" + getCacheConfiguration().clustering().cacheMode().toString().toLowerCase() + ")";
  83. }
  84. @Override
  85. @ManagedAttribute(
  86. description = "Returns the version of Infinispan",
  87. displayName = "Infinispan version",
  88. dataType = DataType.TRAIT,
  89. displayType = DisplayType.SUMMARY
  90. )
  91. public String getVersion() {
  92. return cache.getVersion();
  93. }
  94. @Override
  95. public EmbeddedCacheManager getCacheManager() {
  96. return cache.getCacheManager();
  97. }
  98. @Override
  99. public V put(K key, V value, long lifespan, TimeUnit unit) {
  100. return cache.put(key, value, lifespan, unit);
  101. }
  102. /**
  103. * Don't remove.
  104. * @see {@link org.infinispan.cache.impl.CacheSupport#set(Object, Object)}
  105. */
  106. protected void set(K key, V value) {
  107. cache.put(key, value);
  108. }
  109. @Override
  110. public V putIfAbsent(K key, V value, long lifespan, TimeUnit unit) {
  111. return cache.putIfAbsent(key, value, lifespan, unit);
  112. }
  113. @Override
  114. public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit unit) {
  115. cache.putAll(map, lifespan, unit);
  116. }
  117. @Override
  118. public V replace(K key, V value, long lifespan, TimeUnit unit) {
  119. return cache.replace(key, value, lifespan, unit);
  120. }
  121. @Override
  122. public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit) {
  123. return cache.replace(key, oldValue, value, lifespan, unit);
  124. }
  125. @Override
  126. public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  127. return cache.put(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  128. }
  129. @Override
  130. public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  131. return cache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  132. }
  133. @Override
  134. public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  135. cache.putAll(map, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  136. }
  137. @Override
  138. public V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  139. return cache.replace(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  140. }
  141. @Override
  142. public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  143. return cache.replace(key, oldValue, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  144. }
  145. @Override
  146. public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
  147. cache.replaceAll(function);
  148. }
  149. @Override
  150. public CompletableFuture<V> putAsync(K key, V value) {
  151. return cache.putAsync(key, value);
  152. }
  153. @Override
  154. public CompletableFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit) {
  155. return cache.putAsync(key, value, lifespan, unit);
  156. }
  157. @Override
  158. public CompletableFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  159. return cache.putAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  160. }
  161. @Override
  162. public CompletableFuture<Void> putAllAsync(Map<? extends K, ? extends V> data) {
  163. return cache.putAllAsync(data);
  164. }
  165. @Override
  166. public CompletableFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit unit) {
  167. return cache.putAllAsync(data, lifespan, unit);
  168. }
  169. @Override
  170. public CompletableFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  171. return cache.putAllAsync(data, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  172. }
  173. @Override
  174. public CompletableFuture<Void> clearAsync() {
  175. return cache.clearAsync();
  176. }
  177. @Override
  178. public CompletableFuture<V> putIfAbsentAsync(K key, V value) {
  179. return cache.putIfAbsentAsync(key, value);
  180. }
  181. @Override
  182. public CompletableFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit) {
  183. return cache.putIfAbsentAsync(key, value, lifespan, unit);
  184. }
  185. @Override
  186. public CompletableFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  187. return cache.putIfAbsentAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  188. }
  189. @Override
  190. public CompletableFuture<V> removeAsync(Object key) {
  191. return cache.removeAsync(key);
  192. }
  193. @Override
  194. public CompletableFuture<Boolean> removeAsync(Object key, Object value) {
  195. return cache.removeAsync(key, value);
  196. }
  197. @Override
  198. public CompletableFuture<V> replaceAsync(K key, V value) {
  199. return cache.replaceAsync(key, value);
  200. }
  201. @Override
  202. public CompletableFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit) {
  203. return cache.replaceAsync(key, value, lifespan, unit);
  204. }
  205. @Override
  206. public CompletableFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  207. return cache.replaceAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  208. }
  209. @Override
  210. public CompletableFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
  211. return cache.replaceAsync(key, oldValue, newValue);
  212. }
  213. @Override
  214. public CompletableFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit) {
  215. return cache.replaceAsync(key, oldValue, newValue, lifespan, unit);
  216. }
  217. @Override
  218. public CompletableFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  219. return cache.replaceAsync(key, oldValue, newValue, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  220. }
  221. @Override
  222. public CompletableFuture<V> computeAsync(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
  223. return cache.computeAsync(key, remappingFunction);
  224. }
  225. @Override
  226. public CompletableFuture<V> computeAsync(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit) {
  227. return cache.computeAsync(key, remappingFunction, lifespan, lifespanUnit);
  228. }
  229. @Override
  230. public CompletableFuture<V> computeAsync(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  231. return cache.computeAsync(key, remappingFunction, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  232. }
  233. @Override
  234. public CompletableFuture<V> computeIfAbsentAsync(K key, Function<? super K, ? extends V> mappingFunction) {
  235. return cache.computeIfAbsentAsync(key, mappingFunction);
  236. }
  237. @Override
  238. public CompletableFuture<V> computeIfAbsentAsync(K key, Function<? super K, ? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit) {
  239. return cache.computeIfAbsentAsync(key, mappingFunction, lifespan, lifespanUnit);
  240. }
  241. @Override
  242. public CompletableFuture<V> computeIfAbsentAsync(K key, Function<? super K, ? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  243. return cache.computeIfAbsentAsync(key, mappingFunction, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  244. }
  245. @Override
  246. public CompletableFuture<V> computeIfPresentAsync(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
  247. return cache.computeIfPresentAsync(key, remappingFunction);
  248. }
  249. @Override
  250. public CompletableFuture<V> computeIfPresentAsync(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit) {
  251. return cache.computeIfPresentAsync(key, remappingFunction, lifespan, lifespanUnit);
  252. }
  253. @Override
  254. public CompletableFuture<V> computeIfPresentAsync(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  255. return cache.computeIfPresentAsync(key, remappingFunction, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  256. }
  257. @Override
  258. public CompletableFuture<V> mergeAsync(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
  259. return cache.mergeAsync(key, value, remappingFunction);
  260. }
  261. @Override
  262. public CompletableFuture<V> mergeAsync(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit) {
  263. return cache.mergeAsync(key, value, remappingFunction, lifespan, lifespanUnit);
  264. }
  265. @Override
  266. public CompletableFuture<V> mergeAsync(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  267. return cache.mergeAsync(key, value, remappingFunction, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  268. }
  269. @Override
  270. public AdvancedCache<K, V> getAdvancedCache() {
  271. return cache.getAdvancedCache();
  272. }
  273. @Override
  274. public ComponentStatus getStatus() {
  275. return cache.getStatus();
  276. }
  277. /**
  278. * Returns String representation of ComponentStatus enumeration in order to avoid class not found exceptions in JMX
  279. * tools that don't have access to infinispan classes.
  280. */
  281. @ManagedAttribute(
  282. description = "Returns the cache status",
  283. displayName = "Cache status",
  284. dataType = DataType.TRAIT,
  285. displayType = DisplayType.SUMMARY
  286. )
  287. public String getCacheStatus() {
  288. return getStatus().toString();
  289. }
  290. @Override
  291. public V putIfAbsent(K key, V value) {
  292. return cache.putIfAbsent(key, value);
  293. }
  294. @Override
  295. public boolean remove(Object key, Object value) {
  296. return cache.remove(key, value);
  297. }
  298. @Override
  299. public boolean replace(K key, V oldValue, V newValue) {
  300. return cache.replace(key, oldValue, newValue);
  301. }
  302. @Override
  303. public V replace(K key, V value) {
  304. return cache.replace(key, value);
  305. }
  306. @Override
  307. public int size() {
  308. return cache.size();
  309. }
  310. @Override
  311. public boolean isEmpty() {
  312. return cache.isEmpty();
  313. }
  314. @Override
  315. public boolean containsKey(Object key) {
  316. return cache.containsKey(key);
  317. }
  318. @Override
  319. public boolean containsValue(Object value) {
  320. return cache.containsValue(value);
  321. }
  322. @Override
  323. public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
  324. return cache.compute(key, remappingFunction);
  325. }
  326. @Override
  327. public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit) {
  328. return cache.compute(key, remappingFunction, lifespan, lifespanUnit);
  329. }
  330. @Override
  331. public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  332. return cache.compute(key, remappingFunction, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  333. }
  334. @Override
  335. public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
  336. return cache.computeIfPresent(key, remappingFunction);
  337. }
  338. @Override
  339. public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit) {
  340. return cache.computeIfPresent(key, remappingFunction, lifespan, lifespanUnit);
  341. }
  342. @Override
  343. public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  344. return cache.computeIfPresent(key, remappingFunction, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  345. }
  346. @Override
  347. public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
  348. return cache.computeIfAbsent(key, mappingFunction);
  349. }
  350. @Override
  351. public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit) {
  352. return cache.computeIfAbsent(key, mappingFunction, lifespan, lifespanUnit);
  353. }
  354. @Override
  355. public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  356. return cache.computeIfAbsent(key, mappingFunction, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  357. }
  358. @Override
  359. public V get(Object key) {
  360. return cache.get(key);
  361. }
  362. @Override
  363. public V getOrDefault(Object key, V defaultValue) {
  364. return cache.getOrDefault(key, defaultValue);
  365. }
  366. @Override
  367. public V put(K key, V value) {
  368. return cache.put(key, value);
  369. }
  370. @Override
  371. public V remove(Object key) {
  372. return cache.remove(key);
  373. }
  374. @Override
  375. public void putAll(Map<? extends K, ? extends V> t) {
  376. cache.putAll(t);
  377. }
  378. @Override
  379. public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
  380. return cache.merge(key, value, remappingFunction);
  381. }
  382. @Override
  383. public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit) {
  384. return cache.merge(key, value, remappingFunction, lifespan, lifespanUnit);
  385. }
  386. @Override
  387. public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  388. return cache.merge(key, value, remappingFunction, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  389. }
  390. @Override
  391. public void forEach(BiConsumer<? super K, ? super V> action) {
  392. cache.forEach(action);
  393. }
  394. @Override
  395. @ManagedOperation(
  396. description = "Clears the cache",
  397. displayName = "Clears the cache", name = "clear"
  398. )
  399. public void clear() {
  400. cache.clear();
  401. }
  402. @Override
  403. public CacheSet<K> keySet() {
  404. return cache.keySet();
  405. }
  406. @Override
  407. public CacheSet<Entry<K, V>> entrySet() {
  408. return cache.entrySet();
  409. }
  410. @Override
  411. public CacheCollection<V> values() {
  412. return cache.values();
  413. }
  414. @Override
  415. @ManagedOperation(
  416. description = "Starts the cache.",
  417. displayName = "Starts cache."
  418. )
  419. public void start() {
  420. cache.start();
  421. }
  422. @Override
  423. @ManagedOperation(
  424. description = "Stops the cache.",
  425. displayName = "Stops cache."
  426. )
  427. public void stop() {
  428. cache.stop();
  429. }
  430. @Override
  431. @ManagedOperation(
  432. description = "Shuts down the cache across the cluster",
  433. displayName = "Clustered cache shutdown"
  434. )
  435. public void shutdown() {
  436. cache.shutdown();
  437. }
  438. @Override
  439. public void addListener(Object listener) {
  440. cache.addListener(listener);
  441. }
  442. @Override
  443. public CompletionStage<Void> addListenerAsync(Object listener) {
  444. return cache.addListenerAsync(listener);
  445. }
  446. @Override
  447. public void addListener(Object listener, KeyFilter<? super K> filter) {
  448. cache.addListener(listener, filter);
  449. }
  450. @Override
  451. public <C> void addListener(Object listener, CacheEventFilter<? super K, ? super V> filter,
  452. CacheEventConverter<? super K, ? super V, C> converter) {
  453. cache.addListener(listener, filter, converter);
  454. }
  455. @Override
  456. public <C> CompletionStage<Void> addListenerAsync(Object listener, CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter) {
  457. return cache.addListenerAsync(listener, filter, converter);
  458. }
  459. @Override
  460. public void removeListener(Object listener) {
  461. cache.removeListener(listener);
  462. }
  463. @Override
  464. public CompletionStage<Void> removeListenerAsync(Object listener) {
  465. return cache.removeListenerAsync(listener);
  466. }
  467. @Deprecated
  468. @Override
  469. public Set<Object> getListeners() {
  470. return cache.getListeners();
  471. }
  472. @Override
  473. public <C> void addFilteredListener(Object listener,
  474. CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter,
  475. Set<Class<? extends Annotation>> filterAnnotations) {
  476. cache.addFilteredListener(listener, filter, converter, filterAnnotations);
  477. }
  478. @Override
  479. public <C> CompletionStage<Void> addFilteredListenerAsync(Object listener,
  480. CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter,
  481. Set<Class<? extends Annotation>> filterAnnotations) {
  482. return cache.addFilteredListenerAsync(listener, filter, converter, filterAnnotations);
  483. }
  484. @Override
  485. public <C> void addStorageFormatFilteredListener(Object listener, CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter, Set<Class<? extends Annotation>> filterAnnotations) {
  486. cache.addStorageFormatFilteredListener(listener, filter, converter, filterAnnotations);
  487. }
  488. @Override
  489. public <C> CompletionStage<Void> addStorageFormatFilteredListenerAsync(Object listener, CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter, Set<Class<? extends Annotation>> filterAnnotations) {
  490. return cache.addStorageFormatFilteredListenerAsync(listener, filter, converter, filterAnnotations);
  491. }
  492. @Override
  493. public CompletableFuture<V> getAsync(K key) {
  494. return cache.getAsync(key);
  495. }
  496. @Override
  497. public CompletableFuture<Map<K, V>> getAllAsync(Set<?> keys) {
  498. return cache.getAllAsync(keys);
  499. }
  500. @ManagedAttribute(
  501. description = "Returns the cache configuration in form of properties",
  502. displayName = "Cache configuration properties",
  503. dataType = DataType.TRAIT,
  504. displayType = DisplayType.SUMMARY
  505. )
  506. public Properties getConfigurationAsProperties() {
  507. return new PropertyFormatter().format(getCacheConfiguration());
  508. }
  509. @Override
  510. public String toString() {
  511. return cache.toString();
  512. }
  513. public Cache<K, V> getDelegate() {
  514. return cache;
  515. }
  516. /**
  517. * Fully unwraps a given cache returning the base cache. Will unwrap all <b>AbstractDelegatingCache</b> wrappers.
  518. * @param cache
  519. * @param <K>
  520. * @param <V>
  521. * @return
  522. */
  523. public static <K, V> Cache<K, V> unwrapCache(Cache<K, V> cache) {
  524. if (cache instanceof AbstractDelegatingCache) {
  525. return unwrapCache(((AbstractDelegatingCache<K, V>) cache).getDelegate());
  526. }
  527. return cache;
  528. }
  529. }