public HazelcastLockMemory(IMap<String, LockValue> locksMap) { super(); this.locksMap = locksMap; LOG.info("HazelcastLockMemory ----- MAP_ID: " + locksMap.getId()); LOG.info("HazelcastLockMemory ----- MAP_NAME: " + locksMap.getName()); LOG.info("HazelcastLockMemory ----- MAP_STRING: " + locksMap.toString()); LOG.info("HazelcastLockMemory ----- MAP_INSTANCE_TYPE: " + locksMap.getInstanceType()); MapConfig mapConf = Hazelcast.getConfig().getMapConfig(DistributedMapNames.MAP.LOCK_MEMORY_LOCKS_MAP.toString()); MapStoreConfig mapStoreConf = mapConf.getMapStoreConfig(); if(mapStoreConf == null){ LOG.info("HazelcastLockMemory ----- MAPSTORE NULL"); }else{ LOG.info("HazelcastLockMemory ----- MAPSTORE IMPL: " + mapStoreConf.getImplementation()); } }
/** * Requires a hazelcast map. * * @param fileTrackerMemory * @param logTypeSet * stores the log types * @param agentSet */ public HazelcastFileTrackerStorage( IMap<FileTrackingStatusKey, FileTrackingStatus> fileTrackerMemory, IMap<String, LogTypeContact> logTypeSet, IMap<String, AgentContact> agentSet) { this.fileTrackerMemoryMap = fileTrackerMemory; this.logTypeSet = logTypeSet; this.agentSet = agentSet; MapConfig mapConf = Hazelcast.getConfig().getMapConfig( DistributedMapNames.MAP.FILE_TRACKER_MAP.toString()); MapStoreConfig mapStoreConf = mapConf.getMapStoreConfig(); if (mapStoreConf == null) { LOG.info("HazelcastFileTrackerStorage ----- MAPSTORE NULL"); } else { LOG.info("HazelcastFileTrackerStorage ----- MAPSTORE IMPL: " + mapStoreConf.getImplementation()); } }
@Before public void setup() { factory = new JetTestInstanceFactory(); JetConfig config = new JetConfig(); config.getInstanceConfig().setCooperativeThreadCount(LOCAL_PARALLELISM); // force snapshots to fail by adding a failing map store configuration for snapshot data maps MapConfig mapConfig = new MapConfig(SnapshotRepository.SNAPSHOT_DATA_NAME_PREFIX + '*'); MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig(); mapStoreConfig.setEnabled(true); mapStoreConfig.setImplementation(new FailingMapStore()); config.getHazelcastConfig().addMapConfig(mapConfig); JetInstance[] instances = factory.newMembers(config, 2); instance1 = instances[0]; }
public DistMapConfig setup(Config cfg, String name, Object storeImplementation) { MapConfig mapConfig = new MapConfig(); //TODO: Refactor the config options mapConfig.setName(name); mapConfig.setBackupCount(1); if (storeImplementation != null) { MaxSizeConfig maxSizeConfig = new MaxSizeConfig(); //todo Refactor this to config maxSizeConfig.setSize(1000); MapStoreConfig store = new MapStoreConfig(); store.setImplementation(storeImplementation); mapConfig.setMaxSizeConfig(maxSizeConfig); mapConfig.setMapStoreConfig(store); } cfg.addMapConfig(mapConfig); return this; }
@Verify(global = false) public void verify() { if (isClient(targetInstance)) { return; } MapConfig mapConfig = targetInstance.getConfig().getMapConfig(name); logger.info(name + ": MapConfig: " + mapConfig); MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig(); logger.info(name + ": MapStoreConfig: " + mapStoreConfig); int sleepSeconds = mapConfig.getTimeToLiveSeconds() * 2 + mapStoreConfig.getWriteDelaySeconds() * 2; logger.info("Sleeping for " + sleepSeconds + " seconds to wait for delay and TTL values."); sleepSeconds(sleepSeconds); MapStoreWithCounterPerKey mapStore = (MapStoreWithCounterPerKey) mapStoreConfig.getImplementation(); logger.info(name + ": map size = " + map.size()); logger.info(name + ": map store = " + mapStore); logger.info(name + ": Checking if some keys where stored more than once"); for (Object key : mapStore.keySet()) { assertEquals("There were multiple calls to MapStore.store", 1, mapStore.valueOf(key)); } }
public MapConfig create() { MapConfig mapConfig = new MapConfig(); mapConfig.setName(HazelcastData.INVENTORY_ITEM_AGGREGATE_HISTORY.name()); mapConfig.setInMemoryFormat(MapConfig.DEFAULT_IN_MEMORY_FORMAT); MapStoreConfig mapStoreConfig = new MapStoreConfig(); mapStoreConfig.setImplementation(mapStore); mapStoreConfig.setEnabled(true); mapStoreConfig.setWriteDelaySeconds(writeDelaySeconds); /* writeDelaySeconds > 0 means write-behind. */ mapConfig.setMapStoreConfig(mapStoreConfig); return mapConfig; }
protected Config newConfig(String mapName, Object storeImpl, int writeDelaySeconds) { Config config = new XmlConfigBuilder().build(); MapConfig mapConfig = config.getMapConfig(mapName); MapStoreConfig mapStoreConfig = new MapStoreConfig(); mapStoreConfig.setImplementation(storeImpl); mapStoreConfig.setWriteDelaySeconds(writeDelaySeconds); mapConfig.setMapStoreConfig(mapStoreConfig); return config; }
@Test /** * Issue 816. */ public void testMapRemoveWithWriteBehindMapStore() { Config c = new Config(); TestMapStore mapStore = new TestMapStore(); mapStore.setLoadAllKeys(false); for (int i = 1; i < 5; i++) { mapStore.store(i, "value" + i); } c.getMapConfig("test").setMapStoreConfig(new MapStoreConfig().setEnabled(true) .setWriteDelaySeconds(100).setImplementation(mapStore)); HazelcastInstance hz = Hazelcast.newHazelcastInstance(c); Map map = hz.getMap("test"); assertEquals("value1", map.get(1)); assertEquals("value1", map.remove(1)); assertNull(map.get(1)); assertEquals("value2", map.get(2)); assertEquals("value2", map.remove(2)); assertFalse(map.containsKey(2)); assertEquals("value3", map.get(3)); assertEquals("value3", map.remove(3)); assertNull(map.put(3, "valuex")); assertEquals("value4", map.get(4)); assertEquals("value4", map.remove(4)); assertNull(map.remove(4)); }
public DistributedTableMetadataManager(HazelcastConnection hazelcastConnection, ElasticsearchConnection elasticsearchConnection) { this.hazelcastConnection = hazelcastConnection; MapStoreConfig mapStoreConfig = new MapStoreConfig(); mapStoreConfig.setFactoryImplementation(TableMapStore.factory(elasticsearchConnection)); mapStoreConfig.setEnabled(true); mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER); MapConfig mapConfig = new MapConfig(DATA_MAP); mapConfig.setMapStoreConfig(mapStoreConfig); mapConfig.setReadBackupData(true); hazelcastConnection.getHazelcastConfig().addMapConfig(mapConfig); DistributedCache.setupConfig(hazelcastConnection); }
public static void assertMapStoreConfiguration(Logger logger, HazelcastInstance instance, String mapName, Class<? extends MapStore> mapStoreImplementation) { if (isClient(instance)) { return; } String expectedMapStoreName = mapStoreImplementation.getName(); MapStoreConfig mapStoreConfig = instance.getConfig().getMapConfig(mapName).getMapStoreConfig(); assertMapStoreConfig(expectedMapStoreName, mapName, mapStoreConfig, logger); assertMapStoreClassName(expectedMapStoreName, mapName, mapStoreConfig); assertMapStoreImplementation(expectedMapStoreName, mapName, mapStoreConfig, mapStoreImplementation); }
private static void assertMapStoreConfig(String expectedMapStoreName, String mapName, MapStoreConfig mapStoreConfig, Logger logger) { if (mapStoreConfig == null) { throw new TestException("MapStore for map %s needs to be configured with class %s, but was not configured at all", mapName, expectedMapStoreName); } logger.info(format("MapStore configuration for map %s: %s", mapName, mapStoreConfig)); if (!mapStoreConfig.isEnabled()) { throw new TestException("MapStore for map %s needs to be configured with class %s, but was not enabled", mapName, expectedMapStoreName); } }
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); } }
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); } }
@Verify(global = false) public void verify() { if (isClient(targetInstance)) { return; } MapStoreConfig mapStoreConfig = targetInstance.getConfig().getMapConfig(name).getMapStoreConfig(); int writeDelayMs = (int) TimeUnit.SECONDS.toMillis(mapStoreConfig.getWriteDelaySeconds()); int sleepMs = mapStoreMaxDelayMs * 2 + maxTTLExpiryMs * 2 + (writeDelayMs * 2); logger.info("Sleeping for " + TimeUnit.MILLISECONDS.toSeconds(sleepMs) + " seconds to wait for delay and TTL values."); sleepMillis(sleepMs); final MapStoreWithCounter mapStore = (MapStoreWithCounter) mapStoreConfig.getImplementation(); logger.info(name + ": map size = " + map.size()); logger.info(name + ": map store = " + mapStore); assertTrueEventually(new AssertTask() { @Override public void run() throws Exception { for (Integer key : map.localKeySet()) { assertEquals(map.get(key), mapStore.get(key)); } assertEquals("Map entrySets should be equal", map.getAll(map.localKeySet()).entrySet(), mapStore.entrySet()); for (int key = putTTlKeyDomain; key < putTTlKeyDomain + putTTlKeyRange; key++) { assertNull(name + ": TTL key should not be in the map", map.get(key)); } } }); }
public KfkaManagerImpl(HazelcastInstance hazelcastInstance, KfkaMapStore<? extends KfkaMessage> mapStore, KfkaCounterStore counterStore, KfkaConfig kfkaCfg) { this.kfkaCfg = kfkaCfg; final MapConfig hzcfg = hazelcastInstance.getConfig().getMapConfig(kfkaCfg.getName()); hzcfg.setEvictionPolicy(EvictionPolicy.NONE); final MapStoreConfig mapCfg = hzcfg.getMapStoreConfig(); mapCfg.setImplementation(mapStore); mapCfg.setEnabled(kfkaCfg.isPersistent()); mapCfg.setWriteBatchSize(kfkaCfg.getBatchSize()); mapCfg.setWriteDelaySeconds(kfkaCfg.getWriteDelay()); mapCfg.setInitialLoadMode(kfkaCfg.getInitialLoadMode()); this.mapStore = mapStore; this.messages = hazelcastInstance.getMap(kfkaCfg.getName()); this.counter = hazelcastInstance.getAtomicLong(kfkaCfg.getName()); messages.addIndex("id", true); messages.addIndex("timestamp", true); messages.addEntryListener(new EntryAddedListener<Long, KfkaMessage>() { @Override public void entryAdded(EntryEvent<Long, KfkaMessage> event) { logger.debug("Received message for dispatch: {}", event.getValue()); final Iterator<Entry<KfkaMessageListener, KfkaPredicate>> iter = msgListeners.entrySet().iterator(); while (iter.hasNext()) { final Entry<KfkaMessageListener, KfkaPredicate> e = iter.next(); final KfkaPredicate predicate = e.getValue(); final KfkaMessage msg = event.getValue(); // Check if message should be included if (predicate.toGuavaPredicate().apply(msg)) { final KfkaMessageListener l = e.getKey(); logger.debug("Sending message {} to {}", event.getValue().getId(), e.getKey()); l.onMessage(event.getValue()); } } } }, true); if (counter.get() == 0) { final long initialValue = counterStore.latest(); logger.info("Setting current KFKA message ID counter to {}", initialValue); counter.compareAndSet(0, initialValue); } }
public static void main(String[] args) throws InterruptedException { final Config cfg = new Config(); cfg.setInstanceName(UUID.randomUUID().toString()); final Properties props = new Properties(); props.put("hazelcast.rest.enabled", false); props.put("hazelcast.logging.type", "slf4j"); props.put("hazelcast.connect.all.wait.seconds", 45); props.put("hazelcast.operation.call.timeout.millis", 30000); // group configuration cfg.setGroupConfig(new GroupConfig(args[0], args[1])); // network configuration initialization final NetworkConfig netCfg = new NetworkConfig(); netCfg.setPortAutoIncrement(true); netCfg.setPort(5701); // multicast final MulticastConfig mcCfg = new MulticastConfig(); mcCfg.setEnabled(false); // tcp final TcpIpConfig tcpCfg = new TcpIpConfig(); tcpCfg.addMember("127.0.0.1"); tcpCfg.setEnabled(true); // network join configuration final JoinConfig joinCfg = new JoinConfig(); joinCfg.setMulticastConfig(mcCfg); joinCfg.setTcpIpConfig(tcpCfg); netCfg.setJoin(joinCfg); // ssl netCfg.setSSLConfig(new SSLConfig().setEnabled(false)); // creating cassandra client final CassandraClient dao = new CassandraClient(); dao.initialize(args[2]); final HazelcastMapStore mapStore = new HazelcastMapStore(User.class); mapStore.setDao(dao); // Adding mapstore final MapConfig mapCfg = cfg.getMapConfig("cassandra-map-store"); final MapStoreConfig mapStoreCfg = new MapStoreConfig(); mapStoreCfg.setImplementation(mapStore); mapStoreCfg.setWriteDelaySeconds(1); // to load all map at same time mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER); mapCfg.setMapStoreConfig(mapStoreCfg); cfg.addMapConfig(mapCfg); HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg); // TERM signal processing Runtime.getRuntime().addShutdownHook(new Thread(() -> { Hazelcast.shutdownAll(); })); }
public Config getConfig() { final Config cfg = new Config(); cfg.setInstanceName(instanceName); final Properties props = new Properties(); props.put("hazelcast.rest.enabled", false); props.put("hazelcast.logging.type", "slf4j"); props.put("hazelcast.connect.all.wait.seconds", 45); props.put("hazelcast.operation.call.timeout.millis", 30000); // group configuration cfg.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME, Constants.HC_GROUP_PASSWORD)); // network configuration initialization final NetworkConfig netCfg = new NetworkConfig(); netCfg.setPortAutoIncrement(true); netCfg.setPort(Constants.HC_PORT); // multicast final MulticastConfig mcCfg = new MulticastConfig(); mcCfg.setEnabled(false); // tcp final TcpIpConfig tcpCfg = new TcpIpConfig(); tcpCfg.addMember("127.0.0.1"); tcpCfg.setEnabled(true); // network join configuration final JoinConfig joinCfg = new JoinConfig(); joinCfg.setMulticastConfig(mcCfg); joinCfg.setTcpIpConfig(tcpCfg); netCfg.setJoin(joinCfg); // ssl netCfg.setSSLConfig(new SSLConfig().setEnabled(false)); // Adding mapstore final MapConfig mapCfg = cfg.getMapConfig(storeType); final MapStoreConfig mapStoreCfg = new MapStoreConfig(); mapStoreCfg.setImplementation(store); mapStoreCfg.setWriteDelaySeconds(1); // to load all map at same time mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER); mapCfg.setMapStoreConfig(mapStoreCfg); cfg.addMapConfig(mapCfg); return cfg; }