use of com.hazelcast.core.Hazelcast in project hazelcast by hazelcast.
the class TestBeansApplicationContext method testApplicationContext.
@Test
public void testApplicationContext() {
assertTrue(HazelcastClient.getAllHazelcastClients().isEmpty());
context.getBean("map2");
assertEquals(1, Hazelcast.getAllHazelcastInstances().size());
assertEquals(1, HazelcastClient.getAllHazelcastClients().size());
HazelcastInstance hazelcast = Hazelcast.getAllHazelcastInstances().iterator().next();
long distributedObjectsSize = hazelcast.getDistributedObjects().stream().filter(distributedObject -> !distributedObject.getName().startsWith(INTERNAL_JET_OBJECTS_PREFIX)).count();
assertEquals(2, distributedObjectsSize);
context.getBean("client");
context.getBean("client");
assertEquals(3, HazelcastClient.getAllHazelcastClients().size());
HazelcastClientProxy client = (HazelcastClientProxy) HazelcastClient.getAllHazelcastClients().iterator().next();
assertNull(client.getClientConfig().getManagedContext());
int batchSize = client.getClientConfig().getQueryCacheConfigs().get("").get("cache1").getBatchSize();
assertEquals(12, batchSize);
assertFalse(client.getClientConfig().getMetricsConfig().isEnabled());
HazelcastInstance instance = (HazelcastInstance) context.getBean("instance");
assertEquals(1, Hazelcast.getAllHazelcastInstances().size());
assertEquals(instance, Hazelcast.getAllHazelcastInstances().iterator().next());
assertNull(instance.getConfig().getManagedContext());
}
use of com.hazelcast.core.Hazelcast in project hazelcast by hazelcast.
the class HazelcastStarter method createInstanceViaHazelcast.
@SuppressWarnings("unchecked")
private static Object createInstanceViaHazelcast(HazelcastAPIDelegatingClassloader classloader, Config configTemplate) {
try {
Class<?> configClass = classloader.loadClass("com.hazelcast.config.Config");
Object config = getConfig(classloader, configClass, configTemplate);
Class<Hazelcast> hazelcastClass = (Class<Hazelcast>) classloader.loadClass("com.hazelcast.core.Hazelcast");
System.out.println(hazelcastClass + " loaded by " + hazelcastClass.getClassLoader());
Method newHazelcastInstanceMethod = hazelcastClass.getMethod("newHazelcastInstance", configClass);
return newHazelcastInstanceMethod.invoke(null, config);
} catch (ClassNotFoundException e) {
throw rethrowGuardianException(e);
} catch (NoSuchMethodException e) {
throw rethrowGuardianException(e);
} catch (IllegalAccessException e) {
throw rethrowGuardianException(e);
} catch (InvocationTargetException e) {
throw rethrowGuardianException(e);
} catch (InstantiationException e) {
throw rethrowGuardianException(e);
}
}
use of com.hazelcast.core.Hazelcast in project jnosql-diana-driver by eclipse.
the class HazelcastKeyValueConfiguration method get.
/**
* Creates a {@link HazelcastBucketManagerFactory} from configuration map
* @param configurations the configuration map
* @return the HazelCastBucketManagerFactory instance
* @throws NullPointerException when configurations is null
*/
public HazelcastBucketManagerFactory get(Map<String, String> configurations) throws NullPointerException {
List<String> servers = configurations.keySet().stream().filter(s -> s.startsWith("hazelcast-hoster-")).collect(Collectors.toList());
Config config = new Config(configurations.getOrDefault("hazelcast-instanceName", "hazelcast-instanceName"));
HazelcastInstance hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(config);
return new DefaultHazelcastBucketManagerFactory(hazelcastInstance);
}
use of com.hazelcast.core.Hazelcast in project sonarqube by SonarSource.
the class HazelcastMemberBuilder method build.
public HazelcastMember build() {
Config config = new Config();
// do not use the value defined by property sonar.cluster.name.
// Hazelcast does not fail when joining a cluster with different name.
// Apparently this behavior exists since Hazelcast 3.8.2 (see note
// at http://docs.hazelcast.org/docs/3.8.6/manual/html-single/index.html#creating-cluster-groups)
config.setClusterName("SonarQube");
// Configure network
NetworkConfig netConfig = config.getNetworkConfig();
netConfig.setPort(port).setPortAutoIncrement(false).setReuseAddress(true);
netConfig.getInterfaces().setEnabled(true).setInterfaces(singletonList(requireNonNull(networkInterface, "Network interface is missing")));
JoinConfig joinConfig = netConfig.getJoin();
joinConfig.getAwsConfig().setEnabled(false);
joinConfig.getMulticastConfig().setEnabled(false);
if (KUBERNETES.equals(type)) {
joinConfig.getKubernetesConfig().setEnabled(true).setProperty("service-dns", requireNonNull(members, "Service DNS is missing")).setProperty("service-port", CLUSTER_NODE_HZ_PORT.getDefaultValue());
} else {
List<String> addressesWithDefaultPorts = Stream.of(this.members.split(",")).filter(host -> !host.isBlank()).map(String::trim).map(HazelcastMemberBuilder::applyDefaultPortToHost).collect(Collectors.toList());
joinConfig.getTcpIpConfig().setEnabled(true);
joinConfig.getTcpIpConfig().setMembers(requireNonNull(addressesWithDefaultPorts, "Members are missing"));
}
// We are not using the partition group of Hazelcast, so disabling it
config.getPartitionGroupConfig().setEnabled(false);
// Tweak HazelCast configuration
config.setProperty("hazelcast.tcp.join.port.try.count", "10").setProperty("hazelcast.socket.bind.any", "false").setProperty("hazelcast.phone.home.enabled", "false").setProperty("hazelcast.logging.type", "slf4j");
MemberAttributeConfig attributes = config.getMemberAttributeConfig();
attributes.setAttribute(Attribute.NODE_NAME.getKey(), requireNonNull(nodeName, "Node name is missing"));
attributes.setAttribute(Attribute.PROCESS_KEY.getKey(), requireNonNull(processId, "Process key is missing").getKey());
return new HazelcastMemberImpl(Hazelcast.newHazelcastInstance(config));
}
Aggregations