Class CacheUtil


  • public final class CacheUtil
    extends java.lang.Object
    Utility class for various cache related operations to be used by our internal structure and end user.
    Since:
    3.7
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getDistributedObjectName​(java.lang.String cacheName)
      Convenience method to obtain the name of Hazelcast distributed object corresponding to the cache identified by the given cacheName, assuming null URI and ClassLoader prefixes.
      static java.lang.String getDistributedObjectName​(java.lang.String cacheName, java.net.URI uri, java.lang.ClassLoader classLoader)
      Convenience method to obtain the name of Hazelcast distributed object corresponding to the cache identified by the given arguments.
      static java.lang.String getPrefix​(java.net.URI uri, java.lang.ClassLoader classLoader)
      Gets the prefix of cache name without Hazelcast's CacheManager specific prefix HazelcastCacheManager.CACHE_MANAGER_PREFIX.
      static java.lang.String getPrefixedCacheName​(java.lang.String name, java.net.URI uri, java.lang.ClassLoader classLoader)
      Gets the cache name with prefix but without Hazelcast's CacheManager specific prefix HazelcastCacheManager.CACHE_MANAGER_PREFIX.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getPrefix

        public static java.lang.String getPrefix​(java.net.URI uri,
                                                 java.lang.ClassLoader classLoader)
        Gets the prefix of cache name without Hazelcast's CacheManager specific prefix HazelcastCacheManager.CACHE_MANAGER_PREFIX.
        Parameters:
        uri - an implementation specific URI for the Hazelcast's CacheManager (null means use Hazelcast's CachingProvider.getDefaultURI())
        classLoader - the ClassLoader to use for the Hazelcast's CacheManager (null means use Hazelcast's CachingProvider.getDefaultClassLoader())
        Returns:
        the prefix of cache name without Hazelcast's CacheManager specific prefix HazelcastCacheManager.CACHE_MANAGER_PREFIX
      • getPrefixedCacheName

        public static java.lang.String getPrefixedCacheName​(java.lang.String name,
                                                            java.net.URI uri,
                                                            java.lang.ClassLoader classLoader)
        Gets the cache name with prefix but without Hazelcast's CacheManager specific prefix HazelcastCacheManager.CACHE_MANAGER_PREFIX.
        Parameters:
        name - the simple name of the cache without any prefix
        uri - an implementation specific URI for the Hazelcast's CacheManager (null means use Hazelcast's CachingProvider.getDefaultURI())
        classLoader - the ClassLoader to use for the Hazelcast's CacheManager (null means use Hazelcast's CachingProvider.getDefaultClassLoader())
        Returns:
        the cache name with prefix but without Hazelcast's CacheManager specific prefix HazelcastCacheManager.CACHE_MANAGER_PREFIX.
      • getDistributedObjectName

        public static java.lang.String getDistributedObjectName​(java.lang.String cacheName)
        Convenience method to obtain the name of Hazelcast distributed object corresponding to the cache identified by the given cacheName, assuming null URI and ClassLoader prefixes. This is equivalent to invoking getDistributedObjectName(String, URI, ClassLoader) with null passed as URI and ClassLoader arguments.
        Parameters:
        cacheName - the simple name of the cache without any prefix
        Returns:
        the name of the ICache distributed object corresponding to given cacheName, assuming null URI & class loader prefixes.
        See Also:
        getDistributedObjectName(String, URI, ClassLoader)
      • getDistributedObjectName

        public static java.lang.String getDistributedObjectName​(java.lang.String cacheName,
                                                                java.net.URI uri,
                                                                java.lang.ClassLoader classLoader)
        Convenience method to obtain the name of Hazelcast distributed object corresponding to the cache identified by the given arguments. The distributed object name returned by this method can be used to obtain the cache as a Hazelcast ICache as shown in this example:
              HazelcastInstance hz = Hazelcast.newHazelcastInstance();
        
              // Obtain Cache via JSR-107 API
              CachingProvider hazelcastCachingProvider = Caching.getCachingProvider(
                          "com.hazelcast.cache.HazelcastCachingProvider",
                          HazelcastCachingProvider.class.getClassLoader());
              CacheManager cacheManager = hazelcastCachingProvider.getCacheManager();
              Cache testCache = cacheManager.createCache("test", new MutableConfiguration<String, String>());
        
              // URI and ClassLoader are null, since we created this cache with the default CacheManager,
              // otherwise we should pass the owning CacheManager's URI & ClassLoader as arguments.
              String distributedObjectName = CacheUtil.asDistributedObjectName("test", null, null);
        
              // Obtain a reference to the backing ICache via HazelcastInstance.getDistributedObject.
              // You may invoke this on any member of the cluster.
              ICache<String, String> distributedObjectCache = (ICache) hz.getDistributedObject(
                          ICacheService.SERVICE_NAME,
                          distributedObjectName);
         
        Parameters:
        cacheName - the simple name of the cache without any prefix
        uri - an implementation specific URI for the Hazelcast's CacheManager (null means use Hazelcast's CachingProvider.getDefaultURI())
        classLoader - the ClassLoader to use for the Hazelcast's CacheManager (null means use Hazelcast's CachingProvider.getDefaultClassLoader())
        Returns:
        the name of the ICache distributed object corresponding to given arguments.