List of usage examples for org.apache.commons.collections.map LRUMap LRUMap
public LRUMap(Map map)
From source file:org.lockss.plugin.AuSearchSet.java
public void addRecent404(String url) { if (isEmpty()) { return;/* w w w.ja va2 s .c o m*/ } LRUMap map = recent404s; if (map == null) { if (recent404Size <= 0) { return; } map = new LRUMap(recent404Size); recent404s = map; } synchronized (map) { map.put(url, ""); } }
From source file:org.lockss.plugin.AuSearchSet.java
private void set404CacheSize(int newSize) { if (newSize < 0) { // shouldn't happen, but ignore rather than throw log.error("AuSearchSet size < 0"); }// w ww. j a va2s. c om LRUMap map = recent404s; if (map == null) { recent404Size = newSize; return; } synchronized (map) { if (newSize == 0) { if (log.isDebug2()) log.debug2("Removing 404 cache."); recent404s = null; } else if (map.maxSize() < newSize) { LRUMap newMap = new LRUMap(newSize); newMap.putAll(map); if (log.isDebug2()) log.debug2("Enlarging 404 cache."); recent404s = newMap; } recent404Size = newSize; } }
From source file:org.lockss.protocol.LcapDatagramRouter.java
public void setConfig(Configuration config, Configuration oldConfig, Configuration.Differences changedKeys) { enabled = config.getBoolean(LcapDatagramComm.PARAM_ENABLED, LcapDatagramComm.DEFAULT_ENABLED); if (changedKeys.contains(PARAM_FWD_PKT_RATE)) { fwdPktRateLimiter = RateLimiter.getConfiguredRateLimiter(config, fwdPktRateLimiter, PARAM_FWD_PKT_RATE, DEFAULT_FWD_PKT_RATE);//from ww w. j a v a 2 s . c om } if (changedKeys.contains(PARAM_ORIG_PKT_RATE)) { origPktRateLimiter = RateLimiter.getConfiguredRateLimiter(config, origPktRateLimiter, PARAM_ORIG_PKT_RATE, DEFAULT_ORIG_PKT_RATE); } if (changedKeys.contains(PARAM_FWD_MSG_RATE)) { fwdMsgRateLimiter = RateLimiter.getConfiguredRateLimiter(config, fwdMsgRateLimiter, PARAM_FWD_MSG_RATE, DEFAULT_FWD_MSG_RATE); } if (changedKeys.contains(PARAM_ORIG_MSG_RATE)) { origMsgRateLimiter = RateLimiter.getConfiguredRateLimiter(config, origMsgRateLimiter, PARAM_ORIG_MSG_RATE, DEFAULT_ORIG_MSG_RATE); } partnerRefreshInterval = config.getTimeInterval(PARAM_PARTNER_REFRESH_INTERVAL, DEFAULT_PARTNER_REFRESH_INTERVAL); if (changedKeys.contains(PARAM_BEACON_INTERVAL)) { beaconInterval = config.getTimeInterval(PARAM_BEACON_INTERVAL, DEFAULT_BEACON_INTERVAL); if (enabled) { startBeacon(); } } probAddPartner = config.getPercentage(PARAM_PROB_PARTNER_ADD, DEFAULT_PROB_PARTNER_ADD); initialHopCount = config.getInt(PARAM_INITIAL_HOPCOUNT, DEFAULT_INITIAL_HOPCOUNT); int dupSize = config.getInt(PARAM_DUP_MSG_HASH_SIZE, DEFAULT_DUP_MSG_HASH_SIZE); if (dupSize != recentVerifiers.maxSize()) { // Ok to discard current entries - might let some dup messages through. recentVerifiers = new LRUMap(dupSize); } if (partnerList != null) { partnerList.setConfig(config, oldConfig, changedKeys); } }
From source file:org.lockss.util.UniqueRefLruCache.java
/** * Standard constructor. Size must be positive. * @param maxSize maximum size for the LRUMap *//*from w w w . j a v a 2 s . co m*/ public UniqueRefLruCache(int maxSize) { if (maxSize <= 0) { throw new IllegalArgumentException("Negative cache size"); } lruMap = new LRUMap(maxSize); refMap = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK); }
From source file:org.lockss.util.UniqueRefLruCache.java
/** * Sets the NodeState cache size./*from w ww . j av a2 s.c o m*/ * @param newSize the new size */ public synchronized void setMaxSize(int newSize) { if (newSize <= 0) { throw new IllegalArgumentException("Negative cache size"); } if (lruMap.maxSize() != newSize) { LRUMap newMap = new LRUMap(newSize); newMap.putAll(lruMap); lruMap = newMap; } }
From source file:org.mrgeo.data.MrsPyramidRecordReader.java
@SuppressWarnings("unchecked") private T getTileFromCache(final String k, final MrsTileReader<T> reader, TileIdWritable id) { // see if the lower level tile is in our cache... if (!tilecache.containsKey(k)) { tilecache.put(k, new LRUMap(4)); }/*w w w .j av a 2 s. c o m*/ Map<TileIdWritable, T> cache = tilecache.get(k); if (cache.containsKey(id)) { return cache.get(id); } T r = reader.get(id); cache.put(id, r); return r; }
From source file:org.mule.transport.jms.redelivery.CountingRedeliveryHandler.java
@SuppressWarnings("unchecked") public CountingRedeliveryHandler() { super(); messages = Collections.synchronizedMap(new LRUMap(256)); }
From source file:org.nuclos.client.genericobject.GenericObjectLayoutCache.java
private GenericObjectLayoutCache() { mpLayoutIds = new LRUMap(100); INSTANCE = this; }
From source file:org.objectstyle.cayenne.access.DataRowStore.java
protected void initWithProperties(Map properties) { ExtendedProperties propertiesWrapper = new ExtendedProperties(); if (properties != null) { propertiesWrapper.putAll(properties); }//from ww w . ja v a 2 s .com long snapshotsExpiration = propertiesWrapper.getLong(SNAPSHOT_EXPIRATION_PROPERTY, SNAPSHOT_EXPIRATION_DEFAULT); int snapshotsCacheSize = propertiesWrapper.getInt(SNAPSHOT_CACHE_SIZE_PROPERTY, SNAPSHOT_CACHE_SIZE_DEFAULT); boolean notifyRemote = propertiesWrapper.getBoolean(REMOTE_NOTIFICATION_PROPERTY, REMOTE_NOTIFICATION_DEFAULT); String eventBridgeFactory = propertiesWrapper.getString(EVENT_BRIDGE_FACTORY_PROPERTY, EVENT_BRIDGE_FACTORY_DEFAULT); if (logObj.isDebugEnabled()) { logObj.debug("DataRowStore property " + SNAPSHOT_EXPIRATION_PROPERTY + " = " + snapshotsExpiration); logObj.debug("DataRowStore property " + SNAPSHOT_CACHE_SIZE_PROPERTY + " = " + snapshotsCacheSize); logObj.debug("DataRowStore property " + REMOTE_NOTIFICATION_PROPERTY + " = " + notifyRemote); logObj.debug("DataRowStore property " + EVENT_BRIDGE_FACTORY_PROPERTY + " = " + eventBridgeFactory); } // init ivars from properties this.notifyingRemoteListeners = notifyRemote; // TODO: ENTRY EXPIRATION is not supported by commons LRU Map this.snapshots = new LRUMap(snapshotsCacheSize); // TODO: cache size should really be a sum of all result lists sizes... // so we must track it outside the LRUMap... this.snapshotLists = new LRUMap(snapshotsCacheSize); // init event bridge only if we are notifying remote listeners if (notifyingRemoteListeners) { try { EventBridgeFactory factory = (EventBridgeFactory) Class.forName(eventBridgeFactory).newInstance(); this.remoteNotificationsHandler = factory.createEventBridge(getSnapshotEventSubject(), properties); // listen to EventBridge EventManager.getDefaultManager().addListener(this, "processRemoteEvent", SnapshotEvent.class, getSnapshotEventSubject(), remoteNotificationsHandler); // start EventBridge - it will listen to all event sources for this // subject remoteNotificationsHandler.startup(EventManager.getDefaultManager(), EventBridge.RECEIVE_LOCAL_EXTERNAL); } catch (Exception ex) { throw new CayenneRuntimeException("Error initializing DataRowStore.", ex); } } }
From source file:org.opencastproject.oaipmh.server.OaiPmhRepositoryServlet.java
/** * Called by the ConfigurationAdmin service. * This method actually sets up the server. *///from w w w . j av a2 s .co m public synchronized void updated(Dictionary properties) throws ConfigurationException { logger.info("Updated"); checkDictionary(properties, componentContext); // collect properties final String path = getCfg(properties, CFG_MOUNT_PATH); final SearchService searchService = (SearchService) componentContext.locateService("searchService"); logger.info("Using search service " + searchService); final String baseUrl = getContextProperty(componentContext, PROP_SERVER_URL) + path; final String repositoryName = getCfg(properties, CFG_REPOSITORY_NAME); final String adminEmail = getContextProperty(componentContext, PROP_ADMIN_EMAIL); final Integer resultLimit = getCfgAsInt(properties, CFG_RESULT_LIMIT); final HttpService httpService = (HttpService) componentContext.locateService("httpService"); // register servlet try { // ... and unregister first if necessary if (currentServletAlias != null) httpService.unregister(currentServletAlias); httpService.registerServlet(path, this, null, null); currentServletAlias = path; logger.info("Registering OAI-PMH server under " + path); } catch (Exception e) { throw new RuntimeException("Error registering OAI-PMH servlet", e); } // create repository repository = new OaiPmhRepository() { private Map resumptionTokens = Collections.synchronizedMap(new LRUMap(100)); @Override public Granularity getRepositoryTimeGranularity() { return Granularity.DAY; } @Override public String getBaseUrl() { return baseUrl; } @Override public String getRepositoryName() { return repositoryName; } @Override public SearchService getSearchService() { return searchService; } @Override public String getAdminEmail() { return adminEmail; } @Override public String saveQuery(ResumableQuery query) { String token = DigestUtils.md5Hex(Double.toString(Math.random())); resumptionTokens.put(token, query); return token; } @Override public Option<ResumableQuery> getSavedQuery(String resumptionToken) { return option(((ResumableQuery) resumptionTokens.get(resumptionToken))); } @Override public int getResultLimit() { return resultLimit; } @Override public List<MetadataProvider> getMetadataProviders() { return metadataProviders; } }; }