View Javadoc

1   package com.atlassian.cache.hazelcast;
2   
3   import com.hazelcast.core.HazelcastInstance;
4   import com.hazelcast.core.IAtomicLong;
5   
6   import static com.google.common.base.Preconditions.checkNotNull;
7   
8   class CacheVersion
9   {
10      public static final String CACHE_VERSION_PREFIX = "_CACHE_VERSION.";
11  
12      private final IAtomicLong version;
13  
14      public CacheVersion(HazelcastInstance instance, String cacheName)
15      {
16          this.version = checkNotNull(instance, "instance").getAtomicLong(CACHE_VERSION_PREFIX.concat(checkNotNull(cacheName, "cacheName")));
17      }
18  
19      /**
20       * Returns current cache version
21       */
22      public long get()
23      {
24          return version.get();
25      }
26  
27      /**
28       * Increments and then return current cache version. Atomic.
29       */
30      public long incrementAndGet()
31      {
32          return version.incrementAndGet();
33      }
34  
35  
36  }