本文整理了Java中com.hazelcast.config.Config.addMapConfig()
方法的一些代码示例,展示了Config.addMapConfig()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.addMapConfig()
方法的具体详情如下:
包路径:com.hazelcast.config.Config
类名称:Config
方法名:addMapConfig
[英]Adds the map configuration. The configuration is saved under the config name, which may be a pattern with which the configuration will be obtained in the future.
[中]添加映射配置。配置保存在配置名称下,该名称可能是将来获取配置的模式。
代码示例来源:origin: paascloud/paascloud-master
/**
* Hazelcast config config.
*
* @return the config
*/
@Bean
public Config hazelcastConfig() {
return new Config().setProperty("hazelcast.jmx", "true")
.addMapConfig(new MapConfig("spring-boot-admin-application-store").setBackupCount(1)
.setEvictionPolicy(EvictionPolicy.NONE))
.addListConfig(new ListConfig("spring-boot-admin-event-store").setBackupCount(1)
.setMaxSize(1000));
}
代码示例来源:origin: stackoverflow.com
// Build the config from xml file you have in the classpath
Config config = new XmlConfigBuilder().build();
MapStoreConfig msc = new MapStoreConfig..
msc.setFactoryImplementation(new StoreClientFactory());
MapConfig mapConfig = new MapConfig..
mapConfig.setMapStoreConfig(msc);
config.addMapConfig(mapconfig);
// init Hazelcast with this configuration
// make sure you call init fore any other Hazelcast operation!!
Hazelcast.init(config);
// then access to your map
Map map = Hazelcast.getMap("mymap");
代码示例来源:origin: com.jtbdevelopment.core-games/games-hazelcast
@Override
public void modifyConfiguration(final Config config) {
Arrays.asList(CacheConstants.PLAYER_S_AND_SID_CACHE,
CacheConstants.PLAYER_ID_CACHE,
CacheConstants.PLAYER_MD5_CACHE,
CacheConstants.GAME_ID_CACHE).forEach(cache -> {
MapConfig mc = new MapConfig(cache);
mc.setMaxIdleSeconds(FIVE_MINUTES);
config.addMapConfig(mc);
});
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args)
throws InterruptedException {
Config config = new Config();
config.addMapConfig(new MapConfig("default").setTimeToLiveSeconds(5));
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
Map<Integer, String> map = hazelcastInstance.getMap("default");
map.put(0, "Number Zero");
// 0 overrides the map config and make the entry not expirable
((IMap<Integer, String>) map).put(1, "Number One", 0, SECONDS);
System.out.println("Entry 0: " + map.get(0) + ", Entry 1: " + map.get(1));
Thread.sleep(SECONDS.toMillis(5));
if (map.get(0) != null) {
System.err.println("Entry 0 is still alive!");
}
if (map.get(1) != null) {
System.out.println("Entry 1 is still alive!");
}
System.exit(0);
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args)
throws InterruptedException {
Config config = new Config();
config.addMapConfig(new MapConfig("default").setMaxIdleSeconds(5));
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
Map<Integer, String> map = hazelcastInstance.getMap("default");
map.put(0, "Number Zero");
// 0 overrides the map config and make the entry not expirable
((IMap<Integer, String>) map).put(1, "Number One", 0, SECONDS, 0, SECONDS);
System.out.println("Entry 0: " + map.get(0) + ", Entry 1: " + map.get(1));
Thread.sleep(SECONDS.toMillis(5));
if (map.get(0) != null) {
System.err.println("Entry 0 is still alive!");
}
if (map.get(1) != null) {
System.out.println("Entry 1 is still alive!");
}
System.exit(0);
}
代码示例来源:origin: net.kuujo/xync
/**
* Initializes a Vert.x Hazelcast instance for testing.
*/
public static void initialize() {
if (!isHazelcastCluster()) {
Hazelcast.newHazelcastInstance(new Config().addMapConfig(new MapConfig().setName("subs")));
}
}
代码示例来源:origin: com.obsidiandynamics.meteor/meteor-core
static <K, V> IMap<K, V> getMap(HazelcastInstance instance, String mapFQName,
StreamConfig streamConfig, MapStoreConfig mapStoreConfig) {
final MapConfig mapConfig = new MapConfig(mapFQName)
.setBackupCount(streamConfig.getSyncReplicas())
.setAsyncBackupCount(streamConfig.getAsyncReplicas())
.setMapStoreConfig(mapStoreConfig);
instance.getConfig().addMapConfig(mapConfig);
return instance.getMap(mapFQName);
}
}
代码示例来源:origin: com.atlassian.cache/atlassian-cache-hazelcast
private MapConfig convertAndStoreMapConfig(String mapName, CacheSettings newSettings, Config config, MapConfig baseConfig)
{
MapConfig newConfig = new MapConfig(baseConfig);
newConfig.setName(mapName);
newConfig.setStatisticsEnabled(true);
new HazelcastMapConfigConfigurator().configureMapConfig(newSettings, newConfig, hazelcast.getPartitionService().getPartitions().size());
config.addMapConfig(newConfig);
return newConfig;
}
代码示例来源:origin: stackoverflow.com
Config config = new Config();
....
MapConfig mapCfg = new MapConfig();
mapCfg.setName("default");
mapCfg.setBackupCount(2);
mapCfg.getMaxSizeConfig().setSize(10000);
mapCfg.setTimeToLiveSeconds(300);
MapStoreConfig mapStoreCfg = new MapStoreConfig();
mapStoreCfg.setClassName(MyMapStore.class.getName()).setEnabled(true);
mapCfg.setMapStoreConfig(mapStoreCfg);
// use near cache if needed
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setMaxSize(1000).setMaxIdleSeconds(120).setTimeToLiveSeconds(300);
mapCfg.setNearCacheConfig(nearCacheConfig);
config.addMapConfig(mapCfg);
Hazelcast.newHazelcastInstance(config);
代码示例来源:origin: org.apereo.cas/cas-server-support-hazelcast-ticket-registry
@Bean
public TicketRegistry ticketRegistry() {
val hz = casProperties.getTicket().getRegistry().getHazelcast();
val factory = new HazelcastConfigurationFactory();
ticketCatalog.getIfAvailable().findAll().stream()
.map(TicketDefinition::getProperties)
.peek(p -> LOGGER.debug("Created Hazelcast map configuration for [{}]", p))
.map(p -> factory.buildMapConfig(hz, p.getStorageName(), p.getStorageTimeout()))
.forEach(m -> hazelcastInstance.getIfAvailable().getConfig().addMapConfig(m));
val r = new HazelcastTicketRegistry(hazelcastInstance.getIfAvailable(),
ticketCatalog.getIfAvailable(),
hz.getPageSize());
r.setCipherExecutor(CoreTicketUtils.newTicketRegistryCipherExecutor(hz.getCrypto(), "hazelcast"));
return r;
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
MergePolicyConfig mergePolicyConfig = new MergePolicyConfig()
.setPolicy(MapEntryCostsMergePolicy.class.getName());
MapConfig mapConfig = new MapConfig("default")
.setMergePolicyConfig(mergePolicyConfig);
ReplicatedMapConfig replicatedMapConfig = new ReplicatedMapConfig("default")
.setMergePolicyConfig(mergePolicyConfig);
Config config = new Config()
.addMapConfig(mapConfig)
.addReplicatedMapConfig(replicatedMapConfig);
try {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
// this works, since it's an IMap
hazelcastInstance.getMap("myMap");
try {
hazelcastInstance.getReplicatedMap("myReplicatedMap");
} catch (InvalidConfigurationException expected) {
System.out.println("The configured merge policy is just suitable for IMap: " + expected.getMessage());
}
} finally {
Hazelcast.shutdownAll();
}
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) throws Exception {
// for a custom merge policy we have to provide the FQCN, not just the simple classname
MergePolicyConfig mergePolicyConfig = new MergePolicyConfig()
.setPolicy(UserContextMergePolicy.class.getName());
MapConfig mapConfig = new MapConfig()
.setName(MAP_NAME)
.setInMemoryFormat(InMemoryFormat.BINARY)
.setBackupCount(1)
.setAsyncBackupCount(0)
.setMergePolicyConfig(mergePolicyConfig);
// we use the user context to provide access to our TruthProvider in the merge policy
ConcurrentMap<String, Object> userContext = new ConcurrentHashMap<String, Object>();
userContext.put(TRUTH_PROVIDER_ID, new ExampleTruthProvider());
final Config config = new Config()
//.setProperty("hazelcast.logging.type", "none")
.addMapConfig(mapConfig)
.setUserContext(userContext);
HazelcastInstanceFactory.newHazelcastInstance(config);
Hazelcast.shutdownAll();
}
代码示例来源:origin: org.apache.marmotta/kiwi-caching-hazelcast
private void setupMapConfig(String name, int size) {
MapConfig cfg = new MapConfig(NODE_CACHE);
cfg.setMaxSizeConfig(new MaxSizeConfig(size, MaxSizeConfig.MaxSizePolicy.PER_PARTITION));
cfg.setAsyncBackupCount(1);
cfg.setBackupCount(0);
cfg.setEvictionPolicy(MapConfig.EvictionPolicy.LRU);
cfg.setMaxIdleSeconds(600); // 10 minutes
cfg.setTimeToLiveSeconds(3600); // 1 hour
hcConfiguration.addMapConfig(cfg);
}
代码示例来源:origin: apache/marmotta
private void setupMapConfig(String name, int size) {
MapConfig cfg = new MapConfig(NODE_CACHE);
cfg.setMaxSizeConfig(new MaxSizeConfig(size, MaxSizeConfig.MaxSizePolicy.PER_PARTITION));
cfg.setAsyncBackupCount(1);
cfg.setBackupCount(0);
cfg.setEvictionPolicy(MapConfig.EvictionPolicy.LRU);
cfg.setMaxIdleSeconds(600); // 10 minutes
cfg.setTimeToLiveSeconds(3600); // 1 hour
hcConfiguration.addMapConfig(cfg);
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
// for a custom merge policy we have to provide the FQCN, not just the simple classname
MergePolicyConfig mergePolicyConfig = new MergePolicyConfig()
.setPolicy(ComposedHitsAndCreationTimeMergePolicy.class.getName());
MapConfig mapConfig = new MapConfig()
.setName(MAP_NAME)
.setInMemoryFormat(InMemoryFormat.BINARY)
.setBackupCount(1)
.setAsyncBackupCount(0)
.setMergePolicyConfig(mergePolicyConfig);
final Config config = new Config()
//.setProperty("hazelcast.logging.type", "none")
.addMapConfig(mapConfig);
HazelcastInstanceFactory.newHazelcastInstance(config);
Hazelcast.shutdownAll();
}
}
代码示例来源:origin: jerrinot/subzero
@Test
public void givenMemberHasClassLoaderConfigured_whenObjectIsStored_thenClassLoaderWillBeUsed() throws Exception {
String mapName = randomMapName();
Config config = new Config();
SubZero.useAsGlobalSerializer(config);
ClassLoader spyingClassLoader = createSpyingClassLoader();
config.setClassLoader(spyingClassLoader);
config.addMapConfig(new MapConfig(mapName).setInMemoryFormat(OBJECT));
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
IMap<Integer, Object> myMap = member.getMap(mapName);
myMap.put(0, new MyClass());
verify(spyingClassLoader).loadClass("info.jerrinot.subzero.ClassLoadingTest$MyClass");
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static Config newConfig() {
MapConfig mapConfig = new MapConfig();
mapConfig.setName("default");
mapConfig.setInMemoryFormat(InMemoryFormat.NATIVE);
MemorySize memorySize = new MemorySize(128, MemoryUnit.MEGABYTES);
NativeMemoryConfig memoryConfig = new NativeMemoryConfig();
memoryConfig.setEnabled(true);
memoryConfig.setSize(memorySize);
memoryConfig.setAllocatorType(NativeMemoryConfig.MemoryAllocatorType.STANDARD);
Config config = new Config();
config.addMapConfig(mapConfig);
config.setNativeMemoryConfig(memoryConfig);
config.setLicenseKey(ENTERPRISE_LICENSE_KEY);
return config;
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) throws ParseException {
MapAttributeConfig mapAttributeConfig = new MapAttributeConfig();
mapAttributeConfig.setName("limbName");
mapAttributeConfig.setExtractor("com.test.portable.LimbNameExtractor");
MapConfig mapConfig = new MapConfig();
mapConfig.setName("people");
mapConfig.addMapAttributeConfig(mapAttributeConfig);
Config config = new Config();
config.getSerializationConfig().addPortableFactory(PersonFactory.FACTORY_ID, new PersonFactory());
config.addMapConfig(mapConfig);
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<Integer, Person> map = hz.getMap("people");
map.put(1, new Person("Georg", limb("left-leg"), limb("right-leg")));
map.put(2, new Person("Peter", limb("left-hand"), limb("right-hand")));
map.put(3, new Person("Hans", limb("left-finger"), limb("right-finger")));
map.put(4, new Person("Stefanie", limb("left-arm"), limb("right-arm")));
// we're using a custom attribute 'limbName' which is provided by the 'LimbNameExtractor'
Set<Person> people = (Set<Person>) map.values(Predicates.equal("limbName", "left-arm"));
System.out.println("People: " + people);
Hazelcast.shutdownAll();
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static Config newConfig() {
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setMaxSizePolicy(PER_NODE);
maxSizeConfig.setSize(MAX_ENTRY_COUNT);
MapConfig mapConfig = new MapConfig();
mapConfig.setName("default");
mapConfig.setInMemoryFormat(InMemoryFormat.NATIVE);
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
mapConfig.setMaxSizeConfig(maxSizeConfig);
mapConfig.setMinEvictionCheckMillis(0);
MemorySize memorySize = new MemorySize(128, MemoryUnit.MEGABYTES);
NativeMemoryConfig memoryConfig = new NativeMemoryConfig();
memoryConfig.setEnabled(true);
memoryConfig.setSize(memorySize);
memoryConfig.setAllocatorType(NativeMemoryConfig.MemoryAllocatorType.STANDARD);
Config config = new Config();
config.addMapConfig(mapConfig);
config.setNativeMemoryConfig(memoryConfig);
config.setLicenseKey(ENTERPRISE_LICENSE_KEY);
return config;
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
private static Config newConfig() {
NearCacheConfig nearCacheConfig = new NearCacheConfig();
EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig();
evictionConfig.setMaximumSizePolicy(USED_NATIVE_MEMORY_PERCENTAGE);
evictionConfig.setSize(90);
nearCacheConfig.setInMemoryFormat(NATIVE);
nearCacheConfig.setInvalidateOnChange(true);
nearCacheConfig.setCacheLocalEntries(true);
nearCacheConfig.setName("default");
MapConfig mapConfig = new MapConfig();
mapConfig.setName("default");
mapConfig.setNearCacheConfig(nearCacheConfig);
NativeMemoryConfig memoryConfig = new NativeMemoryConfig();
memoryConfig.setEnabled(true);
memoryConfig.setSize(new MemorySize(128, MEGABYTES));
memoryConfig.setAllocatorType(STANDARD);
Config config = new Config();
config.addMapConfig(mapConfig);
config.setNativeMemoryConfig(memoryConfig);
config.setLicenseKey(ENTERPRISE_LICENSE_KEY);
return config;
}
}
内容来源于网络,如有侵权,请联系作者删除!