Hazelcast Quick Start Example

0

Hazelcast is an open source In-Memory Data Grid. In this article, we will see how to get started with hazelcast. We will use the default hazaelcast configuration, start two hazelcast instances on separate jvms, store some data in each cluster instance and then access the cluster data using hazalcast client.

Hazelcast Overview

When the first hazelcast instance starts, it creates its own cluster and adds itself as the leader node. When the second node starts, it will wait 2 seconds for a valid multicast response from another node running in the network before declaring itself as master node and creating its own cluster. If multicast is not the preferred way of discovery, then one can configure Hazelcast to be a
full TCP/IP cluster or using EC2 Auto Discovery.

One of the main features of Hazelcast is not having a master node as each node in the cluster is configured to be the same in terms of functionality. The oldest node (the first node created in the node cluster) manages the cluster members, i.e. automatically performs the data assignment to nodes. If the oldest node dies, the second oldest node will manage the cluster members.

Hazelcast stores everything in-memory. It keeps the backup of each data entry on multiple nodes. On a node failure, the data is restored from the backup and the cluster will continue to operate without downtime.

Dependencies

If your project uses Maven, you need to add hazelcast and hazelcast-client to the pom.xml.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javarticles.mockito</groupId>
	<artifactId>mockitoVerifyBehavior</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<dependencies>
		<dependency>
			<groupId>com.hazelcast</groupId>
			<artifactId>hazelcast</artifactId>
			<version>3.5.2</version>
		</dependency>
		<dependency>
			<groupId>com.hazelcast</groupId>
			<artifactId>hazelcast-client</artifactId>
			<version>3.5.2</version>
		</dependency>
	</dependencies>
</project>

Configuring Logging

Hazelcast supports various logging mechanisms; jdk, log4, sl4j or none if you do not want to have any logging. The default is jdk so no additional dependencies are needed as this comes bundled as part of the JRE.
Hazelcast needs to know the logging mechanism you want to configure. This can be set by adding a logging property hazelcast.logging.type in the hazelcast.xml.

In our example, we will use log4j as the log provider.

hazelcast.xml:

<hazelcast>
...
    <properties>
        <property name="hazelcast.logging.type">log4j</property>
    </properties>
...
</hazelcast>

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javarticles.mockito</groupId>
	<artifactId>mockitoVerifyBehavior</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<dependencies>
		<dependency>
			<groupId>com.hazelcast</groupId>
			<artifactId>hazelcast</artifactId>
			<version>3.5.2</version>
		</dependency>
		<dependency>
			<groupId>com.hazelcast</groupId>
			<artifactId>hazelcast-client</artifactId>
			<version>3.5.2</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
	</dependencies>
</project>

Add log4j.properties to your classpath.

log4j.properties:

# Root logger option
log4j.rootLogger=INFO, console

log4j.logger.com.javarticles=INFO, console

# Direct log messages to console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n

Start Hazelcast Members

Create a simple Java application using the Hazelcast distributed map. When Hazelcast starts up, it checks for the configuration. You can set hazelcast configuration file path against hazelcast.config system property. If the hazelcast configuration file is part of the classpath then we don’t have use the system property and the hazelcast will try to figure out the configuration file on its own. First in the working directory and then in the classpath.

If there is no hazelcast.xml found then hazelcast will use the default configuration file hazelcast-default.xml that comes with hazelcast.jar. Since we are using the default hazelcast configuration, we will set the hazelcast.logging.type programatically.

System.setProperty("hazelcast.logging.type", "log4j");

Cluster Member1

HazelcastInstance represents a hazelcast cluster node. Once we have the HazelcastInstance, we will use it to create a distributed Map object to store employee names.
The distributed implementation of java.util.Map lets you read from and write to a Hazelcast map.

ClusterMember1:

package com.javarticles.hazelcast;

import java.util.Map;

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;

public class ClusterMember1 {
    public static void main(String[] args) {
        System.setProperty("hazelcast.logging.type", "log4j");
        HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance();
        Map<String, String> empMap = hazelcast.getMap("employees");
        empMap.put("02", "Sam");
    }
}

From the output you can see the number of members. For now, we just have one member.

Output:

17:36| INFO | Log4jFactory.java 61 | Loading 'hazelcast-default.xml' from classpath.
17:36| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Prefer IPv4 stack is true.
17:36| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Picked Address[192.168.1.37]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Backpressure is disabled
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Starting with 4 generic operation threads and 8 partition operation threads.
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Hazelcast 3.5.2 (20150826 - ba8dbba) starting at Address[192.168.1.37]:5701
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Creating MulticastJoiner
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Address[192.168.1.37]:5701 is STARTING
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] 


Members [1] {
	Member [192.168.1.37]:5701 this
}

17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Address[192.168.1.37]:5701 is STARTED
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Initializing cluster partition table first arrangement...

Cluster Member2

Let’s start another member. We will get the same map and add one more employee detail.

ClusterMember2:

package com.javarticles.hazelcast;

import java.util.Map;

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;

public class ClusterMember2 {
    public static void main(String[] args) {
        System.setProperty("hazelcast.logging.type", "log4j");
        HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance();
        Map<String, String> empMap = hazelcast.getMap("employees");
        empMap.put("01", "Joe");
    }
}

From the second member’s output, we can see two members in the cluster. The current member is listening on port 5702.

Output:

17:37| INFO | Log4jFactory.java 61 | Loading 'hazelcast-default.xml' from classpath.
17:37| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Prefer IPv4 stack is true.
17:37| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Picked Address[192.168.1.37]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5702], bind any local is true
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Backpressure is disabled
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Starting with 4 generic operation threads and 8 partition operation threads.
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Hazelcast 3.5.2 (20150826 - ba8dbba) starting at Address[192.168.1.37]:5702
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Creating MulticastJoiner
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Address[192.168.1.37]:5702 is STARTING
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Trying to join to discovered node: Address[192.168.1.37]:5701
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Connecting to /192.168.1.37:5701, timeout: 0, bind-any: true
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Established socket connection between /192.168.1.37:59257
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] 

Members [2] {
	Member [192.168.1.37]:5701
	Member [192.168.1.37]:5702 this
}

17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Address[192.168.1.37]:5702 is STARTED

Even the first member’s output shows up the second member joined.

Member1’s output:

17:36| INFO | Log4jFactory.java 61 | Loading 'hazelcast-default.xml' from classpath.
17:36| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Prefer IPv4 stack is true.
17:36| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Picked Address[192.168.1.37]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Backpressure is disabled
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Starting with 4 generic operation threads and 8 partition operation threads.
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Hazelcast 3.5.2 (20150826 - ba8dbba) starting at Address[192.168.1.37]:5701
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Creating MulticastJoiner
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Address[192.168.1.37]:5701 is STARTING
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] 


Members [1] {
	Member [192.168.1.37]:5701 this
}

17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Address[192.168.1.37]:5701 is STARTED
17:36| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Initializing cluster partition table first arrangement...
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Accepting socket connection from /192.168.1.37:59257
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Established socket connection between /192.168.1.37:5701
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] 

Members [2] {
	Member [192.168.1.37]:5701 this
	Member [192.168.1.37]:5702
}

17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Re-partitioning cluster data... Migration queue size: 135
17:37| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] All migration tasks have been completed, queues are empty.

Start the Client

Its the time to access the cluster created using hazelcast Native Java Client API.

ClientOfHazelcast:

package com.javarticles.hazelcast;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;

public class ClientOfHazelcast {
    public static void main(String[] args) {
        ClientConfig clientConfig = new ClientConfig();
        HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
        IMap map = hazelcastInstance.getMap("employees");
        System.out.println(map.get("01"));
        System.out.println(map.get("02"));
    }
}

As you can see it was able to access the map and get the values for ID 01 and 02.

Output:

Dec 23, 2015 5:41:07 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5.2] is STARTING
Dec 23, 2015 5:41:07 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5.2] is STARTED
Dec 23, 2015 5:41:07 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5.2] is CLIENT_CONNECTED
Dec 23, 2015 5:41:07 PM com.hazelcast.client.spi.impl.ClientMembershipListener
INFO: 

Members [2] {
	Member [192.168.1.37]:5701
	Member [192.168.1.37]:5702
}

Joe
Sam

Let’s now shutdown member1.
After the shutdown, the total cluster members have reduced to just one.

Member2’s Output:

17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Connection [Address[192.168.1.37]:5701] lost. Reason: java.io.IOException[An existing connection was forcibly closed by the remote host]
17:43| WARN | Log4jFactory.java 90 | [192.168.1.37]:5702 [dev][3.5.2] hz._hzInstance_1_dev.IO.thread-in-0 Closing socket to endpoint Address[192.168.1.37]:5701, Cause:java.io.IOException: An existing connection was forcibly closed by the remote host
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Connecting to /192.168.1.37:5701, timeout: 0, bind-any: true
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Could not connect to: /192.168.1.37:5701. Reason: SocketException[Connection refused: connect to address /192.168.1.37:5701]
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Connecting to /192.168.1.37:5701, timeout: 0, bind-any: true
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Could not connect to: /192.168.1.37:5701. Reason: SocketException[Connection refused: connect to address /192.168.1.37:5701]
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Connecting to /192.168.1.37:5701, timeout: 0, bind-any: true
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Could not connect to: /192.168.1.37:5701. Reason: SocketException[Connection refused: connect to address /192.168.1.37:5701]
17:43| WARN | Log4jFactory.java 90 | [192.168.1.37]:5702 [dev][3.5.2] Removing connection to endpoint Address[192.168.1.37]:5701 Cause => java.net.SocketException {Connection refused: connect to address /192.168.1.37:5701}, Error-Count: 5
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Master Address[192.168.1.37]:5701 left the cluster. Assigning new master Member [192.168.1.37]:5702 this
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Removing Member [192.168.1.37]:5701
17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] 

Members [1] {
	Member [192.168.1.37]:5702 this
}

17:43| INFO | Log4jFactory.java 94 | [192.168.1.37]:5702 [dev][3.5.2] Partition balance is ok, no need to re-partition cluster data...

Let’s run the client again to make sure we are still able to access the map and get the employee values.

Output:

Dec 23, 2015 5:44:41 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5.2] is STARTING
Dec 23, 2015 5:44:41 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5.2] is STARTED
Dec 23, 2015 5:44:43 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5.2] is CLIENT_CONNECTED
Dec 23, 2015 5:44:43 PM com.hazelcast.client.spi.impl.ClientMembershipListener
INFO: 

Members [1] {
	Member [192.168.1.37]:5702
}

Joe
Sam

Log Level

Set the log level to FINER for more detailed log information.

log4j.properties:

# Root logger option
log4j.rootLogger=FINER, console

log4j.logger.com.javarticles=INFO, console

# Direct log messages to console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n

With the level set to FINER, re-start ClusterMember1. This time you will see loads of log information.

Output:

17:46| DEBUG | Log4jFactory.java 55 | Could not 'hazelcast.config' System property
17:46| DEBUG | Log4jFactory.java 55 | Could not find 'hazelcast.xml' in working directory.
17:46| DEBUG | Log4jFactory.java 55 | Could not find 'hazelcast.xml' in classpath.
17:46| INFO | Log4jFactory.java 61 | Loading 'hazelcast-default.xml' from classpath.
17:46| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Prefer IPv4 stack is true.
17:46| DEBUG | Log4jFactory.java 88 | [LOCAL] [dev][3.5.2] inet reuseAddress:false
17:46| DEBUG | Log4jFactory.java 88 | [LOCAL] [dev][3.5.2] Trying to bind inet socket address:0.0.0.0/0.0.0.0:5701
17:46| DEBUG | Log4jFactory.java 88 | [LOCAL] [dev][3.5.2] Bind successful to inet socket address:0.0.0.0/0.0.0.0:5701
17:46| INFO | Log4jFactory.java 94 | [LOCAL] [dev][3.5.2] Picked Address[192.168.1.37]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
17:46| DEBUG | Log4jFactory.java 88 | [LOCAL] [dev][3.5.2] Using public address the same as the bind address. Address[192.168.1.37]:5701
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Backpressure is disabled
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Starting with 4 generic operation threads and 8 partition operation threads.
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Updating members -> [Member [192.168.1.37]:5701 this]
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Hazelcast 3.5.2 (20150826 - ba8dbba) starting at Address[192.168.1.37]:5701
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Creating MulticastJoiner
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Address[192.168.1.37]:5701 is STARTING
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] We are asked to start and completelyShutdown is false
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering core services...
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:core:clusterService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:core:partitionService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:core:proxyService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:core:txManagerService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:core:clientEngine'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:quorumService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering default services...
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:mapService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:lockService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:queueService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:topicService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:reliableTopicService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:multiMapService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:listService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:setService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:executorService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:atomicLongService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:atomicReferenceService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:countDownLatchService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:semaphoreService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:idGeneratorService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:mapReduceService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:replicatedMapService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:ringbufferService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering service: 'hz:impl:xaService'
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] javax.cache api is not detected on classpath. Skipping CacheService...
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Registering user defined services...
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]38089a5a
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> PartitionManager[0] {

migrationQ: 0
}
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]4faa6
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]f22f3
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> ClusterService{address=Address[192.168.1.37]:5701}
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> com.hazelcast.concurrent.atomic[email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Initializing service -> [email protected]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Starting ConnectionManager and IO selectors.
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Using normal IO Balancer Strategy.
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Starting IOBalancer thread
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] No imbalance has been detected. Max. events: -9223372036854775808 Min events: 0.
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] No imbalance has been detected. Max. events: -9223372036854775808 Min events: 0.
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Adding ShutdownHook
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Starting SocketAcceptor on sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:5701]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] finished starting threads, calling join
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Searching for master node. Max tries: 57
17:46| DEBUG | Log4jFactory.java 88 | Old String constructor doesn't seem available
java.lang.NoSuchMethodException: java.lang.String.(int, int, [C)
	at java.lang.Class.getConstructor0(Class.java:3074)
	at java.lang.Class.getDeclaredConstructor(Class.java:2170)
	at com.hazelcast.nio.UTFEncoderDecoder.useOldStringConstructor(UTFEncoderDecoder.java:698)
	at com.hazelcast.nio.UTFEncoderDecoder.buildFastStringCreator(UTFEncoderDecoder.java:753)
	at com.hazelcast.nio.UTFEncoderDecoder.createStringCreator(UTFEncoderDecoder.java:719)
	at com.hazelcast.nio.UTFEncoderDecoder.createStringCreator(UTFEncoderDecoder.java:715)
	at com.hazelcast.nio.UTFEncoderDecoder.buildUTFUtil(UTFEncoderDecoder.java:709)
	at com.hazelcast.nio.UTFEncoderDecoder.(UTFEncoderDecoder.java:48)
	at com.hazelcast.nio.serialization.ByteArrayObjectDataOutput.writeUTF(ByteArrayObjectDataOutput.java:230)
	at com.hazelcast.nio.serialization.DataSerializer.write(DataSerializer.java:138)
	at com.hazelcast.nio.serialization.DataSerializer.write(DataSerializer.java:39)
	at com.hazelcast.nio.serialization.StreamSerializerAdapter.write(StreamSerializerAdapter.java:37)
	at com.hazelcast.nio.serialization.SerializationServiceImpl.writeObject(SerializationServiceImpl.java:305)
	at com.hazelcast.nio.serialization.ByteArrayObjectDataOutput.writeObject(ByteArrayObjectDataOutput.java:315)
	at com.hazelcast.cluster.impl.MulticastService.send(MulticastService.java:182)
	at com.hazelcast.cluster.impl.MulticastJoiner.findMasterWithMulticast(MulticastJoiner.java:150)
	at com.hazelcast.cluster.impl.MulticastJoiner.doJoin(MulticastJoiner.java:56)
	at com.hazelcast.cluster.impl.AbstractJoiner.join(AbstractJoiner.java:93)
	at com.hazelcast.instance.Node.join(Node.java:534)
	at com.hazelcast.instance.Node.start(Node.java:343)
	at com.hazelcast.instance.HazelcastInstanceImpl.(HazelcastInstanceImpl.java:126)
	at com.hazelcast.instance.HazelcastInstanceFactory.constructHazelcastInstance(HazelcastInstanceFactory.java:152)
	at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:135)
	at com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(HazelcastInstanceFactory.java:111)
	at com.hazelcast.core.Hazelcast.newHazelcastInstance(Hazelcast.java:87)
	at com.javarticles.hazelcast.ClusterMember1.main(ClusterMember1.java:11)
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Dropped: JoinRequest{packetVersion=4, buildNumber=20150826, address=Address[192.168.1.37]:5701, uuid='bfb1c654-c9db-48e7-b6aa-abb557da332f', credentials=null, memberCount=1, tryCount=1}
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] ** setting master address to Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] ** setting master address to Address[192.168.1.37]:5702
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Trying to join to discovered node: Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Dropped: JoinRequest{packetVersion=4, buildNumber=20150826, address=Address[192.168.1.37]:5701, uuid='bfb1c654-c9db-48e7-b6aa-abb557da332f', credentials=null, memberCount=1, tryCount=2}
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Joining to master Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Dropped: JoinMessage{packetVersion=4, buildNumber=20150826, address=Address[192.168.1.37]:5702, uuid='bfb1c654-c9db-48e7-b6aa-abb557da332f'}
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Starting to connect to Address[192.168.1.37]:5702
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Connecting to /192.168.1.37:5702, timeout: 0, bind-any: true
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Successfully connected to: Address[192.168.1.37]:5702 using socket Socket[addr=/192.168.1.37,port=5702,localport=59770]
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Connection Connection [/192.168.1.37:59770 -> /192.168.1.37:5702], endpoint=Address[192.168.1.37]:5702, live=true, type=NONE uses read handler [email protected] and write handler [email protected]
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] Established socket connection between /192.168.1.37:59770
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Sending bind packet to Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Binding Connection [/192.168.1.37:59770 -> /192.168.1.37:5702], endpoint=Address[192.168.1.37]:5702, live=true, type=MEMBER to Address[192.168.1.37]:5702, reply is false
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Resetting connection monitor for endpoint Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Joining to master Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Handling master response: Address[192.168.1.37]:5702 from: Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] ** setting master address to Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Joining to master Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Joining to master Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Joining to master Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Joining to master Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Joining to master Address[192.168.1.37]:5702
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Node should be active(true) and joined(false) to be able to process partition table!
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Setting cluster time diff to -4ms.
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Updating members -> [Member [192.168.1.37]:5702, Member [192.168.1.37]:5701 this]
17:46| INFO | Log4jFactory.java 94 | [192.168.1.37]:5701 [dev][3.5.2] 

Members [2] {
	Member [192.168.1.37]:5702
	Member [192.168.1.37]:5701 this
}

17:46| DEBUG | Log4jFactory.java 55 | No configuration found for employees, using default config!
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Sending sync replica request to -> Address[192.168.1.37]:5702; for partitionId=135, replicaIndex=1
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Sending sync replica request to -> Address[192.168.1.37]:5702; for partitionId=136, replicaIndex=1
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Sending sync replica request to -> Address[192.168.1.37]:5702; for partitionId=137, replicaIndex=1
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] No data available for replica sync, partitionId=136, replicaIndex=1
.....
17:46| DEBUG | Log4jFactory.java 88 | [192.168.1.37]:5701 [dev][3.5.2] Sending sync response to -> Address[192.168.1.37]:5702 for partitionId=46, replicaIndex=1

Download the source code

This was an example about getting started with hazelcast.

You can download the source code here: HazelcastExample.zip
Share.

Comments are closed.