public MapStoreConfig asMapStoreConfig(SerializationService serializationService) { MapStoreConfig config = new MapStoreConfig(); config.setClassName(className); config.setEnabled(enabled); config.setFactoryClassName(factoryClassName); config.setInitialLoadMode(InitialLoadMode.valueOf(initialLoadMode)); config.setProperties(properties); config.setWriteBatchSize(writeBatchSize); config.setWriteCoalescing(writeCoalescing); config.setWriteDelaySeconds(writeDelaySeconds); config.setImplementation(serializationService.toObject(implementation)); config.setFactoryImplementation(serializationService.toObject(factoryImplementation)); return config; }
public MapStoreConfig(MapStoreConfig config) { enabled = config.isEnabled(); className = config.getClassName(); implementation = config.getImplementation(); factoryClassName = config.getFactoryClassName(); factoryImplementation = config.getFactoryImplementation(); writeDelaySeconds = config.getWriteDelaySeconds(); writeBatchSize = config.getWriteBatchSize(); initialLoadMode = config.getInitialLoadMode(); writeCoalescing = config.isWriteCoalescing(); properties.putAll(config.getProperties()); }
private static boolean isWriteBehindMapStoreEnabled(MapStoreConfig mapStoreConfig) { return mapStoreConfig != null && mapStoreConfig.isEnabled() && mapStoreConfig.getWriteDelaySeconds() > 0; }
private MapStoreConfig createMapStoreConfig(Node node) { MapStoreConfig mapStoreConfig = new MapStoreConfig(); NamedNodeMap attributes = node.getAttributes(); for (int a = 0; a < attributes.getLength(); a++) { String value = getTextContent(att).trim(); if ("enabled".equals(att.getNodeName())) { mapStoreConfig.setEnabled(getBooleanValue(value)); } else if ("initial-mode".equals(att.getNodeName())) { MapStoreConfig.InitialLoadMode mode = MapStoreConfig.InitialLoadMode .valueOf(upperCaseInternal(getTextContent(att))); mapStoreConfig.setInitialLoadMode(mode); String nodeName = cleanNodeName(n); if ("class-name".equals(nodeName)) { mapStoreConfig.setClassName(getTextContent(n).trim()); } else if ("factory-class-name".equals(nodeName)) { mapStoreConfig.setFactoryClassName(getTextContent(n).trim()); } else if ("write-delay-seconds".equals(nodeName)) { mapStoreConfig.setWriteDelaySeconds(getIntegerValue("write-delay-seconds", getTextContent(n).trim() )); } else if ("write-batch-size".equals(nodeName)) { mapStoreConfig.setWriteBatchSize(getIntegerValue("write-batch-size", getTextContent(n).trim() )); } else if ("write-coalescing".equals(nodeName)) { String writeCoalescing = getTextContent(n).trim(); if (isNullOrEmpty(writeCoalescing)) { mapStoreConfig.setWriteCoalescing(MapStoreConfig.DEFAULT_WRITE_COALESCING); } else { mapStoreConfig.setWriteCoalescing(getBooleanValue(writeCoalescing));
mapConfig.setName("userMap"); final MapStoreConfig mapStoreConfig = new MapStoreConfig(); mapStoreConfig.setEnabled(true); mapStoreConfig.setWriteDelaySeconds(60); mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.LAZY); mapStoreConfig.setImplementation(userMapStore); mapConfig.setMapStoreConfig(mapStoreConfig); config.addMapConfig(mapConfig);
public static void main(String[] args) { // Start a member with no explicit configuration HazelcastInstance instance = Hazelcast.newHazelcastInstance(); ILogger logger = instance.getLoggingService().getLogger(ClientDynamicConfig.class); // Start a client -- we will be using the map to access & configure data structures HazelcastInstance client = HazelcastClient.newHazelcastClient(); // Obtain a map IMap<String, String> defaultMap = client.getMap("defaultMap"); // no data has been added yet, so get("1") will return null logger.info("defaultMap[\"1\"] = " + defaultMap.get("1")); // Another application will be using a map with a map loader and no backups // Wildcards also work for dynamically added data structure configurations MapConfig mapWithLoaderConfig = new MapConfig("map-with-loader-*").setBackupCount(0); mapWithLoaderConfig.getMapStoreConfig() .setEnabled(true) .setInitialLoadMode(EAGER) .setClassName("EchoMapLoader"); // add the configuration to the already running member client.getConfig().addMapConfig(mapWithLoaderConfig); IMap<String, String> mapWithLoader1 = client.getMap("map-with-loader-1"); logger.info("mapWithLoader1[\"1\"] = " + mapWithLoader1.get("1") + " (loaded from configured map loader)"); client.shutdown(); instance.shutdown(); }
@Verify(global = false) public void verify() throws Exception { try{ MapStoreConfig mapStoreConfig = targetInstance.getConfig().getMapConfig(basename).getMapStoreConfig(); final int writeDelaySeconds = mapStoreConfig.getWriteDelaySeconds(); Thread.sleep(mapStoreMaxDelayMs*2 + maxTTLExpireyMs*2 + ((writeDelaySeconds*2)*1000)); final MapStoreWithCounter mapStore = (MapStoreWithCounter) mapStoreConfig.getImplementation(); final IMap map = targetInstance.getMap(basename); System.out.println(basename+ ": map size =" + map.size() ); System.out.println(basename+ ": map local =" + map.getAll(map.localKeySet()).entrySet() ); System.out.println(basename+ ": map Store =" + mapStore.store.entrySet() ); System.out.println(basename+ ": "+ mapStore); for(Object k: map.localKeySet()){ assertEquals( map.get(k), mapStore.store.get(k) ); } assertEquals("sets should be equals", map.getAll(map.localKeySet()).entrySet(), mapStore.store.entrySet()); for(int k = putTTlKeyDomain; k < putTTlKeyDomain + putTTlKeyRange; k++){ assertNull("TTL key should not be in the map", map.get(k) ); } }catch(UnsupportedOperationException e){} }
public static void main(String[] args) { Config config = new Config(); final MapConfig supplementsMapConfig = config.getMapConfig("supplements"); final MapStoreConfig mapStoreConfig = supplementsMapConfig.getMapStoreConfig(); mapStoreConfig .setEnabled(true) .setClassName("com.hazelcast.loader.MongoMapStore") .setProperty("mongo.url", "mongodb://localhost:27017") .setProperty("mongo.db", "mydb") .setProperty("mongo.collection", "supplements"); final HazelcastInstance hazelcastInstance = newHazelcastInstance(config); new ReadWriteThroughCache(hazelcastInstance).run(); } }
private static Config createNewConfig(String mapName) { SimpleStore simpleStore = new SimpleStore(); MapStoreConfig mapStoreConfig = new MapStoreConfig(); mapStoreConfig.setImplementation(simpleStore); mapStoreConfig.setWriteDelaySeconds(0); XmlConfigBuilder configBuilder = new XmlConfigBuilder(); Config config = configBuilder.build(); MapConfig mapConfig = config.getMapConfig(mapName); mapConfig.setMapStoreConfig(mapStoreConfig); return config; }
Config config = new Config(); MapConfig mapConfig = config.getMapConfig("map"); MapStoreConfig mapStoreConfig = new MapStoreConfig(); mapStoreConfig.setEnabled(true).setClassName(IncrementerPostProcessingMapStore.class.getName()); mapConfig.setMapStoreConfig(mapStoreConfig);
.setEnabled(true) .setClassName("com.networknt.oauth.cache.ServiceMapStore"); .setEnabled(true) .setClassName("com.networknt.oauth.cache.ServiceEndpointMapStore"); .setEnabled(true) .setClassName("com.networknt.oauth.cache.ClientMapStore"); .setEnabled(true) .setClassName("com.networknt.oauth.cache.RefreshTokenMapStore"); userConfig.setBackupCount(1); userConfig.getMapStoreConfig() .setEnabled(true) .setClassName("com.networknt.oauth.cache.UserMapStore"); userConfig.addMapIndexConfig(new MapIndexConfig("email", true)); providerConfig.setNearCacheConfig(providerCacheConfig); providerConfig.getMapStoreConfig() .setEnabled(true) .setClassName("com.networknt.oauth.cache.ProviderMapStore");
Config config = new Config(); .... MapConfig mapCfg = new MapConfig(); mapCfg.setName("default"); mapCfg.setBackupCount(2); mapCfg.getMaxSizeConfig().setSize(10000); mapCfg.setTimeToLiveSeconds(300); MapStoreConfig mapStoreCfg = new MapStoreConfig(); mapStoreCfg.setClassName(MyMapStore.class.getName()).setEnabled(true); mapCfg.setMapStoreConfig(mapStoreCfg); // use near cache if needed NearCacheConfig nearCacheConfig = new NearCacheConfig(); nearCacheConfig.setMaxSize(1000).setMaxIdleSeconds(120).setTimeToLiveSeconds(300); mapCfg.setNearCacheConfig(nearCacheConfig); config.addMapConfig(mapCfg); Hazelcast.newHazelcastInstance(config);
private static void assertMapStoreImplementation(String expectedMapStoreName, String mapName, MapStoreConfig mapStoreConfig, Class<? extends MapStore> mapStoreImplementation) { Object configuredMapStoreImpl = mapStoreConfig.getImplementation(); if (configuredMapStoreImpl == null) { if (mapStoreConfig.getInitialLoadMode().equals(LAZY)) { return; } throw new TestException("MapStore for map %s needs to be initialized with class %s, but was null (%s)", mapName, expectedMapStoreName, mapStoreConfig); } if (!configuredMapStoreImpl.getClass().equals(mapStoreImplementation)) { throw new TestException("MapStore for map %s needs to be initialized with class %s, but was %s (%s)", mapName, expectedMapStoreName, configuredMapStoreImpl.getClass().getName(), mapStoreConfig); } } }
@Override public IdentifiedDataSerializable createNew(Integer arg) { return new MapStoreConfig(); } };
private void initializeMapStoreLoad() { MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig(); if (mapStoreConfig != null && mapStoreConfig.isEnabled()) { MapStoreConfig.InitialLoadMode initialLoadMode = mapStoreConfig.getInitialLoadMode(); if (MapStoreConfig.InitialLoadMode.EAGER.equals(initialLoadMode)) { waitUntilLoaded(); } } }
private static int getWriteDelaySeconds(MapStoreContext mapStoreContext) { MapStoreConfig mapStoreConfig = mapStoreContext.getMapStoreConfig(); return mapStoreConfig.getWriteDelaySeconds(); }
private static Object getStoreFromImplementationOrNull(MapStoreConfig mapStoreConfig) { return mapStoreConfig.getImplementation(); }
class Foo{ private InitialLoadMode initialLoadMode = InitialLoadMode.EAGER; final Config config= new Config(); final MapConfig mapConfig = config.getMapConfig("*"); final MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig(); { mapStoreConfig.setInitialLoadMode(initialLoadMode); } }
private static void setStoreImplToWritableMapStoreConfig(NodeEngine nodeEngine, String mapName, Object store) { final Config config = nodeEngine.getConfig(); // get writable config (not read-only one) from node engine. final MapConfig mapConfig = config.getMapConfig(mapName); final MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig(); mapStoreConfig.setImplementation(store); }
private static void assertMapStoreClassName(String expectedMapStoreName, String mapName, MapStoreConfig mapStoreConfig) { String configuredMapStoreClassName = mapStoreConfig.getClassName(); if (configuredMapStoreClassName == null) { throw new TestException("MapStore for map %s needs to be configured with class %s, but was null", mapName, expectedMapStoreName); } if (!expectedMapStoreName.equals(configuredMapStoreClassName)) { throw new TestException("MapStore for map %s needs to be configured with class %s, but was %s", mapName, expectedMapStoreName, configuredMapStoreClassName); } }