Java Code Examples for com.hazelcast.config.MapConfig#setTimeToLiveSeconds()

The following examples show how to use com.hazelcast.config.MapConfig#setTimeToLiveSeconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DistributedTableMetadataManager.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
private MapConfig tableMapConfig() {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setReadBackupData(true);
    mapConfig.setInMemoryFormat(InMemoryFormat.BINARY);
    mapConfig.setTimeToLiveSeconds(TIME_TO_LIVE_TABLE_CACHE);
    mapConfig.setBackupCount(0);

    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setFactoryImplementation(TableMapStore.factory(elasticsearchConnection));
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapConfig.setMapStoreConfig(mapStoreConfig);

    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setTimeToLiveSeconds(TIME_TO_LIVE_TABLE_CACHE);
    nearCacheConfig.setInvalidateOnChange(true);
    mapConfig.setNearCacheConfig(nearCacheConfig);
    return mapConfig;
}
 
Example 2
Source File: ClusterManager.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
@Inject
public ClusterManager(HazelcastConnection connection, List<HealthCheck> healthChecks, ServerFactory serverFactory) throws IOException {
    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();
    //Auto detect marathon environment and query for host environment variable
    if(!Strings.isNullOrEmpty(System.getenv("HOST")))
        hostname = System.getenv("HOST");
    Preconditions.checkNotNull(hostname, "Could not retrieve hostname, cannot proceed");
    int port = ServerUtils.port(serverFactory);
    //Auto detect marathon environment and query for host environment variable
    if(!Strings.isNullOrEmpty(System.getenv("PORT_" + port)))
        port = Integer.parseInt(System.getenv("PORT_" + port));
    executor = Executors.newScheduledThreadPool(1);
    clusterMember = new ClusterMember(hostname, port);
}
 
Example 3
Source File: CachingConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@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;
}
 
Example 4
Source File: HazelcastSymmetric.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
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");
    }
 
Example 5
Source File: ServiceCacheConfiguration.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: HazelcastSlidingWindowRequestRateLimiter.java    From ratelimitj with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: _CacheConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
private MapConfig initializeClusteredSession(JHipsterProperties jHipsterProperties) {
    MapConfig mapConfig = new MapConfig();

    mapConfig.setBackupCount(jHipsterProperties.getCache().getHazelcast().getBackupCount());
    mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getTimeToLiveSeconds());
    return mapConfig;
}
 
Example 8
Source File: DistributedCacheFactory.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
private MapConfig getDefaultMapConfig(CacheConfig cacheConfig) {
    MapConfig mapConfig = new MapConfig(CACHE_NAME_PREFIX + "*");
    mapConfig.setInMemoryFormat(InMemoryFormat.BINARY);
    mapConfig.setBackupCount(0);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);

    if(cacheConfig.getMaxIdleSeconds() == 0) {
        mapConfig.setMaxIdleSeconds(DEFAULT_MAX_IDLE_SECONDS);
    } else {
        mapConfig.setMaxIdleSeconds(cacheConfig.getMaxIdleSeconds());
    }

    if(cacheConfig.getTimeToLiveSeconds() == 0) {
        mapConfig.setTimeToLiveSeconds(DEFAULT_TIME_TO_LIVE_SECONDS);
    } else {
        mapConfig.setTimeToLiveSeconds(cacheConfig.getTimeToLiveSeconds());
    }

    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.USED_HEAP_PERCENTAGE);
    if(cacheConfig.getSize() == 0) {
        maxSizeConfig.setSize(DEFAULT_SIZE);
    } else {
        maxSizeConfig.setSize(cacheConfig.getSize());
    }
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    return mapConfig;
}
 
Example 9
Source File: DistributedTableMetadataManager.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
private MapConfig fieldMetaMapConfig() {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setReadBackupData(true);
    mapConfig.setInMemoryFormat(InMemoryFormat.BINARY);
    mapConfig.setTimeToLiveSeconds(TIME_TO_LIVE_CACHE);
    mapConfig.setBackupCount(0);

    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setTimeToLiveSeconds(TIME_TO_NEAR_CACHE);
    nearCacheConfig.setInvalidateOnChange(true);
    mapConfig.setNearCacheConfig(nearCacheConfig);

    return mapConfig;
}
 
Example 10
Source File: DistributedTableMetadataManager.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
private MapConfig cardinalityFieldMetaMapConfig() {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setReadBackupData(true);
    mapConfig.setInMemoryFormat(InMemoryFormat.BINARY);
    mapConfig.setTimeToLiveSeconds(TIME_TO_LIVE_CARDINALITY_CACHE);
    mapConfig.setBackupCount(0);

    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setTimeToLiveSeconds(TIME_TO_LIVE_CARDINALITY_CACHE);
    nearCacheConfig.setInvalidateOnChange(true);
    mapConfig.setNearCacheConfig(nearCacheConfig);

    return mapConfig;
}
 
Example 11
Source File: CacheConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
private MapConfig initializeDomainMapConfig(JHipsterProperties jHipsterProperties) {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getHazelcast().getTimeToLiveSeconds());
    return mapConfig;
}
 
Example 12
Source File: CacheConfiguration.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
private MapConfig initializeDomainMapConfig(JHipsterProperties jHipsterProperties) {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getHazelcast().getTimeToLiveSeconds());
    return mapConfig;
}
 
Example 13
Source File: CacheConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
private MapConfig initializeDomainMapConfig(JHipsterProperties jHipsterProperties) {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getHazelcast().getTimeToLiveSeconds());
    return mapConfig;
}
 
Example 14
Source File: CacheConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
private MapConfig initializeDomainMapConfig(JHipsterProperties jHipsterProperties) {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getHazelcast().getTimeToLiveSeconds());
    return mapConfig;
}
 
Example 15
Source File: _CacheConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 4 votes vote down vote up
private MapConfig initializeDomainMapConfig(JHipsterProperties jHipsterProperties) {
    MapConfig mapConfig = new MapConfig();

    mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getTimeToLiveSeconds());
    return mapConfig;
}
 
Example 16
Source File: HazelCastConfigration.java    From sctalk with Apache License 2.0 4 votes vote down vote up
private MapConfig initializeDomainMapConfig(MessageServerConfig serverConfig) {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setTimeToLiveSeconds(serverConfig.getHazelcast().getTimeToLiveSeconds());
    return mapConfig;
}
 
Example 17
Source File: CacheConfiguration.java    From jhipster-microservices-example with Apache License 2.0 4 votes vote down vote up
private MapConfig initializeDomainMapConfig(JHipsterProperties jHipsterProperties) {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setTimeToLiveSeconds(jHipsterProperties.getCache().getHazelcast().getTimeToLiveSeconds());
    return mapConfig;
}