com.hazelcast.client.config.ClientConfig Java Examples
The following examples show how to use
com.hazelcast.client.config.ClientConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HazelcastMemoryService.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Service INIT */ public void init() { String clientServers = serverConfigurationService.getString("memory.hc.server", null); boolean clientConfigured = StringUtils.isNotBlank(clientServers); if (clientConfigured) { ClientConfig clientConfig = new ClientConfig(); ClientNetworkConfig clientNetworkConfig = new ClientNetworkConfig(); clientNetworkConfig.addAddress(StringUtils.split(clientServers, ',')); clientConfig.setNetworkConfig(clientNetworkConfig); hcInstance = HazelcastClient.newHazelcastClient(clientConfig); } else { // start up a local server instead Config localConfig = new Config(); localConfig.setInstanceName(serverConfigurationService.getServerIdInstance()); hcInstance = Hazelcast.newHazelcastInstance(localConfig); } if (hcInstance == null) { throw new IllegalStateException("init(): HazelcastInstance is null!"); } log.info("INIT: " + hcInstance.getName() + " ("+(clientConfigured?"client:"+hcInstance.getClientService():"localServer")+"), cache maps: " + hcInstance.getDistributedObjects()); }
Example #2
Source File: HazelcastMemoryService.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Service INIT */ public void init() { String clientServers = serverConfigurationService.getString("memory.hc.server", null); boolean clientConfigured = StringUtils.isNotBlank(clientServers); if (clientConfigured) { ClientConfig clientConfig = new ClientConfig(); ClientNetworkConfig clientNetworkConfig = new ClientNetworkConfig(); clientNetworkConfig.addAddress(StringUtils.split(clientServers, ',')); clientConfig.setNetworkConfig(clientNetworkConfig); hcInstance = HazelcastClient.newHazelcastClient(clientConfig); } else { // start up a local server instead Config localConfig = new Config(); localConfig.setInstanceName(serverConfigurationService.getServerIdInstance()); hcInstance = Hazelcast.newHazelcastInstance(localConfig); } if (hcInstance == null) { throw new IllegalStateException("init(): HazelcastInstance is null!"); } log.info("INIT: " + hcInstance.getName() + " ("+(clientConfigured?"client:"+hcInstance.getClientService():"localServer")+"), cache maps: " + hcInstance.getDistributedObjects()); }
Example #3
Source File: TestCustomerSerializers.java From subzero with Apache License 2.0 | 6 votes |
@Test public void testGlobalCustomDelegateSerializationConfiguredProgrammaticallyForClientConfig() { Config memberConfig = new Config(); SubZero.useAsGlobalSerializer(memberConfig); hazelcastFactory.newHazelcastInstance(memberConfig); String mapName = randomMapName(); ClientConfig config = new ClientConfig(); SubZero.useAsGlobalSerializer(config, MyGlobalDelegateSerlizationConfig.class); HazelcastInstance member = hazelcastFactory.newHazelcastClient(config); IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName); myMap.put(0, new AnotherNonSerializableObject()); AnotherNonSerializableObject fromCache = myMap.get(0); assertEquals("deserialized", fromCache.name); }
Example #4
Source File: TestCustomerSerializers.java From subzero with Apache License 2.0 | 6 votes |
@Test public void testGlobalCustomSerializationConfiguredProgrammaticallyForClientConfig() { Config memberConfig = new Config(); SubZero.useAsGlobalSerializer(memberConfig); hazelcastFactory.newHazelcastInstance(memberConfig); String mapName = randomMapName(); ClientConfig config = new ClientConfig(); SubZero.useAsGlobalSerializer(config, MyGlobalUserSerlizationConfig.class); HazelcastInstance member = hazelcastFactory.newHazelcastClient(config); IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName); myMap.put(0, new AnotherNonSerializableObject()); AnotherNonSerializableObject fromCache = myMap.get(0); assertEquals("deserialized", fromCache.name); }
Example #5
Source File: ZeebeHazelcastService.java From zeebe-simple-monitor with Apache License 2.0 | 6 votes |
@PostConstruct public void start() { final ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().addAddress(hazelcastConnection); final var connectionRetryConfig = clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig(); connectionRetryConfig.setClusterConnectTimeoutMillis( Duration.parse(hazelcastConnectionTimeout).toMillis()); LOG.info("Connecting to Hazelcast '{}'", hazelcastConnection); final HazelcastInstance hazelcast = HazelcastClient.newHazelcastClient(clientConfig); LOG.info("Importing records from Hazelcast..."); closeable = importService.importFrom(hazelcast); }
Example #6
Source File: ClassLoadingTest.java From subzero with Apache License 2.0 | 6 votes |
@Test public void givenClientHasClassLoaderConfigured_whenObjectIsFetched_thenClassLoaderWillBeUsed() throws Exception { Config memberConfig = new Config(); SubZero.useAsGlobalSerializer(memberConfig); hazelcastFactory.newHazelcastInstance(memberConfig); ClientConfig clientConfig = new ClientConfig(); ClassLoader clientClassLoader = createSpyingClassLoader(); clientConfig.setClassLoader(clientClassLoader); SubZero.useAsGlobalSerializer(clientConfig); HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig); IMap<Integer, Object> myMap = client.getMap(randomMapName()); myMap.put(0, new MyClass()); myMap.get(0); verify(clientClassLoader).loadClass("info.jerrinot.subzero.ClassLoadingTest$MyClass"); }
Example #7
Source File: ProducerConsumerHzClient.java From hazelcastmq with Apache License 2.0 | 5 votes |
@Override public void run() { // Create a Hazelcast instance. ClientConfig config = new ClientConfig(); config.getNetworkConfig().addAddress("localhost:6071"); HazelcastInstance hz = HazelcastClient.newHazelcastClient(config); try { // Setup the connection factory. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hz); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); try (HazelcastMQContext mqContext = mqInstance.createContext()) { try (HazelcastMQConsumer mqConsumer = mqContext.createConsumer("/queue/example.dest")) { HazelcastMQMessage msg = mqConsumer.receive(10, TimeUnit.SECONDS); if (msg != null) { System.out.println("Got message: " + msg.getBodyAsString()); } else { System.out.println("Failed to get message."); } } mqContext.stop(); } mqInstance.shutdown(); } finally { hz.shutdown(); } }
Example #8
Source File: HazelcastConfiguration.java From devicehive-java-server with Apache License 2.0 | 5 votes |
@Bean public HazelcastInstance hazelcast() throws Exception { ClientConfig clientConfig = new ClientConfig(); clientConfig.getGroupConfig() .setName(groupName) .setPassword(groupPassword); clientConfig.getNetworkConfig() .setAddresses(clusterMembers); clientConfig.getSerializationConfig() .addPortableFactory(1, new DevicePortableFactory()); clientConfig.setProperty("hazelcast.client.event.thread.count", eventThreadCount); return HazelcastClient.newHazelcastClient(clientConfig); }
Example #9
Source File: HazelcastCacheConfig.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Bean public HazelcastInstance hazelcastInstance() { ClientNetworkConfig networkConfig = new ClientNetworkConfig() .addAddress("localhost"); ClientConfig clientConfig = new ClientConfig(); clientConfig.setNetworkConfig(networkConfig); return HazelcastClient.newHazelcastClient(clientConfig); }
Example #10
Source File: NativeClient.java From tutorials with MIT License | 5 votes |
public static void main(String[] args) throws InterruptedException { ClientConfig config = new ClientConfig(); GroupConfig groupConfig = config.getGroupConfig(); groupConfig.setName("dev"); groupConfig.setPassword("dev-pass"); HazelcastInstance hazelcastInstanceClient = HazelcastClient.newHazelcastClient(config); IMap<Long, String> map = hazelcastInstanceClient.getMap("data"); for (Entry<Long, String> entry : map.entrySet()) { System.out.println(String.format("Key: %d, Value: %s", entry.getKey(), entry.getValue())); } }
Example #11
Source File: KeyUtilsTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { Config config = new Config(); config.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT); hz = newHazelcastInstance(config); HazelcastInstance remoteInstance = newHazelcastInstance(config); warmupPartitions(hz); warmupPartitions(remoteInstance); ClientConfig clientconfig = new ClientConfig(); clientconfig.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT); client = HazelcastClient.newHazelcastClient(clientconfig); }
Example #12
Source File: ClientServerHazelcastIndexedSessionRepositoryITests.java From spring-session with Apache License 2.0 | 5 votes |
@Bean HazelcastInstance hazelcastInstance() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig() .addAddress(container.getContainerIpAddress() + ":" + container.getFirstMappedPort()); clientConfig.getUserCodeDeploymentConfig().setEnabled(true).addClass(Session.class) .addClass(MapSession.class).addClass(SessionUpdateEntryProcessor.class); return HazelcastClient.newHazelcastClient(clientConfig); }
Example #13
Source File: DefaultHazelcastProvider.java From dolphin-platform with Apache License 2.0 | 5 votes |
public synchronized HazelcastInstance getHazelcastInstance(final HazelcastConfig configuration) { if (hazelcastInstance == null) { final String serverName = configuration.getServerName(); final String serverPort = configuration.getServerPort(); final String groupName = configuration.getGroupName(); LOG.debug("Hazelcast server name: {}", serverName); LOG.debug("Hazelcast server port: {}", serverPort); LOG.debug("Hazelcast group name: {}", groupName); final ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().setConnectionAttemptLimit(configuration.getConnectionAttemptLimit()); clientConfig.getNetworkConfig().setConnectionAttemptPeriod(configuration.getConnectionAttemptPeriod()); clientConfig.getNetworkConfig().setConnectionTimeout(configuration.getConnectionTimeout()); clientConfig.getNetworkConfig().addAddress(serverName + ":" + serverPort); clientConfig.getGroupConfig().setName(groupName); clientConfig.setProperty(LOGGER_PROPERTY_NAME, LOGGER_PROPERTY_SLF4J_TYPE); final SerializerConfig dolphinEventSerializerConfig = new SerializerConfig(). setImplementation(new EventStreamSerializer()).setTypeClass(DolphinEvent.class); clientConfig.getSerializationConfig().getSerializerConfigs().add(dolphinEventSerializerConfig); hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig); } return hazelcastInstance; }
Example #14
Source File: JetRunner.java From beam with Apache License 2.0 | 5 votes |
private JetInstance getJetInstance(JetPipelineOptions options) { String clusterName = options.getClusterName(); ClientConfig clientConfig = new ClientConfig(); clientConfig.setClusterName(clusterName); boolean hasNoLocalMembers = options.getJetLocalMode() <= 0; if (hasNoLocalMembers) { clientConfig .getNetworkConfig() .setAddresses(Arrays.asList(options.getJetServers().split(","))); } return jetClientSupplier.apply(clientConfig); }
Example #15
Source File: BaseSmokeTests.java From subzero with Apache License 2.0 | 5 votes |
private static SerializationConfig extractSerializationConfig(Object configurationObject) { if (configurationObject instanceof Config) { return ((Config) configurationObject).getSerializationConfig(); } else if (configurationObject instanceof ClientConfig) { return ((ClientConfig) configurationObject).getSerializationConfig(); } else { throw new AssertionError("unknown configuration object " + configurationObject); } }
Example #16
Source File: HazelcastGetStartClient.java From hazelcast-demo with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ClientConfig clientConfig = new ClientConfig(); HazelcastInstance instance = HazelcastClient.newHazelcastClient(clientConfig); Map<Integer, String> clusterMap = instance.getMap("MyMap"); Queue<String> clusterQueue = instance.getQueue("MyQueue"); System.out.println("Map Value:" + clusterMap.get(1)); System.out.println("Queue Size :" + clusterQueue.size()); System.out.println("Queue Value 1:" + clusterQueue.poll()); System.out.println("Queue Value 2:" + clusterQueue.poll()); System.out.println("Queue Size :" + clusterQueue.size()); }
Example #17
Source File: SubZero.java From subzero with Apache License 2.0 | 5 votes |
private static SerializationConfig extractSerializationConfig(Object config) { String className = config.getClass().getName(); SerializationConfig serializationConfig; if (className.equals("com.hazelcast.client.config.ClientConfig")) { ClientConfig clientConfig = (ClientConfig) config; serializationConfig = clientConfig.getSerializationConfig(); } else if (className.equals("com.hazelcast.config.Config")) { Config memberConfig = (Config) config; serializationConfig = memberConfig.getSerializationConfig(); } else { throw new IllegalArgumentException("Unknown configuration object " + config); } return serializationConfig; }
Example #18
Source File: HazelcastAdapter.java From dew with Apache License 2.0 | 5 votes |
/** * Init. */ @PostConstruct public void init() { ClientConfig clientConfig = new ClientConfig(); clientConfig.setProperty("hazelcast.logging.type", "slf4j"); if (hazelcastConfig.getUsername() != null) { clientConfig.getGroupConfig().setName(hazelcastConfig.getUsername()).setPassword(hazelcastConfig.getPassword()); } clientConfig.getNetworkConfig().setConnectionTimeout(hazelcastConfig.getConnectionTimeout()); clientConfig.getNetworkConfig().setConnectionAttemptLimit(hazelcastConfig.getConnectionAttemptLimit()); clientConfig.getNetworkConfig().setConnectionAttemptPeriod(hazelcastConfig.getConnectionAttemptPeriod()); hazelcastConfig.getAddresses().forEach(i -> clientConfig.getNetworkConfig().addAddress(i)); hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig); active = true; }
Example #19
Source File: HazelcastJetClientConfiguration.java From hazelcast-jet-contrib with Apache License 2.0 | 5 votes |
private static ClientConfig getClientConfig(Resource clientConfigLocation) throws IOException { URL configUrl = clientConfigLocation.getURL(); String configFileName = configUrl.getPath(); if (configFileName.endsWith(".yaml") || configFileName.endsWith("yml")) { return new YamlClientConfigBuilder(configUrl).build(); } return new XmlClientConfigBuilder(configUrl).build(); }
Example #20
Source File: HazelcastTest.java From greycat with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ClientConfig clientConfig = new ClientConfig(); clientConfig.addAddress("127.0.0.1:5701"); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); IMap map = client.getMap("customers"); System.out.println("Map Size:" + map.size()); client.getDurableExecutorService("hello").submit(new HazelcastJob(() -> System.out.println("Hello"))); }
Example #21
Source File: HazelcastJetAutoConfigurationClientTests.java From hazelcast-jet-contrib with Apache License 2.0 | 5 votes |
@Bean ClientConfig anotherHazelcastClientConfig() { ClientConfig config = new ClientConfig(); config.setClusterName("boot-starter"); Set<String> labels = new HashSet<>(); labels.add("configAsBean-label"); config.setLabels(labels); return config; }
Example #22
Source File: HazelcastSetup.java From mercury with Apache License 2.0 | 5 votes |
public static void connectToHazelcast() { String topic = getRealTopic(); if (client != null) { client.getLifecycleService().removeLifecycleListener(listenerId); client.shutdown(); } String[] address = new String[cluster.size()]; for (int i=0; i < cluster.size(); i++) { address[i] = cluster.get(i); } ClientConnectionStrategyConfig connectionStrategy = new ClientConnectionStrategyConfig(); connectionStrategy.setReconnectMode(ClientConnectionStrategyConfig.ReconnectMode.ASYNC); ConnectionRetryConfig retry = new ConnectionRetryConfig(); retry.setClusterConnectTimeoutMillis(MAX_CLUSTER_WAIT); connectionStrategy.setConnectionRetryConfig(retry); ClientConfig config = new ClientConfig(); config.getNetworkConfig().addAddress(address); config.setConnectionStrategyConfig(connectionStrategy); client = HazelcastClient.newHazelcastClient(config); client.getCluster().addMembershipListener(new ClusterListener()); listenerId = client.getLifecycleService().addLifecycleListener(new TopicLifecycleListener(topic)); if (!isServiceMonitor) { try { // recover the topic PostOffice.getInstance().request(MANAGER, 10000, new Kv(TYPE, TopicManager.CREATE_TOPIC)); } catch (IOException | TimeoutException | AppException e) { log.error("Unable to create topic {} - {}", topic, e.getMessage()); } } log.info("Connected to hazelcast cluster and listening to {} ", topic); }
Example #23
Source File: CalculatorApplication.java From Continuous-Delivery-with-Docker-and-Jenkins-Second-Edition with MIT License | 4 votes |
@Bean public ClientConfig hazelcastClientConfig() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().addAddress("hazelcast"); return clientConfig; }
Example #24
Source File: ProducerRequestReplyWithExternalHazelcast.java From hazelcastmq with Apache License 2.0 | 4 votes |
/** * Constructs the example. * * @throws JMSException */ public ProducerRequestReplyWithExternalHazelcast() throws JMSException { // Create a Hazelcast instance client. ClientConfig config = new ClientConfig(); config.setAddresses(asList("127.0.0.1")); HazelcastInstance hazelcast = HazelcastClient.newHazelcastClient(config); try { // HazelcastMQ Instance HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // HazelcastMQJms Instance HazelcastMQJmsConfig mqJmsConfig = new HazelcastMQJmsConfig(); mqJmsConfig.setHazelcastMQInstance(mqInstance); HazelcastMQJmsConnectionFactory connectionFactory = new HazelcastMQJmsConnectionFactory( mqJmsConfig); // Create a connection, session, and destinations. Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination requestDest = session.createQueue("foo.bar"); Destination replyDest = session.createTemporaryQueue(); // Create a request producer and reply consumer. MessageProducer producer1 = session.createProducer(requestDest); MessageConsumer consumer1 = session.createConsumer(replyDest); // Send the request. sendRequest(session, producer1, replyDest); // Process the reply. handleReply(session, consumer1); // Cleanup. session.close(); connection.close(); } finally { hazelcast.getLifecycleService().shutdown(); } }
Example #25
Source File: CalculatorApplication.java From Continuous-Delivery-with-Docker-and-Jenkins-Second-Edition with MIT License | 4 votes |
@Bean public ClientConfig hazelcastClientConfig() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().addAddress("hazelcast"); return clientConfig; }
Example #26
Source File: CalculatorApplication.java From Continuous-Delivery-with-Docker-and-Jenkins-Second-Edition with MIT License | 4 votes |
@Bean public ClientConfig hazelcastClientConfig() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().addAddress("<machine-ip-1>"); return clientConfig; }
Example #27
Source File: HazelcastJetClientConfiguration.java From hazelcast-jet-contrib with Apache License 2.0 | 4 votes |
@Bean JetInstance jetInstance(ClientConfig clientConfig) { return Jet.newJetClient(clientConfig); }
Example #28
Source File: Cluster.java From OSPREY3 with GNU General Public License v2.0 | 4 votes |
public Client(Parallelism parallelism) { this.parallelism = parallelism; this.name = String.format("%s-client-%d", Cluster.this.name, nodeId); // make a member first, if needed if (clientIsMember) { member = new Member(parallelism); } else { member = null; } // configure the cluster ClientConfig cfg = new ClientConfig(); cfg.setClusterName(id); cfg.setInstanceName(name); // disable Hazelcast's automatic phone home "feature", which is on by default cfg.setProperty("hazelcast.phone.home.enabled", "false"); log("node looking for cluster named %s ...", id); inst = HazelcastClient.newHazelcastClient(cfg); log("node started on cluster %s", id); activeId = new Value<>(inst, TasksActiveIdName); scatter = inst.getQueue(TasksScatterName); gather = inst.getQueue(TasksGatherName); listener = new Thread(() -> { try { while (listenerActive.get()) { // get the next task result, if any TaskResult<?> taskResult = gather.poll(400, TimeUnit.MILLISECONDS); if (taskResult != null) { // find the task for this result TaskAndListener<?,?> tal = tasks.get(taskResult.taskId); if (tal == null) { log("WARNING: received result for unknown task: %d", taskResult.taskId); continue; } try { // handle the task result if (taskResult.t != null) { taskFailure(tal.task, tal.listener, taskResult.t); } else { taskSuccessCoerceTypes(tal.task, tal.listener, taskResult.result); } } finally { // clean up the handled task tasks.remove(taskResult.taskId); } } } } catch (InterruptedException ex) { // exit the thread } catch (Throwable t) { t.printStackTrace(System.err); } }); listener.setName("ClusterClientListener"); listener.setDaemon(true); listener.start(); }
Example #29
Source File: ApplicationConfig.java From hazelcast-jet-demos with Apache License 2.0 | 4 votes |
@Bean public ClientConfig clientConfig() throws Exception { return new YamlClientConfigBuilder("hazelcast-client.yaml").build(); }
Example #30
Source File: HazelcastTestHelper.java From brooklyn-library with Apache License 2.0 | 4 votes |
public HazelcastTestHelper(String hazelcastAddress, Integer hazelcastPort) { clientConfig = new ClientConfig(); clientConfig.getGroupConfig().setName(GROUP_NAME).setPassword(GROUP_PASS); clientConfig.getNetworkConfig().addAddress(String.format("%s:%d", hazelcastAddress, hazelcastPort)); }