/** * Creates a store based on given configuration parameters. * * @param capacity the maximum number of connections the store can manage * @param threshold the period of time of inactivity (in seconds) after which a * connection is considered stale and can be evicted from the store if * a new connection is to be added to the store * @param sessionCache a second level cache to use for <em>current</em> * connection state of established DTLS sessions. */ public InMemoryConnectionStore(final int capacity, final long threshold, final SessionCache sessionCache) { connections = new LeastRecentlyUsedCache<>(capacity, threshold); this.sessionCache = sessionCache; if (sessionCache != null) { // make sure that session state for stale (evicted) connections is removed from second level cache connections.addEvictionListener(new LeastRecentlyUsedCache.EvictionListener<Connection>() { @Override public void onEviction(Connection staleConnection) { removeSessionFromCache(staleConnection); } }); } LOG.log(Level.CONFIG, "Created new InMemoryConnectionStore [capacity: {0}, connection expiration threshold: {1}s]", new Object[]{capacity, threshold}); }
/** * * @param capacity * @param expirationThreshold * @param noOfEntries */ private void givenACacheWithEntries(int capacity, long expirationThreshold, int noOfEntries) { cache = new LeastRecentlyUsedCache<>(capacity, expirationThreshold); for (int i = 0; i < noOfEntries; i++) { cache.put(i, String.valueOf(i)); } } }
trackers = new LeastRecentlyUsedCache<>(config.getInt(NetworkConfig.Keys.MAX_ACTIVE_PEERS, 150000), config.getLong(NetworkConfig.Keys.MAX_PEER_INACTIVITY_PERIOD, 10 * 60));