00001 /* 00002 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 00003 * 00004 * Licensed under the Universal Permissive License v 1.0 as shown at 00005 * http://oss.oracle.com/licenses/upl. 00006 */ 00007 #ifndef COH_NAMED_CACHE_HPP 00008 #define COH_NAMED_CACHE_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 #include "coherence/net/ViewBuilder.hpp" 00013 00014 #include "coherence/net/cache/CacheMap.hpp" 00015 00016 #include "coherence/util/ConcurrentMap.hpp" 00017 #include "coherence/util/InvocableMap.hpp" 00018 #include "coherence/util/ObservableMap.hpp" 00019 #include "coherence/util/QueryMap.hpp" 00020 00021 COH_OPEN_NAMESPACE2(coherence,net) 00022 00023 using coherence::net::cache::CacheMap; 00024 using coherence::util::ConcurrentMap; 00025 using coherence::util::InvocableMap; 00026 using coherence::util::ObservableMap; 00027 using coherence::util::QueryMap; 00028 00029 class CacheService; 00030 00031 /** 00032 * A NamedCache is a Map that holds resources shared among members of a 00033 * cluster. These resources are expected to be managed in memory, and are 00034 * typically composed of data that are also stored persistently in a database, 00035 * or data that have been assembled or calculated at some significant cost, 00036 * thus these resources are referred to as <i>cached</i>. 00037 * 00038 * @see coherence::net::cache::CacheMap 00039 * @see coherence::util::ConcurrentMap 00040 * @see coherence::util::InvocableMap 00041 * @see coherence::util::ObservableMap 00042 * @see coherence::util::QueryMap 00043 * 00044 * @author jh 2008.03.05 00045 */ 00046 class COH_EXPORT NamedCache 00047 : public interface_spec<NamedCache, 00048 implements<CacheMap, ConcurrentMap, InvocableMap, QueryMap, 00049 ObservableMap> > 00050 { 00051 // ----- handle definitions --------------------------------------------- 00052 00053 public: 00054 /** 00055 * CacheService Handle definition. 00056 */ 00057 typedef TypedHandle<CacheService> CacheServiceHandle; 00058 00059 /** 00060 * CacheService View definition. 00061 */ 00062 typedef TypedHandle<const CacheService> CacheServiceView; 00063 00064 00065 // ----- NamedCache interface ------------------------------------------- 00066 00067 public: 00068 /** 00069 * Return the cache name. 00070 * 00071 * @return the cache name 00072 */ 00073 virtual String::View getCacheName() const = 0; 00074 00075 /** 00076 * Return the CacheService that this NamedCache is a part of. 00077 * 00078 * @return the CacheService 00079 */ 00080 virtual CacheServiceHandle getCacheService() = 0; 00081 00082 /** 00083 * Return the CacheService that this NamedCache is a part of. 00084 * 00085 * @return the CacheService 00086 */ 00087 virtual CacheServiceView getCacheService() const = 0; 00088 00089 /** 00090 * Specifies whether or not the NamedCache is active. 00091 * 00092 * @return true if the NamedCache is active; false otherwise 00093 */ 00094 virtual bool isActive() const = 0; 00095 00096 /** 00097 * Release local resources associated with this instance of 00098 * NamedCache. 00099 * 00100 * Releasing a cache makes it no longer usable, but does not affect 00101 * the cache itself. In other words, all other references to the cache 00102 * will still be valid, and the cache data is not affected by 00103 * releasing the reference. Any attempt to use this reference 00104 * afterward will result in an exception. 00105 * 00106 * Caches should be released by the same mechanism in which they were 00107 * obtained. For example: 00108 * <ul> 00109 * <li> Cache::create() - cache->release()</li> 00110 * <li> CacheFactory::getCache() - CacheFactory::releaseCache()</li> 00111 * <li> ConfigurableCacheFactory::ensureCache() - ConfigurableCacheFactory::releaseCache()</li> 00112 * </ul> 00113 * Except for the case where the application code explicitly allocated 00114 * the cache, this method should not be called by application code. 00115 * 00116 * @see CacheFactory#releaseCache 00117 * @see ConfigurableCacheFactory#releaseCache 00118 */ 00119 virtual void release() = 0; 00120 00121 /** 00122 * Release and destroy this instance of NamedCache. 00123 * 00124 * <b>Warning:</b> This method is used to completely destroy the 00125 * specified cache across the cluster. All references in the entire 00126 * cluster to this cache will be invalidated, the cached data will be 00127 * cleared, and all resources will be released. 00128 * 00129 * Caches should be destroyed by the same mechanism in which they were 00130 * obtained. For example: 00131 * <ul> 00132 * <li> Cache::create() - cache->destroy()</li> 00133 * <li> CacheFactory::getCache() - CacheFactory::destroyCache()</li> 00134 * <li> ConfigurableCacheFactory::ensureCache() - ConfigurableCacheFactory::destroyCache()</li> 00135 * </ul> 00136 * Except for the case where the application code explicitly allocated 00137 * the cache, this method should not be called by application code. 00138 * 00139 * @see CacheService#destroyCache 00140 */ 00141 virtual void destroy() = 0; 00142 00143 /** 00144 * Removes all mappings from this map. 00145 * <p> 00146 * Note: the removal of entries caused by this truncate operation will 00147 * not be observable. This includes any registered {@link MapListener 00148 * listeners}, {@link MapTrigger triggers}, or interceptors. However, a 00149 * CacheLifecycleEvent is raised to notify subscribers of the execution 00150 * of this operation. 00151 * 00152 * @throws UnsupportedOperationException if the server does not support the truncate operation 00153 */ 00154 virtual void truncate() 00155 { 00156 COH_THROW (UnsupportedOperationException::create()); 00157 } 00158 00159 /** 00160 * Construct a view of this NamedCache. 00161 * 00162 * @return a local view for this NamedCache 00163 * 00164 * @see ViewBuilder 00165 * 00166 * @since 12.2.1.4 00167 */ 00168 virtual ViewBuilder::Handle view() 00169 { 00170 return ViewBuilder::create(this); 00171 } 00172 }; 00173 00174 COH_CLOSE_NAMESPACE2 00175 00176 #endif // COH_NAMED_CACHE_HPP