Code cleanup
Signed-off-by: nguyenminhtuanfit@gmail.com <nguyenminhtuanfit@gmail.com>
This commit is contained in:
parent
877706d2e1
commit
97d0c71449
@ -1,9 +1,7 @@
|
|||||||
package com.baeldung.hazelcast.cluster;
|
package com.baeldung.hazelcast.cluster;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import java.util.Map.Entry;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.baeldung.hazelcast.listener.CountryEntryListener;
|
|
||||||
import com.hazelcast.client.HazelcastClient;
|
import com.hazelcast.client.HazelcastClient;
|
||||||
import com.hazelcast.client.config.ClientConfig;
|
import com.hazelcast.client.config.ClientConfig;
|
||||||
import com.hazelcast.config.GroupConfig;
|
import com.hazelcast.config.GroupConfig;
|
||||||
@ -11,7 +9,6 @@ import com.hazelcast.core.HazelcastInstance;
|
|||||||
import com.hazelcast.core.IMap;
|
import com.hazelcast.core.IMap;
|
||||||
|
|
||||||
public class NativeClient {
|
public class NativeClient {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(NativeClient.class);
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
ClientConfig config = new ClientConfig();
|
ClientConfig config = new ClientConfig();
|
||||||
@ -19,8 +16,9 @@ public class NativeClient {
|
|||||||
groupConfig.setName("dev");
|
groupConfig.setName("dev");
|
||||||
groupConfig.setPassword("dev-pass");
|
groupConfig.setPassword("dev-pass");
|
||||||
HazelcastInstance hazelcastInstanceClient = HazelcastClient.newHazelcastClient(config);
|
HazelcastInstance hazelcastInstanceClient = HazelcastClient.newHazelcastClient(config);
|
||||||
IMap<Long, String> countryMap = hazelcastInstanceClient.getMap("country");
|
IMap<Long, String> map = hazelcastInstanceClient.getMap("data");
|
||||||
countryMap.addEntryListener(new CountryEntryListener(), true);
|
for (Entry<Long, String> entry : map.entrySet()) {
|
||||||
logger.info("Country map size: " + countryMap.size());
|
System.out.println(String.format("Key: %d, Value: %s", entry.getKey(), entry.getValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,18 @@ package com.baeldung.hazelcast.cluster;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.hazelcast.core.Hazelcast;
|
import com.hazelcast.core.Hazelcast;
|
||||||
import com.hazelcast.core.HazelcastInstance;
|
import com.hazelcast.core.HazelcastInstance;
|
||||||
import com.hazelcast.core.IdGenerator;
|
import com.hazelcast.core.IdGenerator;
|
||||||
|
|
||||||
public class ServerNode {
|
public class ServerNode {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ServerNode.class);
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
|
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
|
||||||
Map<Long, String> countryMap = hazelcastInstance.getMap("country");
|
Map<Long, String> map = hazelcastInstance.getMap("data");
|
||||||
IdGenerator idGenerator = hazelcastInstance.getIdGenerator("newid");
|
IdGenerator idGenerator = hazelcastInstance.getIdGenerator("newid");
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
countryMap.put(idGenerator.newId(), "message" + 1);
|
map.put(idGenerator.newId(), "message" + 1);
|
||||||
}
|
}
|
||||||
logger.info("Country map size: " + countryMap.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package com.baeldung.hazelcast.listener;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.hazelcast.core.EntryEvent;
|
|
||||||
import com.hazelcast.core.MapEvent;
|
|
||||||
import com.hazelcast.map.listener.EntryAddedListener;
|
|
||||||
import com.hazelcast.map.listener.EntryEvictedListener;
|
|
||||||
import com.hazelcast.map.listener.EntryRemovedListener;
|
|
||||||
import com.hazelcast.map.listener.EntryUpdatedListener;
|
|
||||||
import com.hazelcast.map.listener.MapClearedListener;
|
|
||||||
import com.hazelcast.map.listener.MapEvictedListener;
|
|
||||||
|
|
||||||
public class CountryEntryListener implements EntryAddedListener<Long, String>, EntryRemovedListener<Long, String>, EntryUpdatedListener<Long, String>, EntryEvictedListener<Long, String>, MapEvictedListener, MapClearedListener {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CountryEntryListener.class);
|
|
||||||
|
|
||||||
public void entryAdded(EntryEvent<Long, String> event) {
|
|
||||||
logger.info("entryAdded:" + event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void entryUpdated(EntryEvent<Long, String> event) {
|
|
||||||
logger.info("entryUpdated:" + event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void entryRemoved(EntryEvent<Long, String> event) {
|
|
||||||
logger.info("entryRemoved:" + event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void entryEvicted(EntryEvent<Long, String> event) {
|
|
||||||
logger.info("entryEvicted:" + event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mapCleared(MapEvent event) {
|
|
||||||
logger.info("mapCleared:" + event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mapEvicted(MapEvent event) {
|
|
||||||
logger.info("mapEvicted:" + event);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user