use of com.hazelcast.client.config.ClientConfig 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.ClientConfig in project camel by apache.
the class HazelcastRoute method configure.
@Override
public void configure() throws Exception {
HazelcastComponent component = new HazelcastComponent();
ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress("hazelcast");
config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(false));
config.setGroupConfig(new GroupConfig("someGroup", "someSecret"));
HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);
component.setHazelcastInstance(instance);
getContext().addComponent("hazelcast", component);
from("timer:foo?period=5000").log("Producer side: Sending data to Hazelcast topic..").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(HazelcastConstants.OPERATION, HazelcastConstants.PUBLISH_OPERATION);
String payload = "Test " + UUID.randomUUID();
exchange.getIn().setBody(payload);
}
}).to("hazelcast:topic:foo");
from("hazelcast:topic:foo").log("Consumer side: Detected following action: $simple{in.header.CamelHazelcastListenerAction}");
}
use of com.hazelcast.client.config.ClientConfig 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.ClientConfig in project hazelcast by hazelcast.
the class ClientAuthenticationTest method testFailedAuthentication.
@Test(expected = IllegalStateException.class)
public void testFailedAuthentication() throws Exception {
hazelcastFactory.newHazelcastInstance();
final ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptPeriod(1);
clientConfig.getGroupConfig().setPassword("InvalidPassword");
hazelcastFactory.newHazelcastClient(clientConfig);
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientConnectionTest method testWithLegalAndIllegalAddressTogether.
@Test
public void testWithLegalAndIllegalAddressTogether() {
String illegalAddress = randomString();
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
ClientConfig config = new ClientConfig();
config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
config.getNetworkConfig().addAddress(illegalAddress).addAddress("localhost");
HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
Collection<Client> connectedClients = server.getClientService().getConnectedClients();
assertEquals(connectedClients.size(), 1);
Client serverSideClientInfo = connectedClients.iterator().next();
assertEquals(serverSideClientInfo.getUuid(), client.getLocalEndpoint().getUuid());
}
Aggregations