use of com.hazelcast.core.HazelcastInstance in project camel by apache.
the class HazelcastComponent method doStop.
@Override
public void doStop() throws Exception {
for (HazelcastInstance hazelcastInstance : customHazelcastInstances) {
hazelcastInstance.getLifecycleService().shutdown();
}
customHazelcastInstances.clear();
super.doStop();
}
use of com.hazelcast.core.HazelcastInstance in project camel by apache.
the class HazelcastComponent method getOrCreateHzInstance.
private HazelcastInstance getOrCreateHzInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
HazelcastInstance hzInstance = null;
Config 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, Config.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 XmlConfigBuilder(is).build();
}
}
if (hazelcastInstance == null && config == null) {
config = new XmlConfigBuilder().build();
// Disable the version check
config.getProperties().setProperty("hazelcast.version.check.enabled", "false");
config.getProperties().setProperty("hazelcast.phone.home.enabled", "false");
hzInstance = Hazelcast.newHazelcastInstance(config);
} else if (config != null) {
if (ObjectHelper.isNotEmpty(config.getInstanceName())) {
hzInstance = Hazelcast.getOrCreateHazelcastInstance(config);
} else {
hzInstance = Hazelcast.newHazelcastInstance(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.core.HazelcastInstance 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.core.HazelcastInstance in project camel by apache.
the class HazelcastConfigurationTest method testNamedInstanceWithConfigurationUri.
@Test
public void testNamedInstanceWithConfigurationUri() throws Exception {
DefaultCamelContext context = null;
try {
context = new DefaultCamelContext();
context.start();
HazelcastDefaultEndpoint endpoint1 = getHzEndpoint(context, "hazelcast:map:my-cache-1?hazelcastConfigUri=classpath:hazelcast-named.xml");
HazelcastDefaultEndpoint endpoint2 = getHzEndpoint(context, "hazelcast:map:my-cache-2?hazelcastConfigUri=classpath:hazelcast-named.xml");
Assert.assertNotNull(endpoint1.getHazelcastInstance());
Assert.assertNotNull(endpoint2.getHazelcastInstance());
Assert.assertTrue(endpoint1.getHazelcastInstance() == endpoint2.getHazelcastInstance());
HazelcastComponent component = context.getComponent("hazelcast", HazelcastComponent.class);
Assert.assertNull(component.getHazelcastInstance());
HazelcastInstance hz = endpoint1.getHazelcastInstance();
Assert.assertFalse(hz.getConfig().getNetworkConfig().getJoin().getAwsConfig().isEnabled());
Assert.assertFalse(hz.getConfig().getNetworkConfig().getJoin().getMulticastConfig().isEnabled());
Assert.assertFalse(hz.getConfig().getNetworkConfig().getJoin().getTcpIpConfig().isEnabled());
Assert.assertEquals(9876, hz.getConfig().getNetworkConfig().getPort());
} finally {
if (context != null) {
context.stop();
}
}
}
use of com.hazelcast.core.HazelcastInstance in project camel by apache.
the class HazelcastConfigurationTest method testDefaultConfiguration.
@Test
public void testDefaultConfiguration() throws Exception {
DefaultCamelContext context = null;
try {
context = new DefaultCamelContext();
context.start();
HazelcastDefaultEndpoint endpoint1 = getHzEndpoint(context, "hazelcast:map:my-cache-1");
HazelcastDefaultEndpoint endpoint2 = getHzEndpoint(context, "hazelcast:map:my-cache-2");
Assert.assertNotNull(endpoint1.getHazelcastInstance());
Assert.assertNotNull(endpoint2.getHazelcastInstance());
Assert.assertTrue(endpoint1.getHazelcastInstance() != endpoint2.getHazelcastInstance());
HazelcastComponent component = context.getComponent("hazelcast", HazelcastComponent.class);
Assert.assertNull(component.getHazelcastInstance());
for (HazelcastDefaultEndpoint endpoint : Arrays.asList(endpoint1, endpoint2)) {
HazelcastInstance hz = endpoint.getHazelcastInstance();
Assert.assertFalse(hz.getConfig().getNetworkConfig().getJoin().getAwsConfig().isEnabled());
Assert.assertFalse(hz.getConfig().getNetworkConfig().getJoin().getMulticastConfig().isEnabled());
Assert.assertTrue(hz.getConfig().getNetworkConfig().getJoin().getTcpIpConfig().isEnabled());
Assert.assertEquals(5701, hz.getConfig().getNetworkConfig().getPort());
}
} finally {
if (context != null) {
context.stop();
}
}
}
Aggregations