use of com.hazelcast.config.XmlConfigBuilder in project cas by apereo.
the class HazelcastTicketRegistryConfiguration method getConfig.
private Config getConfig(final TicketCatalog ticketCatalog) {
final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
final HazelcastProperties.Cluster cluster = hz.getCluster();
final Config config;
if (hz.getConfigLocation() != null && hz.getConfigLocation().exists()) {
try {
final URL configUrl = hz.getConfigLocation().getURL();
LOGGER.debug("Loading Hazelcast configuration from [{}]", configUrl);
config = new XmlConfigBuilder(hz.getConfigLocation().getInputStream()).build();
config.setConfigurationUrl(configUrl);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
} else {
// No config location, so do a default config programmatically with handful of properties exposed by CAS
config = new Config();
config.setProperty("hazelcast.prefer.ipv4.stack", String.valueOf(cluster.isIpv4Enabled()));
// TCP config
final TcpIpConfig tcpIpConfig = new TcpIpConfig().setEnabled(cluster.isTcpipEnabled()).setMembers(cluster.getMembers()).setConnectionTimeoutSeconds(cluster.getTimeout());
LOGGER.debug("Created Hazelcast TCP/IP configuration [{}]", tcpIpConfig);
// Multicast config
final MulticastConfig multicastConfig = new MulticastConfig().setEnabled(cluster.isMulticastEnabled());
if (cluster.isMulticastEnabled()) {
multicastConfig.setMulticastGroup(cluster.getMulticastGroup());
multicastConfig.setMulticastPort(cluster.getMulticastPort());
final Set<String> trustedInterfaces = StringUtils.commaDelimitedListToSet(cluster.getMulticastTrustedInterfaces());
if (!trustedInterfaces.isEmpty()) {
multicastConfig.setTrustedInterfaces(trustedInterfaces);
}
multicastConfig.setMulticastTimeoutSeconds(cluster.getMulticastTimeout());
multicastConfig.setMulticastTimeToLive(cluster.getMulticastTimeToLive());
}
LOGGER.debug("Created Hazelcast Multicast configuration [{}]", multicastConfig);
// Join config
final JoinConfig joinConfig = new JoinConfig().setMulticastConfig(multicastConfig).setTcpIpConfig(tcpIpConfig);
LOGGER.debug("Created Hazelcast join configuration [{}]", joinConfig);
// Network config
final NetworkConfig networkConfig = new NetworkConfig().setPort(cluster.getPort()).setPortAutoIncrement(cluster.isPortAutoIncrement()).setJoin(joinConfig);
LOGGER.debug("Created Hazelcast network configuration [{}]", networkConfig);
// Finally aggregate all those config into the main Config
config.setMapConfigs(buildHazelcastMapConfigurations(ticketCatalog)).setNetworkConfig(networkConfig);
}
// Add additional default config properties regardless of the configuration source
return config.setInstanceName(cluster.getInstanceName()).setProperty(HazelcastProperties.LOGGING_TYPE_PROP, cluster.getLoggingType()).setProperty(HazelcastProperties.MAX_HEARTBEAT_SECONDS_PROP, String.valueOf(cluster.getMaxNoHeartbeatSeconds()));
}
use of com.hazelcast.config.XmlConfigBuilder in project cas by apereo.
the class HazelcastSessionConfiguration method hazelcastInstance.
/**
* Hazelcast instance that is used by the spring session
* repository to broadcast session events. The name
* of this bean must be left untouched.
*
* @return the hazelcast instance
*/
@Bean
public HazelcastInstance hazelcastInstance() {
final Resource hzConfigResource = casProperties.getWebflow().getSession().getHzLocation();
try {
final URL configUrl = hzConfigResource.getURL();
final Config config = new XmlConfigBuilder(hzConfigResource.getInputStream()).build();
config.setConfigurationUrl(configUrl);
config.setInstanceName(this.getClass().getSimpleName()).setProperty("hazelcast.logging.type", "slf4j").setProperty("hazelcast.max.no.heartbeat.seconds", "300");
return Hazelcast.newHazelcastInstance(config);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class DiscoverySpiTest method testParsing.
@Test
public void testParsing() throws Exception {
String xmlFileName = "test-hazelcast-discovery-spi.xml";
InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Config config = new XmlConfigBuilder(xmlResource).build();
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
AwsConfig awsConfig = joinConfig.getAwsConfig();
assertFalse(awsConfig.isEnabled());
TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
assertFalse(tcpIpConfig.isEnabled());
MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
assertFalse(multicastConfig.isEnabled());
DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
assertTrue(discoveryConfig.isEnabled());
assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size());
DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
assertEquals(3, providerConfig.getProperties().size());
assertEquals("foo", providerConfig.getProperties().get("key-string"));
assertEquals("123", providerConfig.getProperties().get("key-int"));
assertEquals("true", providerConfig.getProperties().get("key-boolean"));
}
use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class DiscoverySpiTest method getDiscoverySPIConfig.
private static Config getDiscoverySPIConfig(String xmlFileName) {
InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Config config = new XmlConfigBuilder(xmlResource).build();
config.getNetworkConfig().setPort(50001);
InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
interfaces.clear();
interfaces.setEnabled(true);
interfaces.addInterface("127.0.0.1");
List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
DiscoveryStrategyFactory factory = new CollectingDiscoveryStrategyFactory(discoveryNodes);
DiscoveryConfig discoveryConfig = config.getNetworkConfig().getJoin().getDiscoveryConfig();
discoveryConfig.getDiscoveryStrategyConfigs().clear();
DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
return config;
}
use of com.hazelcast.config.XmlConfigBuilder in project hazelcast by hazelcast.
the class DiscoverySpiTest method test_metadata_discovery_on_node_startup.
@Test
public void test_metadata_discovery_on_node_startup() throws Exception {
String xmlFileName = "test-hazelcast-discovery-spi-metadata.xml";
InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Config config = new XmlConfigBuilder(xmlResource).build();
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(1);
try {
HazelcastInstance hazelcastInstance1 = instanceFactory.newHazelcastInstance(config);
assertNotNull(hazelcastInstance1);
Member localMember = hazelcastInstance1.getCluster().getLocalMember();
assertEquals(Byte.MAX_VALUE, (byte) localMember.getByteAttribute("test-byte"));
assertEquals(Short.MAX_VALUE, (short) localMember.getShortAttribute("test-short"));
assertEquals(Integer.MAX_VALUE, (int) localMember.getIntAttribute("test-int"));
assertEquals(Long.MAX_VALUE, (long) localMember.getLongAttribute("test-long"));
assertEquals(Float.MAX_VALUE, localMember.getFloatAttribute("test-float"), 0);
assertEquals(Double.MAX_VALUE, localMember.getDoubleAttribute("test-double"), 0);
assertTrue(localMember.getBooleanAttribute("test-boolean"));
assertEquals("TEST", localMember.getStringAttribute("test-string"));
} finally {
instanceFactory.shutdownAll();
}
}
Aggregations