View Javadoc
1   package com.atlassian.cache.hazelcast;
2   
3   import java.util.SortedMap;
4   import java.util.concurrent.TimeUnit;
5   
6   import javax.annotation.Nonnull;
7   
8   import com.atlassian.cache.CacheStatisticsKey;
9   import com.atlassian.cache.ManagedCache;
10  import java.util.function.Supplier;
11  
12  import com.google.common.collect.ImmutableSortedMap;
13  
14  /**
15   * Common implementation of {@link com.atlassian.cache.ManagedCache} methods for hybrid caches and cached references.
16   *
17   * @since 2.4.0
18   */
19  public abstract class ManagedHybridCacheSupport implements ManagedCache
20  {
21      protected final HazelcastCacheManager cacheManager;
22      protected final String name;
23  
24      public ManagedHybridCacheSupport(String name, HazelcastCacheManager cacheManager)
25      {
26          this.cacheManager = cacheManager;
27          this.name = name;
28      }
29  
30      @Override
31      public Long currentExpireAfterAccessMillis()
32      {
33          return getLocalCache().currentExpireAfterAccessMillis();
34      }
35  
36      @Override
37      public Long currentExpireAfterWriteMillis()
38      {
39          return getLocalCache().currentExpireAfterWriteMillis();
40      }
41  
42      @Override
43      public Integer currentMaxEntries()
44      {
45          return getLocalCache().currentMaxEntries();
46      }
47  
48      @Nonnull
49      @Override
50      public String getName()
51      {
52          return name;
53      }
54  
55      @Override
56      public boolean isLocal()
57      {
58          return false;
59      }
60  
61      @Override
62      public boolean isReplicateViaCopy()
63      {
64          return false;
65      }
66  
67      @Override
68      public boolean updateExpireAfterAccess(long expireAfter, @Nonnull TimeUnit timeUnit)
69      {
70          return getLocalCache().updateExpireAfterAccess(expireAfter, timeUnit);
71      }
72  
73      @Override
74      public boolean updateExpireAfterWrite(long expireAfter, @Nonnull TimeUnit timeUnit)
75      {
76          return getLocalCache().updateExpireAfterAccess(expireAfter, timeUnit);
77      }
78  
79      @Override
80      public boolean updateMaxEntries(int newValue)
81      {
82          return getLocalCache().updateMaxEntries(newValue);
83      }
84  
85      protected abstract ManagedCache getLocalCache();
86  
87      @Nonnull
88      @Override
89      public SortedMap<CacheStatisticsKey, Supplier<Long>> getStatistics()
90      {
91          return ImmutableSortedMap.of();
92      }
93  
94      @Override
95      public boolean isStatisticsEnabled()
96      {
97          return false;
98      }
99  
100     @Override
101     public void setStatistics(boolean enabled) { throw new UnsupportedOperationException("setStatistics() not implemented"); }
102 }