org.apache.commons.collections4.map.LRUMap Java Examples

The following examples show how to use org.apache.commons.collections4.map.LRUMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ROTransaction.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public ROTransaction(StorageAccessIF access) {
  super("TX" + access.getId(), access);
  
  // initialize shared data cache
  StorageCacheIF scache = access.getStorage().getStorageCache();
  this.txncache = new ROLocalCache(this, scache);

  // initialize identity map
  this.lrusize = PropertyUtils.getInt(access.getProperty("net.ontopia.topicmaps.impl.rdbms.Cache.shared.identitymap.lru"), 5000);
  this.lru = new LRUMap(this.lrusize);

  // instrument transaction cache
  int dinterval = PropertyUtils.getInt(access.getStorage().getProperty("net.ontopia.topicmaps.impl.rdbms.Cache.local.debug"), -1);
  if (dinterval > 0) {
    log.info("Instrumenting local cache.");
    this.txncache = new StatisticsCache("lcache", this.txncache, dinterval);
  }
  
  // Get access registrar from transaction cache (currently the
  // local data cache)
  this.registrar = txncache.getRegistrar();  
  
  // Use IdentityIF object access
  this.oaccess = new PersistentObjectAccess(this);
}
 
Example #2
Source File: CompactorScanner.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
public CompactorScanner(ObserverContext<RegionCoprocessorEnvironment> e,
                        InternalScanner internalScanner,
                        Client commitTableClient,
                        boolean isMajorCompaction,
                        boolean preserveNonTransactionallyDeletedCells) throws IOException {
    this.internalScanner = internalScanner;
    this.commitTableClient = commitTableClient;
    this.isMajorCompaction = isMajorCompaction;
    this.retainNonTransactionallyDeletedCells = preserveNonTransactionallyDeletedCells;
    this.lowWatermark = getLowWatermarkFromCommitTable();
    // Obtain the table in which the scanner is going to operate
    this.hRegion = HBaseShims.getRegionCoprocessorRegion(e.getEnvironment());
    commitCache = new LRUMap<>(1000);
    LOG.info("Scanner cleaning up uncommitted txs older than LW [{}] in region [{}]",
            lowWatermark, hRegion.getRegionInfo());
}
 
Example #3
Source File: RWTransaction.java    From ontopia with Apache License 2.0 6 votes vote down vote up
public RWTransaction(StorageAccessIF access) {
  super("TX" + access.getId(), access);
  
  // initialize shared data cache
  StorageCacheIF scache = access.getStorage().getStorageCache();
  if (scache != null) trackall = true;
  this.txncache = new RWLocalCache(this, scache);

  // initialize identity map
  this.lrusize = PropertyUtils.getInt(access.getProperty("net.ontopia.topicmaps.impl.rdbms.Cache.identitymap.lru"), 300);
  this.lru = new LRUMap(lrusize);
  
  // instrument transaction cache
  int dinterval = PropertyUtils.getInt(access.getStorage().getProperty("net.ontopia.topicmaps.impl.rdbms.Cache.local.debug"), -1);
  if (dinterval > 0) {
    log.info("Instrumenting local cache.");
    this.txncache = new StatisticsCache("lcache", this.txncache, dinterval);
  }
  
  // Get access registrar from transaction cache (currently the
  // local data cache)
  this.registrar = txncache.getRegistrar();  
  
  // Use IdentityIF object access
  this.oaccess = new PersistentObjectAccess(this);
}
 
Example #4
Source File: Contract.java    From aion_api with MIT License 6 votes vote down vote up
private Contract(final ContractBuilder contractBuilder) {
    this.api = contractBuilder.api;
    this.contractName = contractBuilder.contractName;
    this.contractAddress = contractBuilder.dr.getAddress();
    this.deployTxId = contractBuilder.dr.getTxid();
    this.from = contractBuilder.from;
    this.abiDefinition = contractBuilder.cr.getAbiDefinition();
    this.abiDefStr = contractBuilder.cr.getAbiDefString();
    this.contractCode = contractBuilder.cr.getCode();
    this.contractSource = contractBuilder.cr.getSource();
    this.languageVersion = contractBuilder.cr.getLanguageVersion();
    this.compilerOptions = contractBuilder.cr.getCompilerOptions();
    this.compilerVersion = contractBuilder.cr.getCompilerVersion();
    this.userDoc = contractBuilder.cr.getUserDoc();
    this.developerDoc = contractBuilder.cr.getDeveloperDoc();
    this.funcParams = setupAbiFunctionDefinitions(contractBuilder.cr.getAbiDefinition());

    this.inputParams = new ArrayList<>();
    this.outputParams = new ArrayList<>();
    this.eventsName = new ArrayList<>();
    int lrumapSize = 100;
    this.eventsIssued = new LRUMap<>(lrumapSize);
    this.eventsIssuedRev = new LRUMap<>(lrumapSize);
    reset();
}
 
Example #5
Source File: MsgExecutor.java    From aion_api with MIT License 5 votes vote down vote up
MsgExecutor(int protocolVer, String url, int timeout, String pubkey) {
    this.ver = protocolVer;
    this.url = url;
    this.addrBindNumber = Arrays.toString(ApiUtils.genHash(8));
    this.hashMap = Collections.synchronizedMap(new LRUTimeMap<>(maxPenddingTx << 1, timeout));
    this.eventMap = Collections.synchronizedMap(new LRUMap<>(100));
    ServerPubkeyString = pubkey;
    initPriviege();
}
 
Example #6
Source File: QueryCache.java    From ontopia with Apache License 2.0 5 votes vote down vote up
QueryCache(DetachedQueryIF query, CacheIF<K, E> cache, int lrusize, E nullObject) {
  this.query = query;
  this.cache = cache;
  this.lru = Collections.synchronizedMap(new LRUMap<K, E>(lrusize));
  this.lrusize = lrusize;
  NULLOBJECT = nullObject;
}
 
Example #7
Source File: TransactionVisibilityFilterBase.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
public TransactionVisibilityFilterBase(Filter cellFilter,
                                       SnapshotFilterImpl snapshotFilter,
                                       HBaseTransaction hbaseTransaction) {
    this.userFilter = cellFilter;
    this.snapshotFilter = snapshotFilter;
    commitCache = new LRUMap<>(1000);
    this.hbaseTransaction = hbaseTransaction;
    familyDeletionCache = new HashMap<>();

}
 
Example #8
Source File: TestCaching.java    From yauaa with Apache License 2.0 5 votes vote down vote up
private int getAllocatedCacheSize(UserAgentAnalyzer uaa) throws IllegalAccessException {
    LRUMap<?, ?> cache = getCache(uaa);
    if (cache == null) {
        return 0;
    }
    return cache.maxSize();
}
 
Example #9
Source File: TestCaching.java    From yauaa with Apache License 2.0 5 votes vote down vote up
private LRUMap<?, ?> getCache(UserAgentAnalyzer uaa) throws IllegalAccessException {
    LRUMap<?, ?> actualCache = null;
    Object rawParseCache = FieldUtils.readField(uaa, "parseCache", true);
    if (rawParseCache instanceof LRUMap<?, ?>) {
        actualCache = (LRUMap<?, ?>) rawParseCache;
    }
    return actualCache;
}
 
Example #10
Source File: AbstractUserAgentAnalyzer.java    From yauaa with Apache License 2.0 5 votes vote down vote up
private synchronized void initializeCache() {
    if (cacheSize >= 1) {
        parseCache = new LRUMap<>(cacheSize);
    } else {
        parseCache = null;
    }
}
 
Example #11
Source File: ReadCache.java    From nuls with MIT License 5 votes vote down vote up
@Override
public ReadCache.BytesKey<V> withMaxCapacity(int maxCapacity) {
    withCache(new ByteArrayMap<V>(new LRUMap<ByteArrayWrapper, V>(maxCapacity) {
        @Override
        protected boolean removeLRU(LinkEntry<ByteArrayWrapper, V> entry) {
            cacheRemoved(entry.getKey().getData(), entry.getValue());
            return super.removeLRU(entry);
        }
    }));
    return this;
}
 
Example #12
Source File: ReadCache.java    From nuls with MIT License 5 votes vote down vote up
/**
 * Sets the max number of entries to cache
 */
public ReadCache<Key, Value> withMaxCapacity(int maxCapacity) {
    return withCache(new LRUMap<Key, Value>(maxCapacity) {
        @Override
        protected boolean removeLRU(LinkEntry<Key, Value> entry) {
            cacheRemoved(entry.getKey(), entry.getValue());
            return super.removeLRU(entry);
        }
    });
}
 
Example #13
Source File: ReadCache.java    From nuls-v2 with MIT License 5 votes vote down vote up
@Override
public ReadCache.BytesKey<V> withMaxCapacity(int maxCapacity) {
    withCache(new ByteArrayMap<V>(new LRUMap<ByteArrayWrapper, V>(maxCapacity) {
        @Override
        protected boolean removeLRU(LinkEntry<ByteArrayWrapper, V> entry) {
            cacheRemoved(entry.getKey().getData(), entry.getValue());
            return super.removeLRU(entry);
        }
    }));
    return this;
}
 
Example #14
Source File: ReadCache.java    From nuls-v2 with MIT License 5 votes vote down vote up
/**
 * Sets the max number of entries to cache
 */
public ReadCache<Key, Value> withMaxCapacity(int maxCapacity) {
    return withCache(new LRUMap<Key, Value>(maxCapacity) {
        @Override
        protected boolean removeLRU(LinkEntry<Key, Value> entry) {
            cacheRemoved(entry.getKey(), entry.getValue());
            return super.removeLRU(entry);
        }
    });
}
 
Example #15
Source File: MsgExecutor.java    From aion_api with MIT License 5 votes vote down vote up
MsgExecutor(int protocolVer, String url) {
    this.ver = protocolVer;
    this.url = url;
    this.addrBindNumber = Arrays.toString(ApiUtils.genHash(8));
    this.hashMap = Collections.synchronizedMap(new LRUTimeMap<>(maxPenddingTx << 1));
    this.eventMap = Collections.synchronizedMap(new LRUMap<>(100));
    initPriviege();
}
 
Example #16
Source File: MemoryCache.java    From amdb-proxy with Apache License 2.0 5 votes vote down vote up
public MemoryCache(Integer cacheSize) {
	//by spring inject, defaut set 1000
	if(cacheSize == null) {
		this.cacheSize = 1000;
	}else {
		this.cacheSize = cacheSize;
	}
	
	map = new LRUMap<String, CacheEntry>(this.cacheSize);
	cache = Collections.synchronizedMap(map);
}
 
Example #17
Source File: QueryMetricsWriter.java    From datawave with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void init() {
    // noinspection unchecked
    lastPageMap = new LRUMap(1000);
    lastPageMetricMap = new LRUMap(1000);
    metricQueue = new ArrayList<>();
    timelyClient = createUdpClient();
}
 
Example #18
Source File: TopSeedsStatsTracker.java    From aion with MIT License 5 votes vote down vote up
public TopSeedsStatsTracker(int maxActivePeers) {
    // instantiate objects for gathering stats
    for (BlockType type : BlockType.values()) {
        blocksByPeer.put(type, new LRUMap<>(maxActivePeers));
    }
    seedsLock = new ReentrantLock();
}
 
Example #19
Source File: LocatorLookup.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public LocatorLookup(String qname, TransactionIF txn, TopicMapIF tm, int lrusize, E nullObject) {
  this.qname = qname;
  this.txn = txn;
  this.tm = tm;
  this.lrusize = lrusize;
  this.cache = new ReferenceMap<LocatorIF, E>(AbstractReferenceMap.ReferenceStrength.SOFT, AbstractReferenceMap.ReferenceStrength.HARD);
  this.lru = new LRUMap<LocatorIF, E>(lrusize);
  NULLOBJECT = nullObject;
}
 
Example #20
Source File: QueryLookup.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public QueryLookup(String qname, TransactionIF txn, int lrusize, V nullObject) {
   this.qname = qname;
   this.txn = txn;
   this.cache = new ReferenceMap(AbstractReferenceMap.ReferenceStrength.SOFT, AbstractReferenceMap.ReferenceStrength.HARD);
   this.lru = new LRUMap(lrusize);
NULLOBJECT = nullObject;
 }
 
Example #21
Source File: BlockPropagationHandler.java    From aion with MIT License 5 votes vote down vote up
public BlockPropagationHandler(
        final int cacheSize,
        final IAionBlockchain blockchain,
        final SyncStats syncStats,
        final IP2pMgr p2pManager,
        BlockHeaderValidator headerValidator,
        final boolean isSyncOnlyNode,
        final byte apiVersion,
        final AionPendingStateImpl pendingState) {
    /*
     * Size of the cache maintained within the map, a lower cacheSize
     * saves space, but indicates we may "forget" about a block sooner.
     *
     * This can possibly lead to increase network traffic and unecessary
     * process (?)
     *
     * all accesses to cacheMap are guarded by instance
     */
    this.cacheMap = new LRUMap<>(cacheSize);

    // the expectation is that we will not have as many peers as we have blocks
    this.blockchain = blockchain;

    this.syncStats = syncStats;

    // record our own nodeId to cover corner case
    this.p2pManager = p2pManager;

    this.blockHeaderValidator = headerValidator;

    this.isSyncOnlyNode = isSyncOnlyNode;
    this.apiVersion = apiVersion;
    this.pendingState = pendingState;
}
 
Example #22
Source File: MinerStatisticsCalculator.java    From aion with MIT License 5 votes vote down vote up
MinerStatisticsCalculator(ChainHolder chainHolder, int size, int blockTimeCount) {
    this.chainHolder = chainHolder;
    this.size = size;
    aionBlockCache = new LinkedBlockingDeque<>(size * 2); // will always store elements in the reverse
    // of natural order, ie. n-1th element>nth element
    this.blockTimeCount = blockTimeCount;
    statsHistory = Collections.synchronizedMap(new LRUMap<>(size * 2));
}
 
Example #23
Source File: BatfishTestUtils.java    From batfish with Apache License 2.0 4 votes vote down vote up
private static Map<NetworkSnapshot, SortedMap<String, BgpAdvertisementsByVrf>> makeEnvBgpCache() {
  return Collections.synchronizedMap(new LRUMap<>(4));
}
 
Example #24
Source File: Driver.java    From batfish with Apache License 2.0 4 votes vote down vote up
private static Map<NetworkSnapshot, SortedMap<String, BgpAdvertisementsByVrf>>
    buildEnvironmentBgpTablesCache() {
  return Collections.synchronizedMap(new LRUMap<>(MAX_CACHED_ENVIRONMENT_BGP_TABLES));
}
 
Example #25
Source File: TimeoutLRUMap.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new instance of TimeoutLRUMap
 */
public TimeoutLRUMap() {
	timeoutInMillis = 5000; // Milliseconds
	internalMap = new LRUMap<>(1000);
}
 
Example #26
Source File: TransactionalLRULookupIndex.java    From ontopia with Apache License 2.0 4 votes vote down vote up
public TransactionalLRULookupIndex(CacheIF cache, int lrusize) {
  this.cache = cache;
  this.lru = Collections.synchronizedMap(new LRUMap(lrusize));
  this.lrusize = lrusize;
}
 
Example #27
Source File: TopLeechesStatsTracker.java    From aion with MIT License 4 votes vote down vote up
public TopLeechesStatsTracker(int maxActivePeers) {
    this.blockRequestsByPeer = new LRUMap<>(maxActivePeers);
    this.leechesLock = new ReentrantLock();
}
 
Example #28
Source File: ResponseStats.java    From aion with MIT License 4 votes vote down vote up
public ResponseStats(int maxActivePeers) {
    requestTimeByPeers = new LRUMap<>(maxActivePeers);
    responseStatsByPeers = new LRUMap<>(maxActivePeers);
}
 
Example #29
Source File: RequestStatsTracker.java    From aion with MIT License 4 votes vote down vote up
public RequestStatsTracker(int maxActivePeers) {
    this.requestsToPeers = new LRUMap<>(maxActivePeers);
    this.requestLock = new ReentrantLock();
}
 
Example #30
Source File: LruDataSource.java    From aion with MIT License 4 votes vote down vote up
LruDataSource(ByteArrayKeyValueDatabase src, Serializer<V> serializer, int cacheSize) {
    super(src, serializer);
    this.cache = new LRUMap<>(cacheSize);
}