Created
January 8, 2016 21:30
-
-
Save gurbuzali/b1e347833fcb5af6c729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.hazelcast.config.Config; | |
| import com.hazelcast.config.InMemoryFormat; | |
| import com.hazelcast.config.MapConfig; | |
| import com.hazelcast.config.MapStoreConfig; | |
| import com.hazelcast.core.Hazelcast; | |
| import com.hazelcast.core.HazelcastInstance; | |
| import com.hazelcast.core.IMap; | |
| import com.hazelcast.core.MapLoader; | |
| import java.util.ArrayList; | |
| import java.util.Collection; | |
| import java.util.List; | |
| import java.util.Map; | |
| public class MapLoaderTest { | |
| public static void main(String[] args) { | |
| Config config = new Config(); | |
| config.setProperty("hazelcast.partition.count", "1"); | |
| config.setProperty("hazelcast.map.load.chunk.size", "5000"); | |
| MapConfig mapConfig = config.getMapConfig("map"); | |
| MapStoreConfig mapStoreConfig = new MapStoreConfig(); | |
| mapStoreConfig.setEnabled(true); | |
| mapStoreConfig.setImplementation(new EventMapLoader()); | |
| mapStoreConfig.setWriteDelaySeconds(5); | |
| mapStoreConfig.setWriteBatchSize(5000); | |
| mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER); | |
| mapConfig.setMapStoreConfig(mapStoreConfig); | |
| mapConfig.setInMemoryFormat(InMemoryFormat.OBJECT); | |
| HazelcastInstance instance = Hazelcast.newHazelcastInstance(config); | |
| IMap<Object, Object> map = instance.getMap("map"); | |
| System.exit(0); | |
| } | |
| static class EventMapLoader implements MapLoader { | |
| private final List keyList; | |
| public EventMapLoader() { | |
| keyList = new ArrayList(); | |
| for (int i = 0; i < 20000; i++) { | |
| keyList.add(i); | |
| } | |
| } | |
| @Override | |
| public Object load(Object key) { | |
| System.err.println("load, key: " + key); | |
| return null; | |
| } | |
| @Override | |
| public Map loadAll(Collection keys) { | |
| System.err.println("loadAll, keys.size: " + keys.size()); | |
| return null; | |
| } | |
| @Override | |
| public Iterable loadAllKeys() { | |
| return keyList; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment