Commit 6386ed61 authored by Matija Obreza's avatar Matija Obreza
Browse files

Hazelcast settings moved to #configureHazelcast(cfg)

Included missing HazelcastConfigCacher class
parent 0585666d
......@@ -34,6 +34,7 @@ public class ElasticsearchConfigAWS {
@Bean
public TransportClientFactoryBean tcfb() {
System.out.println("Setting up external ES cluster.name=" + clusterName + " and nodes=" + clusterNodes);
TransportClientFactoryBean tcfb = new TransportClientFactoryBean();
tcfb.setClusterName(clusterName);
tcfb.setClusterNodes(clusterNodes);
......
......@@ -16,29 +16,35 @@
package org.genesys2.spring.config;
import org.genesys2.spring.hazelcast.HazelcastCacheRegionFactoryWrapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.ExecutorConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MaxSizeConfig;
import com.hazelcast.config.MaxSizeConfig.MaxSizePolicy;
import com.hazelcast.config.QueueConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ILock;
import com.hazelcast.core.ManagedContext;
import com.hazelcast.hibernate.HazelcastCacheRegionFactory;
import com.hazelcast.spring.context.SpringManagedContext;
import org.genesys2.spring.hazelcast.HazelcastCacheRegionFactoryWrapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@EnableCaching
@Import({ HazelcastConfigDev.class, HazelcastConfigAWS.class })
@Import({ HazelcastConfigDev.class, HazelcastConfigAWS.class, HazelcastConfigCacher.class })
public abstract class HazelcastConfig {
/// Interfaces on which HZ should bind
@Value("${hazelcast.interfaces}")
protected String hazelInterfaces;
/// TCP port to listen on
@Value("${hazelcast.port}")
protected int hazelPort;
......@@ -46,7 +52,7 @@ public abstract class HazelcastConfig {
/// The public address (in case of NAT)
@Value("${hazelcast.publicAddress}")
protected String hazelPublicAddress;
@Value("${hazelcast.instanceName}")
protected String instanceName;
@Value("${hazelcast.password}")
......@@ -56,6 +62,10 @@ public abstract class HazelcastConfig {
@Value("${cache.defaultCacheSize}")
protected int defaultCacheSize;
@Value("${cache.time-to-live-seconds}")
private int defaultTimeToLiveSeconds;
@Value("${cache.max-idle-seconds}")
private int defaultMaxIdleSeconds;
@Value("${cache.tileserver.max-size}")
protected int tileserverMaxSize;
......@@ -83,10 +93,10 @@ public abstract class HazelcastConfig {
return lock;
}
/**
* Loads an instance and sets the static field
* @param hazelcastCacheRegionFactory
*
* @param hazelcastCacheRegionFactory
*
* @return
*/
......@@ -109,4 +119,57 @@ public abstract class HazelcastConfig {
System.err.println("HazelcastCacheRegionFactory");
return new HazelcastCacheRegionFactory(instance);
}
protected void configureHazelcast(Config cfg) {
MapConfig defaultMapConfig = new MapConfig();
defaultMapConfig.setName("default");
defaultMapConfig.setTimeToLiveSeconds(defaultTimeToLiveSeconds);
defaultMapConfig.setMaxIdleSeconds(defaultMaxIdleSeconds);
defaultMapConfig.setEvictionPolicy(EvictionPolicy.LFU);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(defaultCacheSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
defaultMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(defaultMapConfig);
MapConfig tileserverMapConfig = new MapConfig();
tileserverMapConfig.setName("tileserver");
tileserverMapConfig.setTimeToLiveSeconds(tileserverTTL);
tileserverMapConfig.setEvictionPolicy(tileserverEvictionPolicy);
tileserverMapConfig.setMaxIdleSeconds(tileserverMaxIdle);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(tileserverMaxSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
tileserverMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(tileserverMapConfig);
MapConfig jettySessionsMapConfig = new MapConfig();
jettySessionsMapConfig.setName("jetty-sessions");
jettySessionsMapConfig.setTimeToLiveSeconds(60 * 60 * 24); // 1 day
jettySessionsMapConfig.setEvictionPolicy(tileserverEvictionPolicy);
jettySessionsMapConfig.setMaxIdleSeconds(tileserverMaxIdle);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(tileserverMaxSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
jettySessionsMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(jettySessionsMapConfig);
ExecutorConfig execConfig = new ExecutorConfig();
execConfig.setName("hazel-exec");
execConfig.setPoolSize(4);
execConfig.setQueueCapacity(2);
execConfig.setStatisticsEnabled(true);
cfg.addExecutorConfig(execConfig);
QueueConfig queueConfig = new QueueConfig();
queueConfig.setName("elasticsearchQueue");
queueConfig.setMaxSize(100);
cfg.addQueueConfig(queueConfig);
}
}
......@@ -16,27 +16,21 @@
package org.genesys2.spring.config;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import com.hazelcast.config.AwsConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.ExecutorConfig;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MaxSizeConfig;
import com.hazelcast.config.MaxSizeConfig.MaxSizePolicy;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.QueueConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ManagedContext;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile("aws")
public class HazelcastConfigAWS extends HazelcastConfig {
......@@ -48,10 +42,6 @@ public class HazelcastConfigAWS extends HazelcastConfig {
private String secretKey;
@Value("${hazelcast.aws.security-group}")
private String securityGroupName;
@Value("${cache.time-to-live-seconds}")
private int defaultTimeToLiveSeconds;
@Value("${cache.max-idle-seconds}")
private int defaultMaxIdleSeconds;
@Bean
public HazelcastInstance hazelcast(ManagedContext managedContext) {
......@@ -95,56 +85,7 @@ public class HazelcastConfigAWS extends HazelcastConfig {
awsConfig.setConnectionTimeoutSeconds(20);
awsConfig.setSecurityGroupName(securityGroupName);
MapConfig defaultMapConfig = new MapConfig();
defaultMapConfig.setName("default");
defaultMapConfig.setTimeToLiveSeconds(defaultTimeToLiveSeconds);
defaultMapConfig.setMaxIdleSeconds(defaultMaxIdleSeconds);
defaultMapConfig.setEvictionPolicy(EvictionPolicy.LFU);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(defaultCacheSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
defaultMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(defaultMapConfig);
MapConfig tileserverMapConfig = new MapConfig();
tileserverMapConfig.setName("tileserver");
tileserverMapConfig.setTimeToLiveSeconds(tileserverTTL);
tileserverMapConfig.setEvictionPolicy(tileserverEvictionPolicy);
tileserverMapConfig.setMaxIdleSeconds(tileserverMaxIdle);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(tileserverMaxSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
tileserverMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(tileserverMapConfig);
MapConfig jettySessionsMapConfig = new MapConfig();
jettySessionsMapConfig.setName("jetty-sessions");
jettySessionsMapConfig.setTimeToLiveSeconds(60*60*24); // 1 day
jettySessionsMapConfig.setEvictionPolicy(tileserverEvictionPolicy);
jettySessionsMapConfig.setMaxIdleSeconds(tileserverMaxIdle);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(tileserverMaxSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
jettySessionsMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(jettySessionsMapConfig);
ExecutorConfig execConfig = new ExecutorConfig();
execConfig.setName("hazel-exec");
execConfig.setPoolSize(4);
execConfig.setQueueCapacity(2);
execConfig.setStatisticsEnabled(true);
cfg.addExecutorConfig(execConfig);
QueueConfig queueConfig = new QueueConfig();
queueConfig.setName("elasticsearchQueue");
queueConfig.setMaxSize(100);
cfg.addQueueConfig(queueConfig);
configureHazelcast(cfg);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
return instance;
......
......@@ -16,25 +16,19 @@
package org.genesys2.spring.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.ExecutorConfig;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MaxSizeConfig;
import com.hazelcast.config.MaxSizeConfig.MaxSizePolicy;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.QueueConfig;
import com.hazelcast.config.TcpIpConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ManagedContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile({ "cacher" })
public class HazelcastConfigCacher extends HazelcastConfig {
......@@ -66,39 +60,7 @@ public class HazelcastConfigCacher extends HazelcastConfig {
// See if there's a local HZ running
tcpIpConfig.addMember("127.0.0.1:5702");
MapConfig defaultMapConfig = new MapConfig();
defaultMapConfig.setName("default");
// defaultMapConfig.setTimeToLiveSeconds(0);
defaultMapConfig.setEvictionPolicy(EvictionPolicy.LFU);
// defaultMapConfig.setMaxIdleSeconds();
MaxSizeConfig defaultMaxSizeConfig = new MaxSizeConfig();
defaultMaxSizeConfig.setSize(defaultCacheSize);
defaultMaxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
defaultMapConfig.setMaxSizeConfig(defaultMaxSizeConfig);
cfg.addMapConfig(defaultMapConfig);
MapConfig tileserverMapConfig = new MapConfig();
tileserverMapConfig.setName("tileserver");
tileserverMapConfig.setTimeToLiveSeconds(tileserverTTL);
tileserverMapConfig.setEvictionPolicy(tileserverEvictionPolicy);
tileserverMapConfig.setMaxIdleSeconds(tileserverMaxIdle);
MaxSizeConfig tileserverMaxSizeConfig = new MaxSizeConfig();
tileserverMaxSizeConfig.setSize(tileserverMaxSize);
tileserverMaxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
tileserverMapConfig.setMaxSizeConfig(tileserverMaxSizeConfig);
cfg.addMapConfig(tileserverMapConfig);
ExecutorConfig execConfig = new ExecutorConfig();
execConfig.setName("hazel-exec");
execConfig.setPoolSize(4);
execConfig.setQueueCapacity(2);
execConfig.setStatisticsEnabled(true);
cfg.addExecutorConfig(execConfig);
QueueConfig queueConfig = new QueueConfig();
queueConfig.setName("elasticsearchQueue");
queueConfig.setMaxSize(100);
cfg.addQueueConfig(queueConfig);
configureHazelcast(cfg);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
return instance;
......
......@@ -16,26 +16,20 @@
package org.genesys2.spring.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.ExecutorConfig;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.MaxSizeConfig;
import com.hazelcast.config.MaxSizeConfig.MaxSizePolicy;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.QueueConfig;
import com.hazelcast.config.TcpIpConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ManagedContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile({ "dev" })
public class HazelcastConfigDev extends HazelcastConfig {
......@@ -67,56 +61,7 @@ public class HazelcastConfigDev extends HazelcastConfig {
tcpIpConfig.setEnabled(false);
tcpIpConfig.setConnectionTimeoutSeconds(20);
MapConfig defaultMapConfig = new MapConfig();
defaultMapConfig.setName("default");
defaultMapConfig.setTimeToLiveSeconds(defaultTimeToLiveSeconds);
defaultMapConfig.setMaxIdleSeconds(defaultMaxIdleSeconds);
defaultMapConfig.setEvictionPolicy(EvictionPolicy.LFU);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(defaultCacheSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
defaultMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(defaultMapConfig);
MapConfig tileserverMapConfig = new MapConfig();
tileserverMapConfig.setName("tileserver");
tileserverMapConfig.setTimeToLiveSeconds(tileserverTTL);
tileserverMapConfig.setEvictionPolicy(tileserverEvictionPolicy);
tileserverMapConfig.setMaxIdleSeconds(tileserverMaxIdle);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(tileserverMaxSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
tileserverMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(tileserverMapConfig);
MapConfig jettySessionsMapConfig = new MapConfig();
jettySessionsMapConfig.setName("jetty-sessions");
jettySessionsMapConfig.setTimeToLiveSeconds(30);
jettySessionsMapConfig.setEvictionPolicy(tileserverEvictionPolicy);
jettySessionsMapConfig.setMaxIdleSeconds(tileserverMaxIdle);
{
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(tileserverMaxSize);
maxSizeConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
jettySessionsMapConfig.setMaxSizeConfig(maxSizeConfig);
}
cfg.addMapConfig(jettySessionsMapConfig);
ExecutorConfig execConfig = new ExecutorConfig();
execConfig.setName("hazel-exec");
execConfig.setPoolSize(4);
execConfig.setQueueCapacity(2);
execConfig.setStatisticsEnabled(true);
cfg.addExecutorConfig(execConfig);
QueueConfig queueConfig = new QueueConfig();
queueConfig.setName("elasticsearchQueue");
queueConfig.setMaxSize(100);
cfg.addQueueConfig(queueConfig);
configureHazelcast(cfg);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
return instance;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment