A specification of a CacheBuilder configuration. CacheBuilderSpec supports parsing configuration off of a string, which makes it especially useful for command-line configuration of a CacheBuilder. The string syntax is a series of comma-separated keys or key-value pair
| 76 | |
| 77 | |
| 78 | @GwtIncompatible |
| 79 | public final class CacheBuilderSpec { |
| 80 | /** Parses a single value. */ |
| 81 | private interface ValueParser { |
| 82 | |
| 83 | void parse(CacheBuilderSpec spec, String key, @Nullable String value); |
| 84 | } |
| 85 | |
| 86 | /** Splits each key-value pair. */ |
| 87 | |
| 88 | private static final Splitter KEYS_SPLITTER = Splitter.on(',').trimResults(); |
| 89 | |
| 90 | /** Splits the key from the value. */ |
| 91 | private static final Splitter KEY_VALUE_SPLITTER = Splitter.on('=').trimResults(); |
| 92 | |
| 93 | /** Map of names to ValueParser. */ |
| 94 | private static final ImmutableMap<String, ValueParser> VALUE_PARSERS = ImmutableMap.<String, ValueParser>builder().put("initialCapacity", new InitialCapacityParser()).put("maximumSize", new MaximumSizeParser()).put("maximumWeight", new MaximumWeightParser()).put("concurrencyLevel", new ConcurrencyLevelParser()).put("weakKeys", new KeyStrengthParser(Strength.WEAK)).put("softValues", new ValueStrengthParser(Strength.SOFT)).put("weakValues", new ValueStrengthParser(Strength.WEAK)).put("recordStats", new RecordStatsParser()).put("expireAfterAccess", new AccessDurationParser()).put("expireAfterWrite", new WriteDurationParser()).put("refreshAfterWrite", new RefreshDurationParser()).put("refreshInterval", new RefreshDurationParser()).build(); |
| 95 | |
| 96 | @VisibleForTesting Integer initialCapacity; |
| 97 | |
| 98 | @VisibleForTesting Long maximumSize; |
| 99 | |
| 100 | @VisibleForTesting Long maximumWeight; |
| 101 | |
| 102 | @VisibleForTesting Integer concurrencyLevel; |
| 103 | |
| 104 | @VisibleForTesting Strength keyStrength; |
| 105 | |
| 106 | @VisibleForTesting Strength valueStrength; |
| 107 | |
| 108 | @VisibleForTesting Boolean recordStats; |
| 109 | |
| 110 | @VisibleForTesting long writeExpirationDuration; |
| 111 | |
| 112 | @VisibleForTesting TimeUnit writeExpirationTimeUnit; |
| 113 | |
| 114 | @VisibleForTesting long accessExpirationDuration; |
| 115 | |
| 116 | @VisibleForTesting TimeUnit accessExpirationTimeUnit; |
| 117 | |
| 118 | @VisibleForTesting long refreshDuration; |
| 119 | |
| 120 | @VisibleForTesting TimeUnit refreshTimeUnit; |
| 121 | /** Specification; used for toParseableString(). */ |
| 122 | private final String specification; |
| 123 | private CacheBuilderSpec(String specification) { |
| 124 | this.specification = specification; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Creates a CacheBuilderSpec from a string. |
| 129 | * |
| 130 | * @param cacheBuilderSpecification the string form |
| 131 | */ |
| 132 | |
| 133 | |
| 134 | public static CacheBuilderSpec parse(String cacheBuilderSpecification) { |
| 135 | CacheBuilderSpec spec = new CacheBuilderSpec(cacheBuilderSpecification); |
nothing calls this directly
no test coverage detected