use of com.hazelcast.client.config.XmlClientConfigBuilder in project camel by apache.
the class HazelcastComponent method getOrCreateHzClientInstance.
private HazelcastInstance getOrCreateHzClientInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
HazelcastInstance hzInstance = null;
ClientConfig config = null;
// Query param named 'hazelcastInstance' (if exists) overrides the instance that was set
hzInstance = resolveAndRemoveReferenceParameter(parameters, HAZELCAST_INSTANCE_PARAM, HazelcastInstance.class);
// Check if an already created instance is given then just get instance by its name.
if (hzInstance == null && parameters.get(HAZELCAST_INSTANCE_NAME_PARAM) != null) {
hzInstance = Hazelcast.getHazelcastInstanceByName((String) parameters.get(HAZELCAST_INSTANCE_NAME_PARAM));
}
// as reference or as xml configuration file.
if (hzInstance == null) {
config = resolveAndRemoveReferenceParameter(parameters, HAZELCAST_CONFIGU_PARAM, ClientConfig.class);
if (config == null) {
String configUri = getAndRemoveParameter(parameters, HAZELCAST_CONFIGU_URI_PARAM, String.class);
if (configUri != null) {
configUri = getCamelContext().resolvePropertyPlaceholders(configUri);
}
if (configUri != null) {
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, configUri);
config = new XmlClientConfigBuilder(is).build();
}
}
if (hazelcastInstance == null && config == null) {
config = new XmlClientConfigBuilder().build();
// Disable the version check
config.getProperties().setProperty("hazelcast.version.check.enabled", "false");
config.getProperties().setProperty("hazelcast.phone.home.enabled", "false");
hzInstance = HazelcastClient.newHazelcastClient(config);
} else if (config != null) {
hzInstance = HazelcastClient.newHazelcastClient(config);
}
if (hzInstance != null) {
if (this.customHazelcastInstances.add(hzInstance)) {
LOGGER.debug("Add managed HZ instance {}", hzInstance.getName());
}
}
}
return hzInstance == null ? hazelcastInstance : hzInstance;
}
use of com.hazelcast.client.config.XmlClientConfigBuilder in project hazelcast by hazelcast.
the class ClientConsoleApp method main.
/**
* Starts the test application. Loads the config from classpath hazelcast.xml,
* if it fails to load, will use default config.
*
* @param args none
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ClientConfig clientConfig;
try {
clientConfig = new XmlClientConfigBuilder().build();
} catch (IllegalArgumentException e) {
clientConfig = new ClientConfig();
}
final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
ClientConsoleApp clientConsoleApp = new ClientConsoleApp(client);
clientConsoleApp.start(args);
}
use of com.hazelcast.client.config.XmlClientConfigBuilder in project hazelcast by hazelcast.
the class ClientCachingProviderTest method setup.
@Before
public void setup() {
// start a member
Config config = new Config();
config.getGroupConfig().setName("test-group1");
config.getGroupConfig().setPassword("test-pass1");
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
instances.add(instance);
// start two client instances
instance1 = createHazelcastInstance(INSTANCE_1_NAME);
instance2 = createHazelcastInstance(INSTANCE_2_NAME);
try {
instance3 = HazelcastClient.newHazelcastClient(new XmlClientConfigBuilder(CONFIG_CLASSPATH_LOCATION).build());
} catch (IOException e) {
throw new AssertionError("Could not construct named hazelcast client instance: " + e.getMessage());
}
instances.add(instance1);
instances.add(instance2);
instances.add(instance3);
cachingProvider = createCachingProvider(instance1);
}
use of com.hazelcast.client.config.XmlClientConfigBuilder in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testNodeFilter_from_xml.
@Test
public void testNodeFilter_from_xml() throws Exception {
String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
discoveryService.start();
discoveryService.discoverNodes();
discoveryService.destroy();
Field nodeFilterField = DefaultDiscoveryService.class.getDeclaredField("nodeFilter");
nodeFilterField.setAccessible(true);
TestNodeFilter nodeFilter = (TestNodeFilter) nodeFilterField.get(discoveryService);
assertEquals(4, nodeFilter.getNodes().size());
}
use of com.hazelcast.client.config.XmlClientConfigBuilder in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method test_discovery_address_translator_with_public_ip.
@Test
public void test_discovery_address_translator_with_public_ip() throws Exception {
String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
AddressTranslator translator = new DiscoveryAddressTranslator(discoveryService, true);
Address publicAddress = new Address("127.0.0.1", 50001);
Address privateAddress = new Address("127.0.0.1", 1);
// Enforce refresh of the internal mapping
assertEquals(publicAddress, translator.translate(privateAddress));
}
Aggregations