com.hazelcast.client.HazelcastClient Java Examples
The following examples show how to use
com.hazelcast.client.HazelcastClient.
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: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 6 votes |
@Test(expected = SnowcastStateException.class) public void test_id_generation_in_attach_wrong_state() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); assertNotNull(sequencer); sequencer.attachLogicalNode(); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #2
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 6 votes |
@Test(expected = SnowcastStateException.class) public void test_id_generation_in_detached_state() throws Exception { Hazelcast.newHazelcastInstance(); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); assertNotNull(sequencer); assertNotNull(sequencer.next()); // Detach the node and free the currently used logical node ID sequencer.detachLogicalNode(); sequencer.next(); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #3
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 6 votes |
@Test public void test_sequencer_counter_value() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(128); int shifting = calculateLogicalNodeShifting(boundedNodeCount); long sequence = generateSequenceId(10000, 10, 100, shifting); assertEquals(100, sequencer.counterValue(sequence)); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #4
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 #5
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 6 votes |
@Test public void test_sequencer_timestamp() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(128); int shifting = calculateLogicalNodeShifting(boundedNodeCount); long sequence = generateSequenceId(10000, 10, 100, shifting); assertEquals(10000, sequencer.timestampValue(sequence)); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #6
Source File: ConnectDisconnectTest.java From hazelcast-simulator with Apache License 2.0 | 6 votes |
@TimeStep public void timestep() throws Exception { Thread thread = new Thread(() -> { try { HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); client.shutdown(); } catch (Exception e) { ExceptionReporter.report(testContext.getTestId(), e); } }); thread.start(); thread.join(timeoutMillis); if (thread.isAlive()) { throw new RuntimeException("Connect/Disconnect cycle failed to complete in " + timeoutMillis + " millis"); } }
Example #7
Source File: ConnectDisconnectTest.java From hazelcast-simulator with Apache License 2.0 | 6 votes |
@TimeStep public void timestep() throws Exception { Thread thread = new Thread(() -> { try { HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); client.shutdown(); } catch (Exception e) { ExceptionReporter.report(testContext.getTestId(), e); } }); thread.start(); thread.join(timeoutMillis); if (thread.isAlive()) { throw new RuntimeException("Connect/Disconnect cycle failed to complete in " + timeoutMillis + " millis"); } }
Example #8
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 #9
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 6 votes |
@Test public void test_single_id_generation() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); assertNotNull(sequencer); assertNotNull(sequencer.next()); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #10
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 #11
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 6 votes |
@Test public void test_sequencer_logical_node_id() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); int boundedNodeCount = calculateBoundedMaxLogicalNodeCount(128); int shifting = calculateLogicalNodeShifting(boundedNodeCount); long sequence = generateSequenceId(10000, 10, 100, shifting); assertEquals(10, sequencer.logicalNodeId(sequence)); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #12
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 6 votes |
@Test public void test_simple_sequencer_initialization() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); assertNotNull(sequencer); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 5 votes |
@Test(expected = SnowcastStateException.class) public void test_destroyed_state_from_node() throws Exception { HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { SnowcastEpoch epoch = buildEpoch(); Snowcast snowcastClient = SnowcastSystem.snowcast(client); SnowcastSequencer sequencerClient = buildSnowcastSequencer(snowcastClient, epoch); assertNotNull(sequencerClient); assertNotNull(sequencerClient.next()); Snowcast snowcastNode = SnowcastSystem.snowcast(hazelcastInstance); SnowcastSequencer sequencerNode = buildSnowcastSequencer(snowcastNode, epoch); assertNotNull(sequencerNode); assertNotNull(sequencerNode.next()); snowcastNode.destroySequencer(sequencerNode); long deadline = System.currentTimeMillis() + 60000; while (true) { // Will eventually fail sequencerClient.next(); if (System.currentTimeMillis() >= deadline) { // Safe exit after another minute of waiting for the event return; } } } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #20
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 5 votes |
@Test(expected = SnowcastStateException.class) public void test_destroyed_state() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); assertNotNull(sequencer); assertNotNull(sequencer.next()); snowcast.destroySequencer(sequencer); long deadline = System.currentTimeMillis() + 60000; while (true) { // Will eventually fail sequencer.next(); if (System.currentTimeMillis() >= deadline) { // Safe exit after another minute of waiting for the event return; } } } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #21
Source File: ClientBasicTestCase.java From snowcast with Apache License 2.0 | 5 votes |
@Test public void test_id_generation_in_reattached_state() throws Exception { Hazelcast.newHazelcastInstance(config); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); try { Snowcast snowcast = SnowcastSystem.snowcast(client); SnowcastSequencer sequencer = buildSnowcastSequencer(snowcast); assertNotNull(sequencer); assertNotNull(sequencer.next()); // Detach the node and free the currently used logical node ID sequencer.detachLogicalNode(); try { // Must fail since we're in detached state! sequencer.next(); fail(); } catch (SnowcastStateException e) { // Expected, so ignore } // Re-attach the node and assign a free logical node ID sequencer.attachLogicalNode(); assertNotNull(sequencer.next()); } finally { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); } }
Example #22
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 #23
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 #24
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 #25
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 #26
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 #27
Source File: HazelcastTest.java From java-specialagent with Apache License 2.0 | 4 votes |
@Test public void testNewHazelcastClientInstance(final MockTracer tracer) { final HazelcastInstance instance = HazelcastClient.newHazelcastClient(); test(instance, tracer); }
Example #28
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 #29
Source File: HazelcastClientFactory.java From incubator-batchee with Apache License 2.0 | 4 votes |
public static HazelcastInstance newClient(final String xmlConfiguration) throws IOException { return HazelcastClient.newHazelcastClient( new XmlClientConfigBuilder(IOs.findConfiguration(xmlConfiguration)).build()); }
Example #30
Source File: KeyUtilsTest.java From hazelcast-simulator with Apache License 2.0 | 4 votes |
@AfterClass public static void afterClass() { HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }