@Test public void testPut() throws Exception { Config config = new Config(); FactoryImpl mockFactory = mock(FactoryImpl.class); Node node = new Node(mockFactory, config); node.serviceThread = Thread.currentThread(); CMap cmap = new CMap(node.concurrentMapManager, "c:myMap"); Object key = "1"; Object value = "istanbul"; Data dKey = toData(key); Data dKey2 = toData("2"); Data dValue = toData(value); cmap.put(newPutRequest(dKey, dValue)); assertTrue(cmap.mapRecords.containsKey(toData(key))); Data actualValue = cmap.get(newGetRequest(dKey)); assertThat(toObject(actualValue), equalTo(value)); assertEquals(1, cmap.mapRecords.size()); Record record = cmap.getRecord(dKey); assertNotNull(record); assertTrue(record.isActive()); assertTrue(record.isValid()); assertEquals(1, cmap.size()); cmap.remove(newRemoveRequest(dKey)); assertTrue(Clock.currentTimeMillis() - record.getRemoveTime() < 100); assertEquals(1, cmap.mapRecords.size()); record = cmap.getRecord(dKey); assertNotNull(record); assertFalse(record.isActive()); assertFalse(record.isValid()); assertEquals(0, cmap.size()); cmap.put(newPutRequest(dKey, dValue, 1000)); cmap.put(newPutIfAbsentRequest(dKey2, dValue, 1000)); assertEquals(0, record.getRemoveTime()); assertTrue(cmap.mapRecords.containsKey(toData(key))); assertTrue(cmap.mapRecords.containsKey(toData("2"))); Thread.sleep(1500); assertEquals(0, cmap.size()); assertFalse(cmap.containsKey(newContainsRequest(dKey, null))); assertFalse(cmap.containsKey(newContainsRequest(dKey2, null))); node.connectionManager.shutdown(); }
public void put(Request req) { long now = Clock.currentTimeMillis(); boolean sendEvictEvent = false; Record evictedRecord = null; if (req.value == null) { req.value = new Data(); } Record record = getRecord(req); if (record != null && !record.isValid(now)) { if (record.isActive() && record.isEvictable()) { sendEvictEvent = true; evictedRecord = createNewTransientRecord(record.getKeyData(), record.getValueData()); } record.setValueData(null); record.setMultiValues(null); } if (req.operation == CONCURRENT_MAP_PUT_IF_ABSENT) { if (!isApplicable(CONCURRENT_MAP_PUT_IF_ABSENT, req, now)) { req.clearForResponse(); req.response = record.getValueData(); return; } } else if (req.operation == CONCURRENT_MAP_REPLACE_IF_NOT_NULL) { if (!isApplicable(CONCURRENT_MAP_REPLACE_IF_NOT_NULL, req, now)) { req.value = null; return; } } Data oldValue = null; if (record == null) { record = createAndAddNewRecord(req.key, req.value); } else { markAsActive(record); oldValue = (record.isValid(now)) ? record.getValueData() : null; record.setValueData(req.value); record.incrementVersion(); record.setLastUpdated(); } if (req.ttl > 0 && req.ttl < Long.MAX_VALUE) { record.setTTL(req.ttl); ttlPerRecord = true; } if (sendEvictEvent) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_EVICTED, null, evictedRecord, req.caller); } if (oldValue == null) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_ADDED, null, record, req.caller); } else { fireInvalidation(record); concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_UPDATED, oldValue, record, req.caller); } if (req.txnId != -1 || req.operation == ClusterOperation.CONCURRENT_MAP_PUT_AND_UNLOCK) { unlock(record, req); } record.setIndexes(req.indexes, req.indexTypes); updateIndexes(record); markAsDirty(record, false); req.clearForResponse(); req.version = record.getVersion(); if (localUpdateListener != null && req.txnId != Long.MIN_VALUE) { localUpdateListener.recordUpdated(record); } if (req.operation == CONCURRENT_MAP_SET || req.operation == CONCURRENT_MAP_TRY_PUT || req.operation == CONCURRENT_MAP_PUT_TRANSIENT || req.operation == CONCURRENT_MAP_REPLACE_IF_SAME || req.operation == CONCURRENT_MAP_PUT_AND_UNLOCK) { req.response = Boolean.TRUE; } else { req.response = oldValue; } }
CMap { public void put(Request req) { long now = Clock.currentTimeMillis(); boolean sendEvictEvent = false; Record evictedRecord = null; if (req.value == null) { req.value = new Data(); } Record record = getRecord(req); if (record != null && !record.isValid(now)) { if (record.isActive() && record.isEvictable()) { sendEvictEvent = true; evictedRecord = createNewTransientRecord(record.getKeyData(), record.getValueData()); } record.setValueData(null); record.setMultiValues(null); } if (req.operation == CONCURRENT_MAP_PUT_IF_ABSENT) { if (!isApplicable(CONCURRENT_MAP_PUT_IF_ABSENT, req, now)) { req.clearForResponse(); req.response = record.getValueData(); return; } } else if (req.operation == CONCURRENT_MAP_REPLACE_IF_NOT_NULL) { if (!isApplicable(CONCURRENT_MAP_REPLACE_IF_NOT_NULL, req, now)) { req.value = null; return; } } Data oldValue = null; if (record == null) { record = createAndAddNewRecord(req.key, req.value); } else { markAsActive(record); oldValue = (record.isValid(now)) ? record.getValueData() : null; record.setValueData(req.value); record.incrementVersion(); record.setLastUpdated(); } if (req.ttl > 0 && req.ttl < Long.MAX_VALUE) { record.setTTL(req.ttl); ttlPerRecord = true; } if (sendEvictEvent) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_EVICTED, null, evictedRecord, req.caller); } if (oldValue == null) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_ADDED, null, record, req.caller); } else { fireInvalidation(record); concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_UPDATED, oldValue, record, req.caller); } if (req.txnId != -1 || req.operation == ClusterOperation.CONCURRENT_MAP_PUT_AND_UNLOCK) { unlock(record, req); } record.setIndexes(req.indexes, req.indexTypes); updateIndexes(record); markAsDirty(record, false); req.clearForResponse(); req.version = record.getVersion(); if (localUpdateListener != null && req.txnId != Long.MIN_VALUE) { localUpdateListener.recordUpdated(record); } if (req.operation == CONCURRENT_MAP_SET || req.operation == CONCURRENT_MAP_TRY_PUT || req.operation == CONCURRENT_MAP_PUT_TRANSIENT || req.operation == CONCURRENT_MAP_REPLACE_IF_SAME || req.operation == CONCURRENT_MAP_PUT_AND_UNLOCK) { req.response = Boolean.TRUE; } else { req.response = oldValue; } } }
CMap { public void put(Request req) { long now = Clock.currentTimeMillis(); boolean sendEvictEvent = false; Record evictedRecord = null; if (req.value == null) { req.value = new Data(); } Record record = getRecord(req); if (record != null && !record.isValid(now)) { if (record.isActive() && record.isEvictable()) { sendEvictEvent = true; evictedRecord = createNewTransientRecord(record.getKeyData(), record.getValueData()); } record.setValueData(null); record.setMultiValues(null); } if (req.operation == CONCURRENT_MAP_PUT_IF_ABSENT) { if (!isApplicable(CONCURRENT_MAP_PUT_IF_ABSENT, req, now)) { req.clearForResponse(); req.response = record.getValueData(); return; } } else if (req.operation == CONCURRENT_MAP_REPLACE_IF_NOT_NULL) { if (!isApplicable(CONCURRENT_MAP_REPLACE_IF_NOT_NULL, req, now)) { req.value = null; return; } } Data oldValue = null; if (record == null) { record = createAndAddNewRecord(req.key, req.value); } else { markAsActive(record); oldValue = (record.isValid(now)) ? record.getValueData() : null; record.setValueData(req.value); record.incrementVersion(); record.setLastUpdated(); } if (req.ttl > 0 && req.ttl < Long.MAX_VALUE) { record.setTTL(req.ttl); ttlPerRecord = true; } if (sendEvictEvent) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_EVICTED, null, evictedRecord, req.caller); } if (oldValue == null) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_ADDED, null, record, req.caller); } else { fireInvalidation(record); concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_UPDATED, oldValue, record, req.caller); } if (req.txnId != -1 || req.operation == ClusterOperation.CONCURRENT_MAP_PUT_AND_UNLOCK) { unlock(record, req); } record.setIndexes(req.indexes, req.indexTypes); updateIndexes(record); markAsDirty(record, false); req.clearForResponse(); req.version = record.getVersion(); if (localUpdateListener != null && req.txnId != Long.MIN_VALUE) { localUpdateListener.recordUpdated(record); } if (req.operation == CONCURRENT_MAP_SET || req.operation == CONCURRENT_MAP_TRY_PUT || req.operation == CONCURRENT_MAP_PUT_TRANSIENT || req.operation == CONCURRENT_MAP_REPLACE_IF_SAME || req.operation == CONCURRENT_MAP_PUT_AND_UNLOCK) { req.response = Boolean.TRUE; } else { req.response = oldValue; } } CMap(ConcurrentMapManager concurrentMapManager, String name); }
CMap { public void put(Request req) { long now = Clock.currentTimeMillis(); boolean sendEvictEvent = false; Record evictedRecord = null; if (req.value == null) { req.value = new Data(); } Record record = getRecord(req); if (record != null && !record.isValid(now)) { if (record.isActive() && record.isEvictable()) { sendEvictEvent = true; evictedRecord = createNewTransientRecord(record.getKeyData(), record.getValueData()); } record.setValueData(null); record.setMultiValues(null); } if (req.operation == CONCURRENT_MAP_PUT_IF_ABSENT) { if (!isApplicable(CONCURRENT_MAP_PUT_IF_ABSENT, req, now)) { req.clearForResponse(); req.response = record.getValueData(); return; } } else if (req.operation == CONCURRENT_MAP_REPLACE_IF_NOT_NULL) { if (!isApplicable(CONCURRENT_MAP_REPLACE_IF_NOT_NULL, req, now)) { req.value = null; return; } } Data oldValue = null; if (record == null) { record = createAndAddNewRecord(req.key, req.value); } else { markAsActive(record); oldValue = (record.isValid(now)) ? record.getValueData() : null; record.setValueData(req.value); record.incrementVersion(); record.setLastUpdated(); } if (req.ttl > 0 && req.ttl < Long.MAX_VALUE) { record.setTTL(req.ttl); ttlPerRecord = true; } if (sendEvictEvent) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_EVICTED, null, evictedRecord, req.caller); } if (oldValue == null) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_ADDED, null, record, req.caller); } else { fireInvalidation(record); concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_UPDATED, oldValue, record, req.caller); } if (req.txnId != -1 || req.operation == ClusterOperation.CONCURRENT_MAP_PUT_AND_UNLOCK) { unlock(record, req); } record.setIndexes(req.indexes, req.indexTypes); updateIndexes(record); markAsDirty(record, false); req.clearForResponse(); req.version = record.getVersion(); if (localUpdateListener != null && req.txnId != Long.MIN_VALUE) { localUpdateListener.recordUpdated(record); } if (req.operation == CONCURRENT_MAP_SET || req.operation == CONCURRENT_MAP_TRY_PUT || req.operation == CONCURRENT_MAP_PUT_TRANSIENT || req.operation == CONCURRENT_MAP_REPLACE_IF_SAME || req.operation == CONCURRENT_MAP_PUT_AND_UNLOCK) { req.response = Boolean.TRUE; } else { req.response = oldValue; } } CMap(ConcurrentMapManager concurrentMapManager, String name); void setRuntimeConfig(MapConfig mapConfig); MapConfig getRuntimeConfig(); MapLoader getMapLoader(); Object getInitLock(); void lockMap(Request request); void addIndex(Expression expression, boolean ordered, int attributeIndex); Record getRecord(Data key); int getBackupCount(); int getAsyncBackupCount(); int getTotalBackupCount(); boolean isCacheValue(); boolean isClearQuick(); boolean isReadBackupData(); void own(DataRecordEntry dataRecordEntry); void storeAsBackup(DataRecordEntry dataRecordEntry); boolean isMultiMap(); boolean isSet(); boolean isList(); boolean isMap(); boolean backup(Request req); void doBackup(final Request req); boolean containsKey(Request req); CMapEntry getMapEntry(Request req); Data get(Request req); boolean add(Request req, boolean backup); void onMigrate(Record record); void onDisconnect(Address deadAddress); void onDisconnect(Record record, Address deadAddress); void onRemoveMulti(Request req, Record record); void putMulti(Request req); void put(Request req); int size(); int size(int expectedPartitionVersion); Collection<Record> getLockedRecordsFor(long acquiredAtLeastFor); void collectScheduledLocks(Map<Object, DistributedLock> lockOwners, Map<Object, DistributedLock> lockRequested); int valueCount(Data key); void incrementGetCount(); boolean removeItem(Request req); void remove(Request req); void addListener(Data key, Address address, boolean includeValue); void removeListener(Data key, Address address); void appendState(StringBuffer sbState); MapConfig getMapConfig(); Node getNode(); MapIndexService getMapIndexService(); String getName(); @Override String toString(); }
CMap { public void put(Request req) { long now = Clock.currentTimeMillis(); boolean sendEvictEvent = false; Record evictedRecord = null; if (req.value == null) { req.value = new Data(); } Record record = getRecord(req); if (record != null && !record.isValid(now)) { if (record.isActive() && record.isEvictable()) { sendEvictEvent = true; evictedRecord = createNewTransientRecord(record.getKeyData(), record.getValueData()); } record.setValueData(null); record.setMultiValues(null); } if (req.operation == CONCURRENT_MAP_PUT_IF_ABSENT) { if (!isApplicable(CONCURRENT_MAP_PUT_IF_ABSENT, req, now)) { req.clearForResponse(); req.response = record.getValueData(); return; } } else if (req.operation == CONCURRENT_MAP_REPLACE_IF_NOT_NULL) { if (!isApplicable(CONCURRENT_MAP_REPLACE_IF_NOT_NULL, req, now)) { req.value = null; return; } } Data oldValue = null; if (record == null) { record = createAndAddNewRecord(req.key, req.value); } else { markAsActive(record); oldValue = (record.isValid(now)) ? record.getValueData() : null; record.setValueData(req.value); record.incrementVersion(); record.setLastUpdated(); } if (req.ttl > 0 && req.ttl < Long.MAX_VALUE) { record.setTTL(req.ttl); ttlPerRecord = true; } if (sendEvictEvent) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_EVICTED, null, evictedRecord, req.caller); } if (oldValue == null) { concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_ADDED, null, record, req.caller); } else { fireInvalidation(record); concurrentMapManager.fireMapEvent(mapListeners, EntryEvent.TYPE_UPDATED, oldValue, record, req.caller); } if (req.txnId != -1 || req.operation == ClusterOperation.CONCURRENT_MAP_PUT_AND_UNLOCK) { unlock(record, req); } record.setIndexes(req.indexes, req.indexTypes); updateIndexes(record); markAsDirty(record, false); req.clearForResponse(); req.version = record.getVersion(); if (localUpdateListener != null && req.txnId != Long.MIN_VALUE) { localUpdateListener.recordUpdated(record); } if (req.operation == CONCURRENT_MAP_SET || req.operation == CONCURRENT_MAP_TRY_PUT || req.operation == CONCURRENT_MAP_PUT_TRANSIENT || req.operation == CONCURRENT_MAP_REPLACE_IF_SAME || req.operation == CONCURRENT_MAP_PUT_AND_UNLOCK) { req.response = Boolean.TRUE; } else { req.response = oldValue; } } CMap(ConcurrentMapManager concurrentMapManager, String name); void setRuntimeConfig(MapConfig mapConfig); MapConfig getRuntimeConfig(); MapLoader getMapLoader(); Object getInitLock(); void lockMap(Request request); void addIndex(Expression expression, boolean ordered, int attributeIndex); Record getRecord(Data key); int getBackupCount(); int getAsyncBackupCount(); int getTotalBackupCount(); boolean isCacheValue(); boolean isClearQuick(); boolean isReadBackupData(); void own(DataRecordEntry dataRecordEntry); void storeAsBackup(DataRecordEntry dataRecordEntry); boolean isMultiMap(); boolean isSet(); boolean isList(); boolean isMap(); boolean backup(Request req); void doBackup(final Request req); boolean containsKey(Request req); CMapEntry getMapEntry(Request req); Data get(Request req); boolean add(Request req, boolean backup); void onMigrate(Record record); void onDisconnect(Address deadAddress); void onDisconnect(Record record, Address deadAddress); void onRemoveMulti(Request req, Record record); void putMulti(Request req); void put(Request req); int size(); int size(int expectedPartitionVersion); Collection<Record> getLockedRecordsFor(long acquiredAtLeastFor); void collectScheduledLocks(Map<Object, DistributedLock> lockOwners, Map<Object, DistributedLock> lockRequested); int valueCount(Data key); void incrementGetCount(); boolean removeItem(Request req); void remove(Request req); void addListener(Data key, Address address, boolean includeValue); void removeListener(Data key, Address address); void appendState(StringBuffer sbState); MapConfig getMapConfig(); Node getNode(); MapIndexService getMapIndexService(); String getName(); @Override String toString();  }