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

https://github.com/vblagoje/infinispan · Java · 376 lines · 291 code · 72 blank · 13 comment · 2 complexity · af44f43637919bead52fc1fbf48511de MD5 · raw file

  1. package org.infinispan.cache.impl;
  2. import org.infinispan.AdvancedCache;
  3. import org.infinispan.Cache;
  4. import org.infinispan.commons.util.CloseableIteratorCollection;
  5. import org.infinispan.commons.util.CloseableIteratorSet;
  6. import org.infinispan.lifecycle.ComponentStatus;
  7. import org.infinispan.manager.EmbeddedCacheManager;
  8. import org.infinispan.filter.Converter;
  9. import org.infinispan.filter.KeyFilter;
  10. import org.infinispan.filter.KeyValueFilter;
  11. import org.infinispan.commons.util.concurrent.NotifyingFuture;
  12. import org.infinispan.notifications.cachelistener.filter.CacheEventConverter;
  13. import org.infinispan.notifications.cachelistener.filter.CacheEventFilter;
  14. import java.util.Collection;
  15. import java.util.Map;
  16. import java.util.Set;
  17. import java.util.concurrent.TimeUnit;
  18. /**
  19. * This is a convenient base class for implementing a cache delegate. The only constructor takes a {@link Cache}
  20. * argument, to which each method call is delegated. One can extend this class and override the method sub-set it is
  21. * interested in. There is also an similar implementation for {@link org.infinispan.AdvancedCache}: {@link
  22. * org.infinispan.cache.impl.AbstractDelegatingAdvancedCache}.
  23. *
  24. * @author Mircea.Markus@jboss.com
  25. * @see org.infinispan.cache.impl.AbstractDelegatingAdvancedCache
  26. */
  27. public abstract class AbstractDelegatingCache<K, V> implements Cache<K, V> {
  28. private final Cache<K, V> cache;
  29. public AbstractDelegatingCache(Cache<K, V> cache) {
  30. this.cache = cache;
  31. if (cache == null) throw new IllegalArgumentException("Delegate cache cannot be null!");
  32. }
  33. @Override
  34. public void putForExternalRead(K key, V value) {
  35. cache.putForExternalRead(key, value);
  36. }
  37. @Override
  38. public void putForExternalRead(K key, V value, long lifespan, TimeUnit unit) {
  39. cache.putForExternalRead(key, value, lifespan, unit);
  40. }
  41. @Override
  42. public void putForExternalRead(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  43. cache.putForExternalRead(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  44. }
  45. @Override
  46. public void evict(K key) {
  47. cache.evict(key);
  48. }
  49. @Override
  50. public org.infinispan.configuration.cache.Configuration getCacheConfiguration() {
  51. return cache.getCacheConfiguration();
  52. }
  53. @Override
  54. public boolean startBatch() {
  55. return cache.startBatch();
  56. }
  57. @Override
  58. public void endBatch(boolean successful) {
  59. cache.endBatch(successful);
  60. }
  61. @Override
  62. public String getName() {
  63. return cache.getName();
  64. }
  65. @Override
  66. public String getVersion() {
  67. return cache.getVersion();
  68. }
  69. @Override
  70. public EmbeddedCacheManager getCacheManager() {
  71. return cache.getCacheManager();
  72. }
  73. @Override
  74. public V put(K key, V value, long lifespan, TimeUnit unit) {
  75. return cache.put(key, value, lifespan, unit);
  76. }
  77. /**
  78. * Don't remove.
  79. * @see {@link org.infinispan.cache.impl.CacheSupport#set(Object, Object)}
  80. */
  81. protected void set(K key, V value) {
  82. cache.put(key, value);
  83. }
  84. @Override
  85. public V putIfAbsent(K key, V value, long lifespan, TimeUnit unit) {
  86. return cache.putIfAbsent(key, value, lifespan, unit);
  87. }
  88. @Override
  89. public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit unit) {
  90. cache.putAll(map, lifespan, unit);
  91. }
  92. @Override
  93. public V replace(K key, V value, long lifespan, TimeUnit unit) {
  94. return cache.replace(key, value, lifespan, unit);
  95. }
  96. @Override
  97. public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit) {
  98. return cache.replace(key, oldValue, value, lifespan, unit);
  99. }
  100. @Override
  101. public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  102. return cache.put(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  103. }
  104. @Override
  105. public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  106. return cache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  107. }
  108. @Override
  109. public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  110. cache.putAll(map, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  111. }
  112. @Override
  113. public V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  114. return cache.replace(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  115. }
  116. @Override
  117. public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  118. return cache.replace(key, oldValue, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
  119. }
  120. @Override
  121. public NotifyingFuture<V> putAsync(K key, V value) {
  122. return cache.putAsync(key, value);
  123. }
  124. @Override
  125. public NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit) {
  126. return cache.putAsync(key, value, lifespan, unit);
  127. }
  128. @Override
  129. public NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  130. return cache.putAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  131. }
  132. @Override
  133. public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data) {
  134. return cache.putAllAsync(data);
  135. }
  136. @Override
  137. public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit unit) {
  138. return cache.putAllAsync(data, lifespan, unit);
  139. }
  140. @Override
  141. public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  142. return cache.putAllAsync(data, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  143. }
  144. @Override
  145. public NotifyingFuture<Void> clearAsync() {
  146. return cache.clearAsync();
  147. }
  148. @Override
  149. public NotifyingFuture<V> putIfAbsentAsync(K key, V value) {
  150. return cache.putIfAbsentAsync(key, value);
  151. }
  152. @Override
  153. public NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit) {
  154. return cache.putIfAbsentAsync(key, value, lifespan, unit);
  155. }
  156. @Override
  157. public NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  158. return cache.putIfAbsentAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  159. }
  160. @Override
  161. public NotifyingFuture<V> removeAsync(Object key) {
  162. return cache.removeAsync(key);
  163. }
  164. @Override
  165. public NotifyingFuture<Boolean> removeAsync(Object key, Object value) {
  166. return cache.removeAsync(key, value);
  167. }
  168. @Override
  169. public NotifyingFuture<V> replaceAsync(K key, V value) {
  170. return cache.replaceAsync(key, value);
  171. }
  172. @Override
  173. public NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit) {
  174. return cache.replaceAsync(key, value, lifespan, unit);
  175. }
  176. @Override
  177. public NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  178. return cache.replaceAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  179. }
  180. @Override
  181. public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
  182. return cache.replaceAsync(key, oldValue, newValue);
  183. }
  184. @Override
  185. public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit) {
  186. return cache.replaceAsync(key, oldValue, newValue, lifespan, unit);
  187. }
  188. @Override
  189. public NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
  190. return cache.replaceAsync(key, oldValue, newValue, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
  191. }
  192. @Override
  193. public AdvancedCache<K, V> getAdvancedCache() {
  194. return cache.getAdvancedCache();
  195. }
  196. @Override
  197. public ComponentStatus getStatus() {
  198. return cache.getStatus();
  199. }
  200. @Override
  201. public V putIfAbsent(K key, V value) {
  202. return cache.putIfAbsent(key, value);
  203. }
  204. @Override
  205. public boolean remove(Object key, Object value) {
  206. return cache.remove(key, value);
  207. }
  208. @Override
  209. public boolean replace(K key, V oldValue, V newValue) {
  210. return cache.replace(key, oldValue, newValue);
  211. }
  212. @Override
  213. public V replace(K key, V value) {
  214. return cache.replace(key, value);
  215. }
  216. @Override
  217. public int size() {
  218. return cache.size();
  219. }
  220. @Override
  221. public boolean isEmpty() {
  222. return cache.isEmpty();
  223. }
  224. @Override
  225. public boolean containsKey(Object key) {
  226. return cache.containsKey(key);
  227. }
  228. @Override
  229. public boolean containsValue(Object value) {
  230. return cache.containsValue(value);
  231. }
  232. @Override
  233. public V get(Object key) {
  234. return cache.get(key);
  235. }
  236. @Override
  237. public V put(K key, V value) {
  238. return cache.put(key, value);
  239. }
  240. @Override
  241. public V remove(Object key) {
  242. return cache.remove(key);
  243. }
  244. @Override
  245. public void putAll(Map<? extends K, ? extends V> t) {
  246. cache.putAll(t);
  247. }
  248. @Override
  249. public void clear() {
  250. cache.clear();
  251. }
  252. @Override
  253. public CloseableIteratorSet<K> keySet() {
  254. return cache.keySet();
  255. }
  256. @Override
  257. public CloseableIteratorSet<Entry<K, V>> entrySet() {
  258. return cache.entrySet();
  259. }
  260. @Override
  261. public CloseableIteratorCollection<V> values() {
  262. return cache.values();
  263. }
  264. @Override
  265. public void start() {
  266. cache.start();
  267. }
  268. @Override
  269. public void stop() {
  270. cache.stop();
  271. }
  272. @Override
  273. public void addListener(Object listener) {
  274. cache.addListener(listener);
  275. }
  276. @Override
  277. public void addListener(Object listener, KeyFilter<? super K> filter) {
  278. cache.addListener(listener, filter);
  279. }
  280. @Override
  281. public <C> void addListener(Object listener, CacheEventFilter<? super K, ? super V> filter,
  282. CacheEventConverter<? super K, ? super V, C> converter) {
  283. cache.addListener(listener, filter, converter);
  284. }
  285. @Override
  286. public void removeListener(Object listener) {
  287. cache.removeListener(listener);
  288. }
  289. @Override
  290. public Set<Object> getListeners() {
  291. return cache.getListeners();
  292. }
  293. @Override
  294. public NotifyingFuture<V> getAsync(K key) {
  295. return cache.getAsync(key);
  296. }
  297. @Override
  298. public String toString() {
  299. return cache.toString();
  300. }
  301. public Cache<K, V> getDelegate() {
  302. return cache;
  303. }
  304. }