use of software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain in project para-cache-hazelcast by Erudika.
the class HazelcastUtils method getClient.
/**
* Initializes a new Hazelcast instance with default settings.
* @return a Hazelcast instance
*/
public static HazelcastInstance getClient() {
if (hcInstance == null) {
hcInstance = Hazelcast.getHazelcastInstanceByName(getNodeName());
if (hcInstance != null) {
return hcInstance;
}
com.hazelcast.config.Config cfg = new com.hazelcast.config.Config();
cfg.setInstanceName(getNodeName());
cfg.setClusterName(Para.getConfig().clusterName());
MapConfig mapcfg = new MapConfig("default");
mapcfg.setEvictionConfig(getEvictionPolicy());
mapcfg.setTimeToLiveSeconds(Para.getConfig().getConfigInt("hc.ttl_seconds", 3600));
mapcfg.setMaxIdleSeconds(mapcfg.getTimeToLiveSeconds() * 2);
// mapcfg.setMapStoreConfig(new MapStoreConfig().setEnabled(false).setClassName(NODE_NAME));
cfg.addMapConfig(mapcfg);
cfg.setProperty("hazelcast.jmx", Boolean.toString(isJMXOn()));
cfg.setProperty("hazelcast.logging.type", "slf4j");
cfg.setProperty("hazelcast.health.monitoring.level", "SILENT");
if (Para.getConfig().inProduction() && Para.getConfig().getConfigBoolean("hc.ec2_discovery_enabled", true)) {
cfg.setProperty("hazelcast.discovery.enabled", "true");
cfg.setProperty("hazelcast.discovery.public.ip.enabled", "true");
Map<String, Comparable> awsConfig = new HashMap<>();
awsConfig.put("access-key", Para.getConfig().getConfigParam("aws_access_key", System.getenv("AWS_ACCESS_KEY_ID")));
awsConfig.put("secret-key", Para.getConfig().getConfigParam("aws_secret_key", System.getenv("AWS_SECRET_ACCESS_KEY")));
awsConfig.put("region", new DefaultAwsRegionProviderChain().getRegion().id());
awsConfig.put("host-header", "ec2.amazonaws.com");
awsConfig.put("security-group-name", Para.getConfig().getConfigParam("hc.discovery_group", "hazelcast"));
DiscoveryConfig ec2DiscoveryConfig = new DiscoveryConfig();
ec2DiscoveryConfig.addDiscoveryStrategyConfig(new DiscoveryStrategyConfig("com.hazelcast.aws.AwsDiscoveryStrategy", awsConfig));
cfg.setNetworkConfig(new NetworkConfig().setJoin(new JoinConfig().setMulticastConfig(new MulticastConfig().setEnabled(false)).setTcpIpConfig(new TcpIpConfig().setEnabled(false)).setAwsConfig(new AwsConfig().setEnabled(false)).setDiscoveryConfig(ec2DiscoveryConfig)));
}
hcInstance = Hazelcast.newHazelcastInstance(cfg);
Para.addDestroyListener(new DestroyListener() {
public void onDestroy() {
shutdownClient();
}
});
}
return hcInstance;
}
Aggregations