protected Map<Class<?>, Class<?>[]> buildPolymorphicEntityMap(Map<Class<?>, Class<?>[]> polymorphicEntityMap, Class<?> ceilingClass, Class<?>[] filteredEntities) { if (polymorphicEntityMap == null) { polymorphicEntityMap = new LRUMap<>(1000); } polymorphicEntityMap.put(ceilingClass, filteredEntities); return polymorphicEntityMap; }
@Override public Chunk put(Key key, Chunk value) { curSizeBytes += value.getData().length; Chunk ret = super.put(key, value); statCurSize.add(curSizeBytes); statCurChunks.add(size()); return ret; }
/** * Gets the value mapped to the key specified. * <p> * This operation changes the position of the key in the map to the * most recently used position (last). * * @param key the key * @return the mapped value, null if no match */ @Override public V get(final Object key) { return get(key, true); }
if (isFull()) { LinkEntry<K, V> reuse = header.after; boolean removeLRUEntry = false; if (scanUntilRemovable) { while (reuse != header && reuse != null) { if (removeLRU(reuse)) { removeLRUEntry = true; break; removeLRUEntry = removeLRU(reuse); " If so, then please report this to dev@commons.apache.org as a bug."); reuseMapping(reuse, hashIndex, hashCode, key, value); } else { super.addMapping(hashIndex, hashCode, key, value);
/** * Adds TransactionInfo to the store. * If entries for this transaction already exist the method adds new entry to the list * if no entry for the same block exists * @return true if TransactionInfo was added, false if already exist */ public boolean put(TransactionInfo tx) { byte[] txHash = tx.getReceipt().getTransaction().getHash(); List<TransactionInfo> existingInfos = null; synchronized (lastSavedTxHash) { if (lastSavedTxHash.put(new ByteArrayWrapper(txHash), object) != null || !lastSavedTxHash.isFull()) { existingInfos = get(txHash); } } // else it is highly unlikely that the transaction was included into another block // earlier than 5000 transactions before with regard to regular block import process if (existingInfos == null) { existingInfos = new ArrayList<>(); } else { for (TransactionInfo info : existingInfos) { if (FastByteComparisons.equal(info.getBlockHash(), tx.getBlockHash())) { return false; } } } existingInfos.add(tx); put(txHash, existingInfos); return true; }
public BigInteger freq(String aUnigram) { BigInteger f = (BigInteger) unigramCache.get(aUnigram); if (f != null) { return f; } // System.out.printf("Frequency for [%s]... ", aUnigram); try { f = BigInteger.valueOf(web1tSearcher.getFrequency(aUnigram)); // System.out.printf("%d%n", f.longValue()); unigramCache.put(aUnigram, f); return f; } catch (IOException e) { throw new IllegalStateException(e); } }
@Override public ByteArraySet getForeignKeys(ByteArray primaryKey) { if(entryRICache.containsKey(primaryKey)) { return entryRICache.get(primaryKey); } else if(pendingRIWrites.containsKey(primaryKey)) { return pendingRIWrites.get(primaryKey); } else { byte[] bytes = state.get(reverseIndexName, primaryKey.getBytes()); if (bytes == null) { return null; } else { ByteArraySet set = ByteArraySet.deserialize(bytes); if(set.size() > LRU_CACHE_THRESHOLD) entryRICache.put(primaryKey, set); return set; } } }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public IValueConnector getModuleConnector(Module module) { if (module == null) { return null; } // we must rehash entries in case in case modules hashcode have changed and // still preserve LRU order. Map<Module, IValueConnector> buff = new LinkedHashMap<>(moduleConnectors); moduleConnectors.clear(); moduleConnectors.putAll(buff); IValueConnector moduleConnector = moduleConnectors.get(module); if (moduleConnector == null) { moduleConnector = createModelConnector(module.getName(), ModuleDescriptor.MODULE_DESCRIPTOR); moduleConnectors.put(module, moduleConnector); } moduleConnector.setConnectorValue(module); return moduleConnector; }
@Override protected boolean removeLRU(LinkEntry<Key, Value> entry) { cacheRemoved(entry.getKey(), entry.getValue()); return super.removeLRU(entry); } });
@Override protected TypeDefinition resolveType(final String descriptor, final boolean mightBePrimitive) { if (failedTypes.containsKey(descriptor)) return null; TypeDefinition result = resolveTypeInternal(descriptor, mightBePrimitive); if (result == null) failedTypes.put(descriptor, true); return result; }
@Override public ByteArraySet remove(ByteArray foreignKey) { Preconditions.checkNotNull(foreignKey); ByteArraySet primaryKeys = getIndexEntry(foreignKey); if(primaryKeys != null) { state.delete(indexName, foreignKey.getBytes()); if(entryCache.containsKey(foreignKey)) { entryCache.remove(foreignKey); } if(pendingWrites.containsKey(foreignKey)) { pendingWrites.remove(foreignKey); } for(ByteArray primaryKey: primaryKeys) { removeRI(foreignKey, primaryKey); } } return primaryKeys; }
/** * Constructor copying elements from another map. * * <p>The maximum size is set from the map's size.</p> * * @param map the map to copy * @param scanUntilRemovable scan until a removeable entry is found, default false * @throws NullPointerException if the map is null * @throws IllegalArgumentException if the map is empty * @since 3.1 */ public LRUMap(final Map<? extends K, ? extends V> map, final boolean scanUntilRemovable) { this(map.size(), DEFAULT_LOAD_FACTOR, scanUntilRemovable); putAll(map); }
private ColumnVisibility getCV(Key k) { Text expr = k.getColumnVisibility(cvHolder); ColumnVisibility vis = (ColumnVisibility) cvCache.get(expr); if (vis == null) { // the column visibility needs to take ownership of the expression vis = new ColumnVisibility(new Text(expr)); cvCache.put(expr, vis); } return vis; }
@Override public ByteArraySet getIndexEntry(ByteArray foreignKey) { Preconditions.checkNotNull(foreignKey); if(entryCache.containsKey(foreignKey)) { return entryCache.get(foreignKey); } else if(pendingWrites.containsKey(foreignKey)) { return pendingWrites.get(foreignKey); } else { byte[] bytes = state.get(indexName, foreignKey.getBytes()); if (bytes == null) { return null; } else { ByteArraySet set = ByteArraySet.deserialize(bytes); if(set.size() > LRU_CACHE_THRESHOLD) entryCache.put(foreignKey, set); return set; } } }
@Override protected boolean removeLRU(LinkEntry<ByteArrayWrapper, V> entry) { cacheRemoved(entry.getKey().getData(), entry.getValue()); return super.removeLRU(entry); } }));
@Override protected TypeDefinition resolveType(final String descriptor, final boolean mightBePrimitive) { if (failedTypes.containsKey(descriptor)) return null; TypeDefinition result = resolveTypeInternal(descriptor, mightBePrimitive); if (result == null) failedTypes.put(descriptor, true); return result; }
/** * Removes the given foreign key from the reverse index entry corresponding to the given primary key * @param foreignKey - The foreign key to remove * @param primaryKey - The primary key of the entry */ protected void removeRI(ByteArray foreignKey, ByteArray primaryKey) { ByteArraySet foreignKeys = getForeignKeys(primaryKey); if(foreignKeys != null) { foreignKeys.remove(foreignKey); if(foreignKeys.size() == 0) { state.delete(reverseIndexName, primaryKey.getBytes()); if(entryRICache.containsKey(primaryKey)) { entryRICache.remove(primaryKey); } if(pendingRIWrites.containsKey(primaryKey)) { pendingRIWrites.remove(primaryKey); } } else { putRIToState(primaryKey, foreignKeys); } } }
protected synchronized boolean switchToLRUMap() { if (!usingLRUMap) { if (size() > maxEntries) { lruMap = Collections.synchronizedMap(new LRUMap<K, V>(maxEntries)); lruMap.putAll(concurrentMap); usingLRUMap = true; concurrentMap.clear(); } } return usingLRUMap; // this could be set by another thread }