11/*
22 * Copyright 2016 Google Inc. All Rights Reserved.
3+ * Copyright 2023 Uwe Trottmann
34 *
45 * Licensed under the Apache License, Version 2.0 (the "License");
56 * you may not use this file except in compliance with the License.
2021import com .google .common .base .Ticker ;
2122import com .google .common .cache .Cache ;
2223import com .google .common .cache .CacheBuilder ;
23- import com .google .common .cache .RemovalListener ;
24- import com .google .common .cache .RemovalNotification ;
2524
26- import java .util .concurrent .ConcurrentLinkedDeque ;
2725import java .util .concurrent .TimeUnit ;
2826
2927import javax .annotation .Nullable ;
@@ -42,13 +40,7 @@ public class CheckAggregationOptions {
4240 */
4341 public static final int DEFAULT_RESPONSE_EXPIRATION_MILLIS = 4000 ;
4442
45- /**
46- * The default flush cache entry interval.
47- */
48- public static final int DEFAULT_FLUSH_CACHE_ENTRY_INTERVAL_MILLIS = 2000 ;
49-
5043 private final int numEntries ;
51- private final int flushCacheEntryIntervalMillis ;
5244 private final int expirationMillis ;
5345
5446 /**
@@ -58,21 +50,13 @@ public class CheckAggregationOptions {
5850 * is the maximum number of cache entries that can be kept in the
5951 * aggregation cache. The cache is disabled if this value is
6052 * negative.
61- * @param flushCacheEntryIntervalMillis
62- * the maximum interval before an aggregated check request is
63- * flushed to the server. The cache entry is deleted after the
64- * flush
6553 * @param expirationMillis
6654 * is the maximum interval in milliseconds before a cached check
67- * response is invalidated. This value should be greater than
68- * {@code flushCacheEntryIntervalMillis}. If not, it is ignored,
69- * and a value of {@code flushCacheEntryIntervalMillis} is used
70- * instead.
55+ * response is invalidated.
7156 */
72- public CheckAggregationOptions (int numEntries , int flushCacheEntryIntervalMillis , int expirationMillis ) {
57+ public CheckAggregationOptions (int numEntries , int expirationMillis ) {
7358 this .numEntries = numEntries ;
74- this .flushCacheEntryIntervalMillis = flushCacheEntryIntervalMillis ;
75- this .expirationMillis = Math .max (expirationMillis , flushCacheEntryIntervalMillis + 1 );
59+ this .expirationMillis = expirationMillis ;
7660 }
7761
7862 /**
@@ -81,7 +65,7 @@ public CheckAggregationOptions(int numEntries, int flushCacheEntryIntervalMillis
8165 * Creates an instance initialized with the default values.
8266 */
8367 public CheckAggregationOptions () {
84- this (DEFAULT_NUM_ENTRIES , DEFAULT_FLUSH_CACHE_ENTRY_INTERVAL_MILLIS , DEFAULT_RESPONSE_EXPIRATION_MILLIS );
68+ this (DEFAULT_NUM_ENTRIES , DEFAULT_RESPONSE_EXPIRATION_MILLIS );
8569 }
8670
8771 /**
@@ -92,18 +76,9 @@ public int getNumEntries() {
9276 return numEntries ;
9377 }
9478
95- /**
96- * @return the maximum interval before aggregated report requests are
97- * flushed to the server
98- */
99- public int getFlushCacheEntryIntervalMillis () {
100- return flushCacheEntryIntervalMillis ;
101- }
102-
10379 /**
10480 * @return the maximum interval before a cached check response should be
105- * deleted. This value will not be greater than
106- * {@link #getFlushCacheEntryIntervalMillis()}
81+ * deleted.
10782 */
10883 public int getExpirationMillis () {
10984 return expirationMillis ;
@@ -115,45 +90,29 @@ public int getExpirationMillis() {
11590 * @param <T>
11691 * the type of the instance being cached
11792 *
118- * @param out
119- * a concurrent {@code Deque} to which previously cached items
120- * are added as they expire
12193 * @return a {@link Cache} corresponding to this instance's values or
12294 * {@code null} unless {@link #numEntries} is positive.
12395 */
12496 @ Nullable
125- public <T > Cache <String , T > createCache (ConcurrentLinkedDeque < T > out ) {
126- return createCache (out , Ticker .systemTicker ());
97+ public <T > Cache <String , T > createCache () {
98+ return createCache (Ticker .systemTicker ());
12799 }
128100
129101 /**
130102 * Creates a {@link Cache} configured by this instance.
131103 *
132- * @param <T>
133- * the type of the value stored in the Cache
134- * @param out
135- * a concurrent {@code Deque} to which the cached values are
136- * added as they are removed from the cache
137- * @param ticker
138- * the time source used to determine expiration
104+ * @param <T> the type of the value stored in the Cache
105+ * @param ticker the time source used to determine expiration
139106 * @return a {@link Cache} corresponding to this instance's values or
140- * {@code null} unless {@code #numEntries} is positive.
107+ * {@code null} unless {@code #numEntries} is positive.
141108 */
142109 @ Nullable
143- public <T > Cache <String , T > createCache (final ConcurrentLinkedDeque <T > out , Ticker ticker ) {
144- Preconditions .checkNotNull (out , "The out deque cannot be null" );
110+ public <T > Cache <String , T > createCache (Ticker ticker ) {
145111 Preconditions .checkNotNull (ticker , "The ticker cannot be null" );
146112 if (numEntries <= 0 ) {
147113 return null ;
148114 }
149- final RemovalListener <String , T > listener = new RemovalListener <String , T >() {
150- @ Override
151- public void onRemoval (RemovalNotification <String , T > notification ) {
152- out .addFirst (notification .getValue ());
153- }
154- };
155- CacheBuilder <String , T > b = CacheBuilder .newBuilder ().maximumSize (numEntries ).ticker (ticker )
156- .removalListener (listener );
115+ CacheBuilder <Object , Object > b = CacheBuilder .newBuilder ().maximumSize (numEntries ).ticker (ticker );
157116 if (expirationMillis >= 0 ) {
158117 b .expireAfterWrite (expirationMillis , TimeUnit .MILLISECONDS );
159118 }
0 commit comments