此内容没有您所选择的语言版本。
Chapter 5. The ConfigurationBuilder API
- Chain coding of configuration options in order to make the coding process more efficient
- Improve the readability of the configuration
5.1. Using the ConfigurationBuilder API 复制链接链接已复制到粘贴板!
Procedure 5.1. Configure the CacheManager Programmatically
- Create a CacheManager as a starting point in an XML file. If required, this CacheManager can be programmed in runtime to the specification that meets the requirements of the use case.
- Create a new synchronously replicated cache programmatically.
- Create a new configuration object instance using the ConfigurationBuilder helper object:In the first line of the configuration, a new cache configuration object (named
c
) is created using theConfigurationBuilder
. Configurationc
is assigned the default values for all cache configuration options except the cache mode, which is overridden and set to synchronous replication (REPL_SYNC
). - Define or register the configuration with a manager:In the third line of the configuration, the cache manager is used to define a named cache configuration for itself. This named cache configuration is called
repl
and its configuration is based on the configuration provided for cache configurationc
in the first line. - In the fourth line of the configuration, the cache manager is used to obtain a reference to the unique instance of the
repl
that is held by the cache manager. This cache instance is now ready to be used to perform operations to store and retrieve data.
Note
infinispan-config-file.xml
specifies the configuration for a replicated cache as a default and a distributed cache with a customized lifespan value is required. The required distributed cache must retain all aspects of the default cache specified in the infinispan-config-file.xml
file except the mentioned aspects.
Procedure 5.2. Customize the Default Cache
- Read an instance of a default Configuration object to get the default configuration:
- Use the ConfigurationBuilder to construct and modify the cache mode and L1 cache lifespan on a new configuration object:
- Register/define your cache configuration with a cache manager, where cacheName is name of cache specified in
infinispan-config-file.xml
: - Get default cache with custom configuration changes.
replicatedCache
as the base instead of the default cache.
Procedure 5.3. Creating a Customized Cache Using a Non-Default Named Cache
- Read the
replicatedCache
to get the default configuration. - Use the ConfigurationBuilder to construct and modify the desired configuration on a new configuration object.
- Register/define your cache configuration with a cache manager where newCacheName is the name of cache specified in
infinispan-config-file.xml
- Get a
newCacheName
cache with custom configuration changes.
5.1.5. Global Configuration Examples 复制链接链接已复制到粘贴板!
5.1.5.1. Globally Configure the Transport Layer 复制链接链接已复制到粘贴板!
Example 5.1. Configuring the Transport Layer
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .globalJmxStatistics().enable() .build();
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.globalJmxStatistics().enable()
.build();
5.1.5.2. Globally Configure the Cache Manager Name 复制链接链接已复制到粘贴板!
Example 5.2. Configuring the Cache Manager Name
5.1.5.3. Globally Customize Thread Pool Executors 复制链接链接已复制到粘贴板!
Example 5.3. Customize Thread Pool Executors
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .replicationQueueScheduledExecutor() .factory(new DefaultScheduledExecutorFactory()) .addProperty("threadNamePrefix", "RQThread") .build();
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.replicationQueueScheduledExecutor()
.factory(new DefaultScheduledExecutorFactory())
.addProperty("threadNamePrefix", "RQThread")
.build();
5.1.6. Cache Level Configuration Examples 复制链接链接已复制到粘贴板!
5.1.6.1. Cache Level Configuration for the Cluster Mode 复制链接链接已复制到粘贴板!
Example 5.4. Configure Cluster Mode at Cache Level
Example 5.5. Configuring Expiration and Eviction at the Cache Level
5.1.6.3. Cache Level Configuration for JTA Transactions 复制链接链接已复制到粘贴板!
Example 5.6. Configuring JTA Transactions at Cache Level
Example 5.7. Configuring Chained Persistent Stores at Cache Level
Example 5.8. Configuring Advanced Externalizers at Cache Level
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .serialization() .addAdvancedExternalizer(new PersonExternalizer()) .addAdvancedExternalizer(999, new AddressExternalizer()) .build();
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.serialization()
.addAdvancedExternalizer(new PersonExternalizer())
.addAdvancedExternalizer(999, new AddressExternalizer())
.build();