added hazelcast client, removed id generator

This commit is contained in:
nguyenminhtuanfit@gmail.com 2016-10-07 23:04:36 +07:00
parent 897e245524
commit 877706d2e1
2 changed files with 71 additions and 65 deletions

View File

@ -7,13 +7,18 @@
<name>hazelcast</name>
<dependencies>
<!-- hazelcast -->
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-all</artifactId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>3.7.2</version>
</dependency>
<!-- utils -->
<dependency>
<groupId>org.slf4j</groupId>
@ -59,7 +64,7 @@
<properties>
<!-- hazelcast -->
<hazelcast.version>3.7</hazelcast.version>
<hazelcast.version>3.7.2</hazelcast.version>
<!-- logging -->
<org.slf4j.version>1.7.21</org.slf4j.version>

View File

@ -16,8 +16,9 @@ public class ServerNode {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
Map<Long, String> countryMap = hazelcastInstance.getMap("country");
IdGenerator idGenerator = hazelcastInstance.getIdGenerator("newid");
Long countryIdGenerator = idGenerator.newId() == 0L ? 1L : idGenerator.newId();
countryMap.put(countryIdGenerator, "Country1");
for (int i = 0; i < 10; i++) {
countryMap.put(idGenerator.newId(), "message" + 1);
}
logger.info("Country map size: " + countryMap.size());
}
}