本文整理匯總了Java中com.hazelcast.config.MapConfig.setTimeToLiveSeconds方法的典型用法代碼示例。如果您正苦於以下問題:Java MapConfig.setTimeToLiveSeconds方法的具體用法?Java MapConfig.setTimeToLiveSeconds怎麽用?Java MapConfig.setTimeToLiveSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hazelcast.config.MapConfig
的用法示例。
在下文中一共展示了MapConfig.setTimeToLiveSeconds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addMapConfig
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
void addMapConfig(Class<?> c)
{
if(!c.isAnnotationPresent(HzMapConfig.class))
throw new IllegalArgumentException(c+" not annotated with @"+HzMapConfig.class.getSimpleName());
HzMapConfig hc = c.getAnnotation(HzMapConfig.class);
MapConfig mapC = new MapConfig(hc.name());
if(hzConfig.getMapConfigs().containsKey(hc.name()))
{
mapC = hzConfig.getMapConfig(hc.name());
}
mapC.setAsyncBackupCount(hc.asyncBackupCount());
mapC.setBackupCount(hc.backupCount());
mapC.setEvictionPercentage(hc.evictPercentage());
mapC.setEvictionPolicy(EvictionPolicy.valueOf(hc.evictPolicy()));
mapC.setInMemoryFormat(InMemoryFormat.valueOf(hc.inMemoryFormat()));
mapC.setMaxIdleSeconds(hc.idleSeconds());
mapC.setMergePolicy(hc.evictPolicy());
mapC.setMinEvictionCheckMillis(hc.evictCheckMillis());
mapC.setTimeToLiveSeconds(hc.ttlSeconds());
mapC.setMaxSizeConfig(new MaxSizeConfig(hc.maxSize(), MaxSizePolicy.valueOf(hc.maxSizePolicy())));
mapC.setStatisticsEnabled(hc.statisticsOn());
hzConfig.getMapConfigs().put(mapC.getName(), mapC);
}
示例2: createCache
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
public Cache createCache(String name) {
// Check if cluster is being started up
while (state == State.starting) {
// Wait until cluster is fully started (or failed)
try {
Thread.sleep(250);
}
catch (InterruptedException e) {
// Ignore
}
}
if (state == State.stopped) {
throw new IllegalStateException("Cannot create clustered cache when not in a cluster");
}
// Determine the time to live. Note that in Hazelcast 0 means "forever", not -1
final long openfireLifetimeInMilliseconds = CacheFactory.getMaxCacheLifetime(name);
final int hazelcastLifetimeInSeconds = openfireLifetimeInMilliseconds < 0 ? 0 : (int) (openfireLifetimeInMilliseconds / 1000);
// Determine the max cache size. Note that in Hazelcast the max cache size must be positive
final long openfireMaxCacheSize = CacheFactory.getMaxCacheSize(name);
final int hazelcastMaxCacheSize = openfireMaxCacheSize < 0 ? Integer.MAX_VALUE : (int) openfireMaxCacheSize;
final MapConfig mapConfig = hazelcast.getConfig().getMapConfig(name);
mapConfig.setTimeToLiveSeconds(hazelcastLifetimeInSeconds);
mapConfig.setMaxSizeConfig(new MaxSizeConfig(hazelcastMaxCacheSize, MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE));
return new ClusteredCache(name, hazelcast.getMap(name), hazelcastLifetimeInSeconds);
}
示例3: testEvictedEntryNotNullAfterLockAndGet
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
/**
* Test for Issue 710
*/
@Test
public void testEvictedEntryNotNullAfterLockAndGet() throws Exception {
String mapName = "testLock";
Config config = new XmlConfigBuilder().build();
MapConfig mapConfig = new MapConfig();
mapConfig.setName(mapName);
mapConfig.setTimeToLiveSeconds(3);
config.addMapConfig(mapConfig);
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
IMap<Object, Object> m1 = h1.getMap(mapName);
m1.put(1, 1);
assertEquals(1, m1.get(1));
Thread.sleep(5000);
assertEquals(null, m1.get(1));
m1.lock(1);
assertEquals(null, m1.get(1));
m1.put(1, 1);
assertEquals(1, m1.get(1));
}
示例4: ClusterManager
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
public ClusterManager(HazelcastConnection connection,
List<HealthCheck> healthChecks,
HttpConfiguration httpConfiguration) throws Exception {
this.hazelcastConnection = connection;
this.healthChecks = healthChecks;
MapConfig mapConfig = new MapConfig(MAP_NAME);
mapConfig.setTimeToLiveSeconds(MAP_REFRESH_TIME + 2); //Reduce jitter
mapConfig.setBackupCount(1);
mapConfig.setAsyncBackupCount(2);
mapConfig.setEvictionPolicy(EvictionPolicy.NONE);
hazelcastConnection.getHazelcastConfig().getMapConfigs().put(MAP_NAME, mapConfig);
String hostname = Inet4Address.getLocalHost().getCanonicalHostName();
executor = Executors.newScheduledThreadPool(1);
clusterMember = new ClusterMember(hostname, httpConfiguration.getPort());
}
示例5: hazelCastConfig
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
@Bean
public Config hazelCastConfig() {
Config config = new Config();
config.setInstanceName("hazelcast-packt-cache");
config.setProperty("hazelcast.jmx", "true");
MapConfig deptCache = new MapConfig();
deptCache.setTimeToLiveSeconds(20);
deptCache.setEvictionPolicy(EvictionPolicy.LFU);
config.getMapConfigs().put("hazeldept",deptCache);
return config;
}
示例6: init
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
public void init() {
//Specific map time to live
MapConfig myMapConfig = new MapConfig();
myMapConfig.setName("cachetest");
myMapConfig.setTimeToLiveSeconds(10);
//Package config
Config myConfig = new Config();
myConfig.addMapConfig(myMapConfig);
//Symmetric Encryption
SymmetricEncryptionConfig symmetricEncryptionConfig = new SymmetricEncryptionConfig();
symmetricEncryptionConfig.setAlgorithm("DESede");
symmetricEncryptionConfig.setSalt("saltysalt");
symmetricEncryptionConfig.setPassword("lamepassword");
symmetricEncryptionConfig.setIterationCount(1337);
//Weak Network config..
NetworkConfig networkConfig = new NetworkConfig();
networkConfig.setSymmetricEncryptionConfig(symmetricEncryptionConfig);
myConfig.setNetworkConfig(networkConfig);
Hazelcast.init(myConfig);
cacheMap = Hazelcast.getMap("cachetest");
}
示例7: createDeviceCredentialsCacheConfig
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
private MapConfig createDeviceCredentialsCacheConfig() {
MapConfig deviceCredentialsCacheConfig = new MapConfig(CacheConstants.DEVICE_CREDENTIALS_CACHE);
deviceCredentialsCacheConfig.setTimeToLiveSeconds(cacheDeviceCredentialsTTL);
deviceCredentialsCacheConfig.setEvictionPolicy(EvictionPolicy.LRU);
deviceCredentialsCacheConfig.setMaxSizeConfig(
new MaxSizeConfig(
cacheDeviceCredentialsMaxSizeSize,
MaxSizeConfig.MaxSizePolicy.valueOf(cacheDeviceCredentialsMaxSizePolicy))
);
return deviceCredentialsCacheConfig;
}
示例8: getMap
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
private IMap<String, Long> getMap(String key, int longestDuration) {
MapConfig mapConfig = hz.getConfig().getMapConfig(key);
mapConfig.setTimeToLiveSeconds(longestDuration);
mapConfig.setAsyncBackupCount(1);
mapConfig.setBackupCount(0);
return hz.getMap(key);
}
示例9: initializeClusteredSession
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
private MapConfig initializeClusteredSession(JHipsterProperties jHipsterProperties) {
MapConfig mapConfig = new MapConfig();
mapConfig.setBackupCount(jHipsterProperties.getCache().getHazelcast().getBackupCount());
mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getTimeToLiveSeconds());
return mapConfig;
}
示例10: createBucket
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
public void createBucket(String map, int ttl, int backups, int mib)
throws IOException
{
if (bucketCreation.containsKey(map)) {
throw new FileAlreadyExistsException(null, null,
"Bucket already exists: " + map);
}
Map<String, MapConfig> mapConfigs = hazelcast.getConfig()
.getMapConfigs();
MapConfig config = new MapConfig(map);
config.setTimeToLiveSeconds(ttl);
config.setEvictionPolicy(EvictionPolicy.LRU);
config.setInMemoryFormat(InMemoryFormat.BINARY);
config.setBackupCount(backups);
int nodes = hazelcast.getCluster().getMembers().size();
MaxSizeConfig max = new MaxSizeConfig(mib / nodes,
MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE);
config.setMaxSizeConfig(max);
mapConfigs.put(map, config);
// pre-fill local map configuration timestamp...
bucketCreation.putIfAbsent(map, System.currentTimeMillis());
// this should always be the first call to the map...
hazelcast.getMap(map);
}
示例11: cache
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
@Bean
public Map<String, Object> cache() {
Config config = new Config();
MapConfig mapConfig = new MapConfig();
mapConfig.setEvictionPercentage(50);
mapConfig.setEvictionPolicy(EvictionPolicy.LFU);
mapConfig.setTimeToLiveSeconds(300);
Map<String, MapConfig> mapConfigMap = new HashMap<>();
mapConfigMap.put("cache", mapConfig);
config.setMapConfigs(mapConfigMap);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
return instance.getMap("cache");
}
示例12: initializeClusteredSession
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
private MapConfig initializeClusteredSession() {
MapConfig mapConfig = new MapConfig();
mapConfig.setBackupCount(env.getProperty("cache.hazelcast.backupCount", Integer.class, 1));
mapConfig.setTimeToLiveSeconds(env.getProperty("cache.timeToLiveSeconds", Integer.class, 3600));
return mapConfig;
}
示例13: setupConfig
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
public static void setupConfig(HazelcastConnection hazelcastConnection) {
MapConfig mapConfig = hazelcastConnection.getHazelcastConfig().getMapConfig(NAME_PREFIX + "*");
mapConfig.setInMemoryFormat(InMemoryFormat.BINARY);
mapConfig.setTimeToLiveSeconds(10);
mapConfig.setMaxIdleSeconds(10);
mapConfig.setBackupCount(0);
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setTimeToLiveSeconds(10);
nearCacheConfig.setInvalidateOnChange(true);
nearCacheConfig.setMaxIdleSeconds(10);
mapConfig.setNearCacheConfig(nearCacheConfig);
}
示例14: startHazelcastServices
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
private void startHazelcastServices(List<String> registeredServers) throws PEException {
Config cfg = new Config();
cfg.setInstanceName(HAZELCAST_INSTANCE_NAME);
cfg.setProperty("hazelcast.logging.type", "log4j");
GroupConfig group = cfg.getGroupConfig();
group.setName(HAZELCAST_GROUP_NAME);
group.setPassword(HAZELCAST_GROUP_PASSWORD);
NetworkConfig network = cfg.getNetworkConfig();
network.setPortAutoIncrement(false);
network.setPublicAddress(ourClusterAddress.getAddress().getHostAddress());
network.setPort(ourClusterAddress.getPort());
Join join = network.getJoin();
join.getMulticastConfig().setEnabled(false);
for (String serverAddress : registeredServers) {
join.getTcpIpConfig().addMember(serverAddress);
logger.debug("Added member " + serverAddress);
}
join.getTcpIpConfig().setEnabled(true);
MapConfig mc = new MapConfig(GLOBAL_SESS_VAR_MAP_NAME);
mc.setStorageType(StorageType.HEAP);
mc.setTimeToLiveSeconds(0);
mc.setMaxIdleSeconds(0);
MaxSizeConfig msc = new MaxSizeConfig();
msc.setSize(0);
msc.setMaxSizePolicy(MaxSizeConfig.POLICY_CLUSTER_WIDE_MAP_SIZE);
mc.setMaxSizeConfig(msc);
cfg.addMapConfig(mc);
ourHazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
}
示例15: setupMapConfig
import com.hazelcast.config.MapConfig; //導入方法依賴的package包/類
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);
}