Code cleanup

Signed-off-by: nguyenminhtuanfit@gmail.com <nguyenminhtuanfit@gmail.com>
This commit is contained in:
Prashant Khanal 2016-10-11 16:06:10 -07:00 committed by nguyenminhtuanfit@gmail.com
parent 877706d2e1
commit 97d0c71449
3 changed files with 7 additions and 55 deletions

View File

@ -1,9 +1,7 @@
package com.baeldung.hazelcast.cluster;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map.Entry;
import com.baeldung.hazelcast.listener.CountryEntryListener;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.GroupConfig;
@ -11,7 +9,6 @@ import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
public class NativeClient {
private static final Logger logger = LoggerFactory.getLogger(NativeClient.class);
public static void main(String[] args) throws InterruptedException {
ClientConfig config = new ClientConfig();
@ -19,8 +16,9 @@ public class NativeClient {
groupConfig.setName("dev");
groupConfig.setPassword("dev-pass");
HazelcastInstance hazelcastInstanceClient = HazelcastClient.newHazelcastClient(config);
IMap<Long, String> countryMap = hazelcastInstanceClient.getMap("country");
countryMap.addEntryListener(new CountryEntryListener(), true);
logger.info("Country map size: " + countryMap.size());
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()));
}
}
}

View File

@ -2,23 +2,18 @@ package com.baeldung.hazelcast.cluster;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IdGenerator;
public class ServerNode {
private static final Logger logger = LoggerFactory.getLogger(ServerNode.class);
public static void main(String[] args) {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
Map<Long, String> countryMap = hazelcastInstance.getMap("country");
Map<Long, String> map = hazelcastInstance.getMap("data");
IdGenerator idGenerator = hazelcastInstance.getIdGenerator("newid");
for (int i = 0; i < 10; i++) {
countryMap.put(idGenerator.newId(), "message" + 1);
}
logger.info("Country map size: " + countryMap.size());
map.put(idGenerator.newId(), "message" + 1);
}
}
}

View File

@ -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);
}
}