Class DefaultConfigurableCacheFactory
The DefaultConfigurableCacheFactory provides a facility to access caches declared in a "cache-config.xsd" compliant configuration file.
Inherited Members
Namespace: Tangosol.Net
Assembly: Coherence.dll
Syntax
public class DefaultConfigurableCacheFactory : IConfigurableCacheFactory, IXmlConfigurable
Remarks
This class is designed to be easily extendable with a collection of factory methods allowing subclasses to customize it by overriding any subset of cache instantiation routines or even allowing the addition of custom schemes.
There are various ways of using this factory:
IConfigurableCacheFactory factory =
new DefaultConfigurableCacheFactory(path);
INamedCache cacheOne = factory.EnsureCache("one");
INamedCache cacheTwo = factory.EnsureCache("two");
Using this approach allows an easy customization by extending the DefaultConfigurableCacheFactory and changing the instantiation line:
IConfigurableCacheFactory factory =
new CustomConfigurableCacheFactory();
...
Another option is using the static version of the "EnsureCache" call:
INamedCache cacheOne = CacheFactory.GetCache("one");
INamedCache cacheTwo = CacheFactory.GetCache("two");
which uses an instance of IConfigurableCacheFactory
obtained by the ConfigurableCacheFactory.
Constructors
DefaultConfigurableCacheFactory()
Construct a default DefaultConfigurableCacheFactory using the default configuration file name.
Declaration
public DefaultConfigurableCacheFactory()
DefaultConfigurableCacheFactory(string)
Construct a DefaultConfigurableCacheFactory using the specified path to a "cache-config.xsd" compliant configuration file.
Declaration
public DefaultConfigurableCacheFactory(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The configuration file path. |
DefaultConfigurableCacheFactory(IXmlElement)
Construct a DefaultConfigurableCacheFactory using the specified configuration XML.
Declaration
public DefaultConfigurableCacheFactory(IXmlElement xmlConfig)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlElement | xmlConfig | The configuration IXmlElement. |
Fields
CACHE_NAME
The name of the replaceable parameter representing the cache name.
Declaration
public const string CACHE_NAME = "{cache-name}"
Field Value
| Type | Description |
|---|---|
| string |
SCHEME_REF
The name of the replaceable parameter representing the scheme reference.
Declaration
public const string SCHEME_REF = "{scheme-ref}"
Field Value
| Type | Description |
|---|---|
| string |
m_storeCache
Store that holds cache references by name and optionally, if configured, IPrincipal.
Declaration
protected ScopedReferenceStore m_storeCache
Field Value
| Type | Description |
|---|---|
| ScopedReferenceStore |
m_storeService
Store that holds service references by name and optionally, if configured, IPrincipal.
Declaration
protected ScopedReferenceStore m_storeService
Field Value
| Type | Description |
|---|---|
| ScopedReferenceStore |
Properties
Config
The current configuration of the object.
Declaration
public virtual IXmlElement Config { get; set; }
Property Value
| Type | Description |
|---|---|
| IXmlElement | The XML configuration or |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | When setting, if the object is not in a state that allows the configuration to be set; for example, if the object has already been configured and cannot be reconfigured. |
DefaultCacheConfig
The default XML configuration used when one isn't explicitly passed in the constructor for this class.
Declaration
public static IXmlDocument DefaultCacheConfig { get; set; }
Property Value
| Type | Description |
|---|---|
| IXmlDocument | The default XML configuration. |
DefaultCacheConfigResource
The IResource for the default XML configuration used when one isn't explicitly passed in the constructor for this class.
Declaration
public static IResource DefaultCacheConfigResource { get; set; }
Property Value
| Type | Description |
|---|---|
| IResource | The IResource for the default XML configuration. |
OperationalContext
The IOperationalContext for this DefaultConfigurableCacheFactory.
Declaration
public virtual IOperationalContext OperationalContext { get; set; }
Property Value
| Type | Description |
|---|---|
| IOperationalContext | An IOperationalContext instance. |
StoreCache
Store that holds cache references by name and optionally, if configured, IPrincipal.
Declaration
protected virtual ScopedReferenceStore StoreCache { get; set; }
Property Value
| Type | Description |
|---|---|
| ScopedReferenceStore |
StoreService
Store that holds cache references by name and optionally, if configured, IPrincipal.
Declaration
protected virtual ScopedReferenceStore StoreService { get; set; }
Property Value
| Type | Description |
|---|---|
| ScopedReferenceStore |
Methods
ConfigureBackingCache(CacheInfo, IXmlElement)
Configures a backing cache according to the scheme.
Declaration
public virtual ICache ConfigureBackingCache(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlScheme)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlScheme | The scheme element for cache configuration. |
Returns
| Type | Description |
|---|---|
| ICache | A backing cache configured according to the scheme. |
ConfigureCache(CacheInfo, IXmlElement)
Ensures a cache for given scheme.
Declaration
protected INamedCache ConfigureCache(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlScheme)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlScheme | The corresponding scheme. |
Returns
| Type | Description |
|---|---|
| INamedCache | A named cache created according to the description in the configuration. |
ConvertInt(IXmlValue)
Convert the value in the specified IXmlValue to an int. If the conversion fails, a warning will be logged.
Declaration
protected static int ConvertInt(IXmlValue xmlValue)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlValue | xmlValue | The element expected to contain an int value. |
Returns
| Type | Description |
|---|---|
| int | The int value in the provided element, or 0 upon a conversion failure. |
ConvertInt(IXmlValue, int)
Convert the value in the specified IXmlValue to an int. If the conversion fails, a warning will be logged.
Declaration
protected static int ConvertInt(IXmlValue xmlValue, int defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlValue | xmlValue | The element expected to contain an int value. |
| int | defaultValue | The value that will be returned if the element does not contain a value that can be converted to int. |
Returns
| Type | Description |
|---|---|
| int | The int value in the provided element, or defaultValue upon a conversion failure. |
DestroyCache(INamedCache)
Release and destroy the specified cache.
Declaration
public virtual void DestroyCache(INamedCache cache)
Parameters
| Type | Name | Description |
|---|---|---|
| INamedCache | cache | The INamedCache object to be destroyed. |
Remarks
Warning: This method is used to completely destroy the specified cache across the cluster. All references in the entire cluster to this cache will be invalidated, the cached data will be cleared, and all resources will be released.
See Also
EnsureCache(string)
Ensure a cache for the given name using the corresponding XML configuration.
Declaration
public virtual INamedCache EnsureCache(string cacheName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cacheName | The cache name. |
Returns
| Type | Description |
|---|---|
| INamedCache | An INamedCache created according to the configuration XML. |
EnsureCache(CacheInfo, IXmlElement)
Obtain the INamedCache reference for the cache service defined by the specified scheme.
Declaration
protected virtual INamedCache EnsureCache(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlScheme)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlScheme | The scheme element for the cache. |
Returns
| Type | Description |
|---|---|
| INamedCache | INamedCache instance. |
EnsureService(string)
Ensure a service for the given name using the corresponding XML configuration.
Declaration
public virtual IService EnsureService(string serviceName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serviceName | The service name. |
Returns
| Type | Description |
|---|---|
| IService | An IService created according to the configuration XML. |
EnsureService(string, ServiceType)
Ensure the service for the specified service name and type.
Declaration
protected virtual IService EnsureService(string serviceName, ServiceType serviceType)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serviceName | Service name. |
| ServiceType | serviceType | Service type. |
Returns
| Type | Description |
|---|---|
| IService | An IService object. |
EnsureService(IXmlElement)
Ensure the service for the specified scheme.
Declaration
public virtual IService EnsureService(IXmlElement xmlScheme)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlElement | xmlScheme | The scheme. |
Returns
| Type | Description |
|---|---|
| IService | Running IService corresponding to the scheme. |
FindScheme(string)
In the configuration XML find a "scheme" element associated with a given cache name.
Declaration
protected virtual IXmlElement FindScheme(string schemeName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | schemeName | The value of the "scheme-name" element to look for. |
Returns
| Type | Description |
|---|---|
| IXmlElement | A "scheme" element associated with a given cache name. |
FindScheme(IXmlElement, string)
In the specified configuration XML, find a "scheme" element associated with the specified scheme name.
Declaration
protected static IXmlElement FindScheme(IXmlElement xmlConfig, string schemeName)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlElement | xmlConfig | The xml configuration. |
| string | schemeName | The value of the "scheme-name" element to look for. |
Returns
| Type | Description |
|---|---|
| IXmlElement | A "scheme" element associated with a given scheme name, or
|
FindSchemeMapping(string)
In the configuration XML find a "cache-mapping" element associated with a given cache name.
Declaration
public virtual DefaultConfigurableCacheFactory.CacheInfo FindSchemeMapping(string cacheName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cacheName | The value of the "cache-name" element to look for. |
Returns
| Type | Description |
|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | A DefaultConfigurableCacheFactory.CacheInfo object associated with a given cache name. |
FindServiceScheme(string)
In the configuration XML find a "scheme" element associated with a given service name.
Declaration
protected virtual IXmlElement FindServiceScheme(string serviceName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serviceName | The value of the "service-name" element to look for. |
Returns
| Type | Description |
|---|---|
| IXmlElement | A "scheme" element associated with a given service name. |
InstantiateAny(CacheInfo, IXmlElement)
Create an object using "class-scheme" element.
Declaration
public virtual object InstantiateAny(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlClass)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlClass | The "class-scheme" element. |
Returns
| Type | Description |
|---|---|
| object | A newly instantiated object. |
Remarks
If the value of any "param-value" element contains the literal "{cache-name}", replace it with the actual cache name.
Finally, if the value of "param-type" is "{scheme-ref}" then the "param-value" should be a name of the scheme that will be used in place of the value.
InstantiateBundlingNamedCache(INamedCache, IXmlElement)
Create a BundlingNamedCache using the "operation-bundling" element.
Declaration
public BundlingNamedCache InstantiateBundlingNamedCache(INamedCache cache, IXmlElement xmlBundling)
Parameters
| Type | Name | Description |
|---|---|---|
| INamedCache | cache | The wrapped cache. |
| IXmlElement | xmlBundling | The "operation-bundling" element. |
Returns
| Type | Description |
|---|---|
| BundlingNamedCache | A newly instantiated BundlingNamedCache. |
InstantiateCache(CacheInfo, IXmlElement)
Create a backing cache using the "class-scheme" element.
Declaration
protected virtual ICache InstantiateCache(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlClass)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlClass | The "class-scheme" element. |
Returns
| Type | Description |
|---|---|
| ICache | A newly instantiated cache. |
Remarks
This method is a thin wrapper around InstantiateAny(CacheInfo, IXmlElement).
InstantiateCacheListener(CacheInfo, IXmlElement)
Create an ICacheListener using the "class-scheme" element.
Declaration
protected virtual ICacheListener InstantiateCacheListener(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlClass)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlClass | The "class-scheme" element. |
Returns
| Type | Description |
|---|---|
| ICacheListener | A newly instantiated ICacheListener. |
InstantiateCacheStore(CacheInfo, IXmlElement)
Create an ICacheLoader or ICacheStore using the "class-scheme" element.
Declaration
protected virtual ICacheLoader InstantiateCacheStore(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlStore)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlStore | The "class-scheme" or "extend-cache-scheme" element for the store. |
Returns
| Type | Description |
|---|---|
| ICacheLoader | A newly instantiated ICacheStore. |
InstantiateLocalNamedCache(int, int)
Construct a LocalNamedCache using the specified parameters.
Declaration
protected virtual LocalNamedCache InstantiateLocalNamedCache(int units, int expiryMillis)
Parameters
| Type | Name | Description |
|---|---|---|
| int | units | The number of units that the cache manager will cache before pruning the cache. |
| int | expiryMillis | The number of milliseconds that each cache entry lives before being automatically expired. |
Returns
| Type | Description |
|---|---|
| LocalNamedCache | A newly instantiated cache. |
Remarks
This method exposes a corresponding LocalNamedCache constructor and is provided for the express purpose of allowing its override.
InstantiateLocalNamedCache(CacheInfo, IXmlElement)
Create a backing cache using the "local-scheme" element.
Declaration
protected virtual INamedCache InstantiateLocalNamedCache(DefaultConfigurableCacheFactory.CacheInfo info, IXmlElement xmlLocal)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| IXmlElement | xmlLocal | The "local-scheme" element. |
Returns
| Type | Description |
|---|---|
| INamedCache | A newly instantiated cache. |
InstantiateNearCache(ICache, INamedCache, CompositeCacheStrategyType)
Construct an NearCache using the specified parameters.
Declaration
protected virtual NearCache InstantiateNearCache(ICache cacheFront, INamedCache cacheBack, CompositeCacheStrategyType strategy)
Parameters
| Type | Name | Description |
|---|---|---|
| ICache | cacheFront | ICache to put in front of the back cache. |
| INamedCache | cacheBack | INamedCache to put behind the front cache. |
| CompositeCacheStrategyType | strategy | Specifies the strategy used for the front cache invalidation; valid values are: ListenNoneListenPresentListenAllListenAuto |
Returns
| Type | Description |
|---|---|
| NearCache | A newly instantiated NearCache. |
Remarks
This method exposes a corresponding NearCache constructor and is provided for the express purpose of allowing its override.
InstantiateSubtype(string, Type, object[], IXmlElement)
Construct an instance of the specified type using the specified parameters.
Declaration
protected virtual object InstantiateSubtype(string typeName, Type supType, object[] initParams, IXmlElement xmlParams)
Parameters
| Type | Name | Description |
|---|---|---|
| string | typeName | The type name. |
| Type | supType | The super type of the newly instantiated type. |
| object[] | initParams | The constructor paramters. |
| IXmlElement | xmlParams | Optional IXmlElement ("init-params"). |
Returns
| Type | Description |
|---|---|
| object | A newly instantiated object. |
LoadDefaultCacheConfig()
Load and return the default XML cache configuration.
Declaration
protected static IXmlDocument LoadDefaultCacheConfig()
Returns
| Type | Description |
|---|---|
| IXmlDocument | The default XML cache configuration. |
ReleaseCache(INamedCache)
Release local resources associated with the specified cache instance.
Declaration
public virtual void ReleaseCache(INamedCache cache)
Parameters
| Type | Name | Description |
|---|---|---|
| INamedCache | cache | The INamedCache object to be released. |
Remarks
This invalidates a reference obtained from the factory.
Releasing an INamedCache reference makes it no longer usable, but does not affect the content of the cache. In other words, all other references to the cache will still be valid, and the cache data is not affected by releasing the reference.
The reference that is released using this method can no longer be used; any attempt to use the reference will result in an exception.
See Also
ReleaseCache(INamedCache, bool)
Release a cache managed by this factory, optionally destroying it.
Declaration
protected virtual void ReleaseCache(INamedCache cache, bool destroy)
Parameters
| Type | Name | Description |
|---|---|---|
| INamedCache | cache | The INamedCache object to be released. |
| bool | destroy | True if the cache should also be destroyed. |
Remarks
This invalidates a reference obtained from the factory.
ReportConversionError(IXmlValue, string, string, SystemException)
Log a failed type conversion.
Declaration
protected static void ReportConversionError(IXmlValue xmlValue, string type, string defaultValue, SystemException e)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlValue | xmlValue | Element that contains the value that failed conversion. |
| string | type | Type that conversion was attempted to. |
| string | defaultValue | Default value that will be substituted. |
| SystemException | e | Root cause of failed type conversion. |
ResolveScheme(CacheInfo)
In the configuration XML find a "scheme" element associated with a given cache and resolve it (recursively) using the "scheme-ref" elements.
Declaration
public virtual IXmlElement ResolveScheme(DefaultConfigurableCacheFactory.CacheInfo info)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
Returns
| Type | Description |
|---|---|
| IXmlElement | A resolved "scheme" element associated with a given cache. |
Remarks
The returned XML is always a clone of the actual configuration and could be safely modified.
ResolveScheme(IXmlElement, CacheInfo, bool, bool)
Resolve the specified "XYZ-scheme" by retrieving the base element refered to by the "scheme-ref" element, resolving it recursively, and combining it with the specified overrides and cache specific attributes.
Declaration
protected virtual IXmlElement ResolveScheme(IXmlElement xmlScheme, DefaultConfigurableCacheFactory.CacheInfo info, bool isChild, bool isRequired)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlElement | xmlScheme | A scheme element to resolve. |
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info (optional). |
| bool | isChild | If true, the actual cache scheme is the only "xyz-scheme" child of the specified xmlScheme element; otherwise it's the xmlScheme element itself. |
| bool | isRequired | If true, the child scheme must be present; false otherwise. |
Returns
| Type | Description |
|---|---|
| IXmlElement | A "scheme" element associated with a given cache name;
|
ResolveScheme(IXmlElement, IXmlElement, CacheInfo, bool, bool, bool)
Resolve the specified "XYZ-scheme" by retrieving the base element refered to by the "scheme-ref" element, resolving it recursively, and combining it with the specified overrides and cache specific attributes.
Declaration
protected static IXmlElement ResolveScheme(IXmlElement xmlConfig, IXmlElement xmlScheme, DefaultConfigurableCacheFactory.CacheInfo info, bool isChild, bool isRequired, bool apply)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlElement | xmlConfig | The cache configuration xml. |
| IXmlElement | xmlScheme | A scheme element to resolve. |
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info (optional). |
| bool | isChild | If true, the actual cache scheme is the only "xyz-scheme" child of the specified xmlScheme element; otherwise it's the xmlScheme element itself. |
| bool | isRequired | If true, the child scheme must be present; false otherwise. |
| bool | apply | If true, apply the specified overrides and cache-specific attributes to the base scheme element; otherwise return a reference to the base scheme element. |
Returns
| Type | Description |
|---|---|
| IXmlElement | A "scheme" element associated with a given cache name;
|
ResolveSerializer(IXmlElement)
Resolve and inject service serializer elements based on defaults defined in the cache configuration.
Declaration
protected void ResolveSerializer(IXmlElement xmlConfig)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlElement | xmlConfig | The configuration element to examine and modify. |
Shutdown()
Release all resources allocated by this cache factory.
Declaration
public virtual void Shutdown()
TranslateSchemeType(string)
Translate the scheme name into the scheme type.
Declaration
public virtual DefaultConfigurableCacheFactory.SchemeType TranslateSchemeType(string scheme)
Parameters
| Type | Name | Description |
|---|---|---|
| string | scheme | The scheme name. |
Returns
| Type | Description |
|---|---|
| DefaultConfigurableCacheFactory.SchemeType | The scheme type. |
Remarks
Valid scheme types are any of the DefaultConfigurableCacheFactory.SchemeType enumeration values.
ValidateConfig(IXmlElement)
Check if configuration is valid:
- service definition must not be duplicated
Declaration
protected virtual void ValidateConfig(IXmlElement config)
Parameters
| Type | Name | Description |
|---|---|---|
| IXmlElement | config | IXmlElement with factory configuration. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If configuration is not valid. |
VerifyCacheListener(CacheInfo, ICache, IXmlElement)
Check whether or not an ICacheListener has to be instantiated and added to an ICache according to a scheme definition.
Declaration
protected virtual void VerifyCacheListener(DefaultConfigurableCacheFactory.CacheInfo info, ICache cache, IXmlElement xmlScheme)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultConfigurableCacheFactory.CacheInfo | info | The cache info. |
| ICache | cache | The ICache to add a listener to. |
| IXmlElement | xmlScheme | The corresponding scheme. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If the listener is required, but the cache does not implement the IObservableCache interface or if the listener cannot be instantiated. |
initializeBundler(AbstractBundler, IXmlElement)
Initialize the specified bundler using the "bundle-config" element.
Declaration
protected void initializeBundler(AbstractBundler bundler, IXmlElement xmlBundle)
Parameters
| Type | Name | Description |
|---|---|---|
| AbstractBundler | bundler | The bundler. |
| IXmlElement | xmlBundle | A "bundle-config" element. |