repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
EdwardRaff/JSAT
JSAT/src/jsat/distributions/kernels/RBFKernel.java
RBFKernel.setSigma
public void setSigma(double sigma) { if(sigma <= 0) throw new IllegalArgumentException("Sigma must be a positive constant, not " + sigma); this.sigma = sigma; this.sigmaSqrd2Inv = 0.5/(sigma*sigma); }
java
public void setSigma(double sigma) { if(sigma <= 0) throw new IllegalArgumentException("Sigma must be a positive constant, not " + sigma); this.sigma = sigma; this.sigmaSqrd2Inv = 0.5/(sigma*sigma); }
[ "public", "void", "setSigma", "(", "double", "sigma", ")", "{", "if", "(", "sigma", "<=", "0", ")", "throw", "new", "IllegalArgumentException", "(", "\"Sigma must be a positive constant, not \"", "+", "sigma", ")", ";", "this", ".", "sigma", "=", "sigma", ";",...
Sets the sigma parameter, which must be a positive value @param sigma the sigma value
[ "Sets", "the", "sigma", "parameter", "which", "must", "be", "a", "positive", "value" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/distributions/kernels/RBFKernel.java#L79-L85
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/boosting/WaggingNormal.java
WaggingNormal.setMean
public void setMean(double mean) { if(Double.isInfinite(mean) || Double.isNaN(mean)) throw new ArithmeticException("Mean must be a real number, not " + mean); ((Normal)getDistribution()).setMean(mean); }
java
public void setMean(double mean) { if(Double.isInfinite(mean) || Double.isNaN(mean)) throw new ArithmeticException("Mean must be a real number, not " + mean); ((Normal)getDistribution()).setMean(mean); }
[ "public", "void", "setMean", "(", "double", "mean", ")", "{", "if", "(", "Double", ".", "isInfinite", "(", "mean", ")", "||", "Double", ".", "isNaN", "(", "mean", ")", ")", "throw", "new", "ArithmeticException", "(", "\"Mean must be a real number, not \"", "...
Sets the mean value used for the normal distribution @param mean the new mean value
[ "Sets", "the", "mean", "value", "used", "for", "the", "normal", "distribution" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/boosting/WaggingNormal.java#L66-L71
train
EdwardRaff/JSAT
JSAT/src/jsat/classifiers/boosting/WaggingNormal.java
WaggingNormal.setStandardDeviations
public void setStandardDeviations(double devs) { if(devs <= 0 || Double.isInfinite(devs) || Double.isNaN(devs)) throw new ArithmeticException("The stnd devs must be a positive value"); ((Normal)getDistribution()).setStndDev(devs); }
java
public void setStandardDeviations(double devs) { if(devs <= 0 || Double.isInfinite(devs) || Double.isNaN(devs)) throw new ArithmeticException("The stnd devs must be a positive value"); ((Normal)getDistribution()).setStndDev(devs); }
[ "public", "void", "setStandardDeviations", "(", "double", "devs", ")", "{", "if", "(", "devs", "<=", "0", "||", "Double", ".", "isInfinite", "(", "devs", ")", "||", "Double", ".", "isNaN", "(", "devs", ")", ")", "throw", "new", "ArithmeticException", "("...
Sets the standard deviations used for the normal distribution @param devs the standard deviations to set
[ "Sets", "the", "standard", "deviations", "used", "for", "the", "normal", "distribution" ]
0ff53b7b39684b2379cc1da522f5b3a954b15cfb
https://github.com/EdwardRaff/JSAT/blob/0ff53b7b39684b2379cc1da522f5b3a954b15cfb/JSAT/src/jsat/classifiers/boosting/WaggingNormal.java#L86-L91
train
JodaOrg/joda-money
src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java
DefaultCurrencyUnitDataProvider.registerCurrencies
@Override protected void registerCurrencies() throws Exception { parseCurrencies(loadFromFile("/org/joda/money/CurrencyData.csv")); parseCountries(loadFromFile("/org/joda/money/CountryData.csv")); parseCurrencies(loadFromFiles("META-INF/org/joda/money/CurrencyDataExtension.csv")); parseCountries(loadFromFiles("META-INF/org/joda/money/CountryDataExtension.csv")); }
java
@Override protected void registerCurrencies() throws Exception { parseCurrencies(loadFromFile("/org/joda/money/CurrencyData.csv")); parseCountries(loadFromFile("/org/joda/money/CountryData.csv")); parseCurrencies(loadFromFiles("META-INF/org/joda/money/CurrencyDataExtension.csv")); parseCountries(loadFromFiles("META-INF/org/joda/money/CountryDataExtension.csv")); }
[ "@", "Override", "protected", "void", "registerCurrencies", "(", ")", "throws", "Exception", "{", "parseCurrencies", "(", "loadFromFile", "(", "\"/org/joda/money/CurrencyData.csv\"", ")", ")", ";", "parseCountries", "(", "loadFromFile", "(", "\"/org/joda/money/CountryData...
Registers all the currencies known by this provider. @throws Exception if an error occurs
[ "Registers", "all", "the", "currencies", "known", "by", "this", "provider", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java#L54-L60
train
JodaOrg/joda-money
src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java
DefaultCurrencyUnitDataProvider.parseCurrencies
private void parseCurrencies(List<String> content) throws Exception { for (String line : content) { Matcher matcher = CURRENCY_REGEX_LINE.matcher(line); if (matcher.matches()) { String currencyCode = matcher.group(1); int numericCode = Integer.parseInt(matcher.group(2)); int digits = Integer.parseInt(matcher.group(3)); registerCurrency(currencyCode, numericCode, digits); } } }
java
private void parseCurrencies(List<String> content) throws Exception { for (String line : content) { Matcher matcher = CURRENCY_REGEX_LINE.matcher(line); if (matcher.matches()) { String currencyCode = matcher.group(1); int numericCode = Integer.parseInt(matcher.group(2)); int digits = Integer.parseInt(matcher.group(3)); registerCurrency(currencyCode, numericCode, digits); } } }
[ "private", "void", "parseCurrencies", "(", "List", "<", "String", ">", "content", ")", "throws", "Exception", "{", "for", "(", "String", "line", ":", "content", ")", "{", "Matcher", "matcher", "=", "CURRENCY_REGEX_LINE", ".", "matcher", "(", "line", ")", "...
parse the currencies
[ "parse", "the", "currencies" ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java#L96-L106
train
JodaOrg/joda-money
src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java
DefaultCurrencyUnitDataProvider.parseCountries
private void parseCountries(List<String> content) throws Exception { for (String line : content) { Matcher matcher = COUNTRY_REGEX_LINE.matcher(line); if (matcher.matches()) { String countryCode = matcher.group(1); String currencyCode = matcher.group(2); registerCountry(countryCode, currencyCode); } } }
java
private void parseCountries(List<String> content) throws Exception { for (String line : content) { Matcher matcher = COUNTRY_REGEX_LINE.matcher(line); if (matcher.matches()) { String countryCode = matcher.group(1); String currencyCode = matcher.group(2); registerCountry(countryCode, currencyCode); } } }
[ "private", "void", "parseCountries", "(", "List", "<", "String", ">", "content", ")", "throws", "Exception", "{", "for", "(", "String", "line", ":", "content", ")", "{", "Matcher", "matcher", "=", "COUNTRY_REGEX_LINE", ".", "matcher", "(", "line", ")", ";"...
parse the countries
[ "parse", "the", "countries" ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/DefaultCurrencyUnitDataProvider.java#L109-L118
train
JodaOrg/joda-money
src/main/java/org/joda/money/format/MoneyAmountStyle.java
MoneyAmountStyle.withGroupingSize
public MoneyAmountStyle withGroupingSize(Integer groupingSize) { int sizeVal = (groupingSize == null ? -1 : groupingSize); if (groupingSize != null && sizeVal <= 0) { throw new IllegalArgumentException("Grouping size must be greater than zero"); } if (sizeVal == this.groupingSize) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, sizeVal, extendedGroupingSize, forceDecimalPoint, absValue); }
java
public MoneyAmountStyle withGroupingSize(Integer groupingSize) { int sizeVal = (groupingSize == null ? -1 : groupingSize); if (groupingSize != null && sizeVal <= 0) { throw new IllegalArgumentException("Grouping size must be greater than zero"); } if (sizeVal == this.groupingSize) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, sizeVal, extendedGroupingSize, forceDecimalPoint, absValue); }
[ "public", "MoneyAmountStyle", "withGroupingSize", "(", "Integer", "groupingSize", ")", "{", "int", "sizeVal", "=", "(", "groupingSize", "==", "null", "?", "-", "1", ":", "groupingSize", ")", ";", "if", "(", "groupingSize", "!=", "null", "&&", "sizeVal", "<="...
Returns a copy of this style with the specified grouping size. @param groupingSize the size of each group, such as 3 for thousands, not zero or negative, null if to be determined by locale @return the new instance for chaining, never null @throws IllegalArgumentException if the grouping size is zero or less
[ "Returns", "a", "copy", "of", "this", "style", "with", "the", "specified", "grouping", "size", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/format/MoneyAmountStyle.java#L469-L482
train
JodaOrg/joda-money
src/main/java/org/joda/money/format/MoneyAmountStyle.java
MoneyAmountStyle.withExtendedGroupingSize
public MoneyAmountStyle withExtendedGroupingSize(Integer extendedGroupingSize) { int sizeVal = (extendedGroupingSize == null ? -1 : extendedGroupingSize); if (extendedGroupingSize != null && sizeVal < 0) { throw new IllegalArgumentException("Extended grouping size must not be negative"); } if (sizeVal == this.extendedGroupingSize) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, groupingSize, sizeVal, forceDecimalPoint, absValue); }
java
public MoneyAmountStyle withExtendedGroupingSize(Integer extendedGroupingSize) { int sizeVal = (extendedGroupingSize == null ? -1 : extendedGroupingSize); if (extendedGroupingSize != null && sizeVal < 0) { throw new IllegalArgumentException("Extended grouping size must not be negative"); } if (sizeVal == this.extendedGroupingSize) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, groupingSize, sizeVal, forceDecimalPoint, absValue); }
[ "public", "MoneyAmountStyle", "withExtendedGroupingSize", "(", "Integer", "extendedGroupingSize", ")", "{", "int", "sizeVal", "=", "(", "extendedGroupingSize", "==", "null", "?", "-", "1", ":", "extendedGroupingSize", ")", ";", "if", "(", "extendedGroupingSize", "!=...
Returns a copy of this style with the specified extended grouping size. @param extendedGroupingSize the size of each group, such as 3 for thousands, not zero or negative, null if to be determined by locale @return the new instance for chaining, never null @throws IllegalArgumentException if the grouping size is zero or less
[ "Returns", "a", "copy", "of", "this", "style", "with", "the", "specified", "extended", "grouping", "size", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/format/MoneyAmountStyle.java#L507-L520
train
JodaOrg/joda-money
src/main/java/org/joda/money/format/MoneyAmountStyle.java
MoneyAmountStyle.withGroupingStyle
public MoneyAmountStyle withGroupingStyle(GroupingStyle groupingStyle) { MoneyFormatter.checkNotNull(groupingStyle, "groupingStyle"); if (this.groupingStyle == groupingStyle) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, groupingSize, extendedGroupingSize, forceDecimalPoint, absValue); }
java
public MoneyAmountStyle withGroupingStyle(GroupingStyle groupingStyle) { MoneyFormatter.checkNotNull(groupingStyle, "groupingStyle"); if (this.groupingStyle == groupingStyle) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, groupingSize, extendedGroupingSize, forceDecimalPoint, absValue); }
[ "public", "MoneyAmountStyle", "withGroupingStyle", "(", "GroupingStyle", "groupingStyle", ")", "{", "MoneyFormatter", ".", "checkNotNull", "(", "groupingStyle", ",", "\"groupingStyle\"", ")", ";", "if", "(", "this", ".", "groupingStyle", "==", "groupingStyle", ")", ...
Returns a copy of this style with the specified grouping setting. @param groupingStyle the grouping style, not null @return the new instance for chaining, never null
[ "Returns", "a", "copy", "of", "this", "style", "with", "the", "specified", "grouping", "setting", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/format/MoneyAmountStyle.java#L538-L548
train
JodaOrg/joda-money
src/main/java/org/joda/money/format/MoneyAmountStyle.java
MoneyAmountStyle.withForcedDecimalPoint
public MoneyAmountStyle withForcedDecimalPoint(boolean forceDecimalPoint) { if (this.forceDecimalPoint == forceDecimalPoint) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, groupingSize, extendedGroupingSize, forceDecimalPoint, absValue); }
java
public MoneyAmountStyle withForcedDecimalPoint(boolean forceDecimalPoint) { if (this.forceDecimalPoint == forceDecimalPoint) { return this; } return new MoneyAmountStyle( zeroCharacter, positiveCharacter, negativeCharacter, decimalPointCharacter, groupingStyle, groupingCharacter, groupingSize, extendedGroupingSize, forceDecimalPoint, absValue); }
[ "public", "MoneyAmountStyle", "withForcedDecimalPoint", "(", "boolean", "forceDecimalPoint", ")", "{", "if", "(", "this", ".", "forceDecimalPoint", "==", "forceDecimalPoint", ")", "{", "return", "this", ";", "}", "return", "new", "MoneyAmountStyle", "(", "zeroCharac...
Returns a copy of this style with the specified decimal point setting. @param forceDecimalPoint true to force the use of the decimal point, false to use it if required @return the new instance for chaining, never null
[ "Returns", "a", "copy", "of", "this", "style", "with", "the", "specified", "decimal", "point", "setting", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/format/MoneyAmountStyle.java#L566-L575
train
JodaOrg/joda-money
src/main/java/org/joda/money/BigMoney.java
BigMoney.checkCurrencyEqual
private BigMoney checkCurrencyEqual(BigMoneyProvider moneyProvider) { BigMoney money = of(moneyProvider); if (isSameCurrency(money) == false) { throw new CurrencyMismatchException(getCurrencyUnit(), money.getCurrencyUnit()); } return money; }
java
private BigMoney checkCurrencyEqual(BigMoneyProvider moneyProvider) { BigMoney money = of(moneyProvider); if (isSameCurrency(money) == false) { throw new CurrencyMismatchException(getCurrencyUnit(), money.getCurrencyUnit()); } return money; }
[ "private", "BigMoney", "checkCurrencyEqual", "(", "BigMoneyProvider", "moneyProvider", ")", "{", "BigMoney", "money", "=", "of", "(", "moneyProvider", ")", ";", "if", "(", "isSameCurrency", "(", "money", ")", "==", "false", ")", "{", "throw", "new", "CurrencyM...
Validates that the currency of this money and the specified money match. @param moneyProvider the money to check, not null @throws CurrencyMismatchException if the currencies differ
[ "Validates", "that", "the", "currency", "of", "this", "money", "and", "the", "specified", "money", "match", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/BigMoney.java#L803-L809
train
JodaOrg/joda-money
src/main/java/org/joda/money/BigMoney.java
BigMoney.compareTo
@Override public int compareTo(BigMoneyProvider other) { BigMoney otherMoney = of(other); if (currency.equals(otherMoney.currency) == false) { throw new CurrencyMismatchException(getCurrencyUnit(), otherMoney.getCurrencyUnit()); } return amount.compareTo(otherMoney.amount); }
java
@Override public int compareTo(BigMoneyProvider other) { BigMoney otherMoney = of(other); if (currency.equals(otherMoney.currency) == false) { throw new CurrencyMismatchException(getCurrencyUnit(), otherMoney.getCurrencyUnit()); } return amount.compareTo(otherMoney.amount); }
[ "@", "Override", "public", "int", "compareTo", "(", "BigMoneyProvider", "other", ")", "{", "BigMoney", "otherMoney", "=", "of", "(", "other", ")", ";", "if", "(", "currency", ".", "equals", "(", "otherMoney", ".", "currency", ")", "==", "false", ")", "{"...
Compares this monetary value to another. The compared values must be in the same currency. @param other the other monetary value, not null @return -1 if this is less than , 0 if equal, 1 if greater than @throws CurrencyMismatchException if the currencies differ
[ "Compares", "this", "monetary", "value", "to", "another", ".", "The", "compared", "values", "must", "be", "in", "the", "same", "currency", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/BigMoney.java#L1603-L1610
train
JodaOrg/joda-money
src/main/java/org/joda/money/format/MoneyParseContext.java
MoneyParseContext.mergeChild
void mergeChild(MoneyParseContext child) { setLocale(child.getLocale()); setText(child.getText()); setIndex(child.getIndex()); setErrorIndex(child.getErrorIndex()); setCurrency(child.getCurrency()); setAmount(child.getAmount()); }
java
void mergeChild(MoneyParseContext child) { setLocale(child.getLocale()); setText(child.getText()); setIndex(child.getIndex()); setErrorIndex(child.getErrorIndex()); setCurrency(child.getCurrency()); setAmount(child.getAmount()); }
[ "void", "mergeChild", "(", "MoneyParseContext", "child", ")", "{", "setLocale", "(", "child", ".", "getLocale", "(", ")", ")", ";", "setText", "(", "child", ".", "getText", "(", ")", ")", ";", "setIndex", "(", "child", ".", "getIndex", "(", ")", ")", ...
Merges the child context back into this instance. @param child the child context, not null
[ "Merges", "the", "child", "context", "back", "into", "this", "instance", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/format/MoneyParseContext.java#L276-L283
train
JodaOrg/joda-money
src/main/java/org/joda/money/format/MoneyParseContext.java
MoneyParseContext.toParsePosition
public ParsePosition toParsePosition() { ParsePosition pp = new ParsePosition(textIndex); pp.setErrorIndex(textErrorIndex); return pp; }
java
public ParsePosition toParsePosition() { ParsePosition pp = new ParsePosition(textIndex); pp.setErrorIndex(textErrorIndex); return pp; }
[ "public", "ParsePosition", "toParsePosition", "(", ")", "{", "ParsePosition", "pp", "=", "new", "ParsePosition", "(", "textIndex", ")", ";", "pp", ".", "setErrorIndex", "(", "textErrorIndex", ")", ";", "return", "pp", ";", "}" ]
Converts the indexes to a parse position. @return the parse position, never null
[ "Converts", "the", "indexes", "to", "a", "parse", "position", "." ]
e1f2de75aa36610a695358696c8a88a18ca66cde
https://github.com/JodaOrg/joda-money/blob/e1f2de75aa36610a695358696c8a88a18ca66cde/src/main/java/org/joda/money/format/MoneyParseContext.java#L291-L295
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheAdapter.java
JCacheAdapter.iterator
@Override public Iterator<Entry<K,V>> iterator() { checkClosed(); final Iterator<K> _keyIterator = cache.keys().iterator(); return new Iterator<Entry<K, V>>() { CacheEntry<K, V> entry; @Override public boolean hasNext() { while(_keyIterator.hasNext()) { entry = cache.getEntry(_keyIterator.next()); if (entry.getException() == null) { return true; } } entry = null; return false; } @Override public Entry<K, V> next() { if (entry == null && !hasNext()) { throw new NoSuchElementException(); } return new Entry<K, V>() { @Override public K getKey() { return entry.getKey(); } @Override public V getValue() { return entry.getValue(); } @SuppressWarnings("unchecked") @Override public <T> T unwrap(Class<T> _class) { if (CacheEntry.class.equals(_class)) { return (T) entry; } return null; } }; } @Override public void remove() { if (entry == null) { throw new IllegalStateException("hasNext() / next() not called or end of iteration reached"); } cache.remove(entry.getKey()); } }; }
java
@Override public Iterator<Entry<K,V>> iterator() { checkClosed(); final Iterator<K> _keyIterator = cache.keys().iterator(); return new Iterator<Entry<K, V>>() { CacheEntry<K, V> entry; @Override public boolean hasNext() { while(_keyIterator.hasNext()) { entry = cache.getEntry(_keyIterator.next()); if (entry.getException() == null) { return true; } } entry = null; return false; } @Override public Entry<K, V> next() { if (entry == null && !hasNext()) { throw new NoSuchElementException(); } return new Entry<K, V>() { @Override public K getKey() { return entry.getKey(); } @Override public V getValue() { return entry.getValue(); } @SuppressWarnings("unchecked") @Override public <T> T unwrap(Class<T> _class) { if (CacheEntry.class.equals(_class)) { return (T) entry; } return null; } }; } @Override public void remove() { if (entry == null) { throw new IllegalStateException("hasNext() / next() not called or end of iteration reached"); } cache.remove(entry.getKey()); } }; }
[ "@", "Override", "public", "Iterator", "<", "Entry", "<", "K", ",", "V", ">", ">", "iterator", "(", ")", "{", "checkClosed", "(", ")", ";", "final", "Iterator", "<", "K", ">", "_keyIterator", "=", "cache", ".", "keys", "(", ")", ".", "iterator", "(...
Iterate with the help of cache2k key iterator.
[ "Iterate", "with", "the", "help", "of", "cache2k", "key", "iterator", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheAdapter.java#L451-L506
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/CacheManager.java
CacheManager.getInstance
public static CacheManager getInstance() { ClassLoader _defaultClassLoader = PROVIDER.getDefaultClassLoader(); return PROVIDER.getManager(_defaultClassLoader, PROVIDER.getDefaultManagerName(_defaultClassLoader)); }
java
public static CacheManager getInstance() { ClassLoader _defaultClassLoader = PROVIDER.getDefaultClassLoader(); return PROVIDER.getManager(_defaultClassLoader, PROVIDER.getDefaultManagerName(_defaultClassLoader)); }
[ "public", "static", "CacheManager", "getInstance", "(", ")", "{", "ClassLoader", "_defaultClassLoader", "=", "PROVIDER", ".", "getDefaultClassLoader", "(", ")", ";", "return", "PROVIDER", ".", "getManager", "(", "_defaultClassLoader", ",", "PROVIDER", ".", "getDefau...
Get the default cache manager for the default class loader. The default class loader is the class loader used to load the cache2k implementation classes. <p>The name of default cache manager is {@code "default"}. This may be changed, by {@link #setDefaultName(String)}.
[ "Get", "the", "default", "cache", "manager", "for", "the", "default", "class", "loader", ".", "The", "default", "class", "loader", "is", "the", "class", "loader", "used", "to", "load", "the", "cache2k", "implementation", "classes", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/CacheManager.java#L87-L90
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/CacheManager.java
CacheManager.getInstance
public static CacheManager getInstance(ClassLoader cl) { return PROVIDER.getManager(cl, PROVIDER.getDefaultManagerName(cl)); }
java
public static CacheManager getInstance(ClassLoader cl) { return PROVIDER.getManager(cl, PROVIDER.getDefaultManagerName(cl)); }
[ "public", "static", "CacheManager", "getInstance", "(", "ClassLoader", "cl", ")", "{", "return", "PROVIDER", ".", "getManager", "(", "cl", ",", "PROVIDER", ".", "getDefaultManagerName", "(", "cl", ")", ")", ";", "}" ]
Get the default cache manager for the specified class loader.
[ "Get", "the", "default", "cache", "manager", "for", "the", "specified", "class", "loader", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/CacheManager.java#L95-L97
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/CacheManager.java
CacheManager.getInstance
public static CacheManager getInstance(ClassLoader cl, String managerName) { return PROVIDER.getManager(cl, managerName); }
java
public static CacheManager getInstance(ClassLoader cl, String managerName) { return PROVIDER.getManager(cl, managerName); }
[ "public", "static", "CacheManager", "getInstance", "(", "ClassLoader", "cl", ",", "String", "managerName", ")", "{", "return", "PROVIDER", ".", "getManager", "(", "cl", ",", "managerName", ")", ";", "}" ]
Retrieve a cache manager with the specified name using the specified classloader. If not existing, a manager with that name is created. Different cache managers are created for different class loaders. Manager names should be unique within one VM instance. <p>The allowed characters in a manager name are identical to the characters in a cache name, this is documented at {@link Cache2kBuilder#name(String)} @see Cache2kBuilder#name(String)
[ "Retrieve", "a", "cache", "manager", "with", "the", "specified", "name", "using", "the", "specified", "classloader", ".", "If", "not", "existing", "a", "manager", "with", "that", "name", "is", "created", ".", "Different", "cache", "managers", "are", "created",...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/CacheManager.java#L123-L125
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.of
public static <K,T> Cache2kBuilder<K,T> of(Class<K> _keyType, Class<T> _valueType) { return new Cache2kBuilder<K, T>(CacheTypeCapture.of(_keyType), CacheTypeCapture.of(_valueType)); }
java
public static <K,T> Cache2kBuilder<K,T> of(Class<K> _keyType, Class<T> _valueType) { return new Cache2kBuilder<K, T>(CacheTypeCapture.of(_keyType), CacheTypeCapture.of(_valueType)); }
[ "public", "static", "<", "K", ",", "T", ">", "Cache2kBuilder", "<", "K", ",", "T", ">", "of", "(", "Class", "<", "K", ">", "_keyType", ",", "Class", "<", "T", ">", "_valueType", ")", "{", "return", "new", "Cache2kBuilder", "<", "K", ",", "T", ">"...
Create a new cache builder for key and value types of classes with no generic parameters. @see #keyType(Class) @see #valueType(Class)
[ "Create", "a", "new", "cache", "builder", "for", "key", "and", "value", "types", "of", "classes", "with", "no", "generic", "parameters", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L99-L101
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.of
public static <K,T> Cache2kBuilder<K, T> of(Cache2kConfiguration<K, T> c) { Cache2kBuilder<K,T> cb = new Cache2kBuilder<K, T>(c); return cb; }
java
public static <K,T> Cache2kBuilder<K, T> of(Cache2kConfiguration<K, T> c) { Cache2kBuilder<K,T> cb = new Cache2kBuilder<K, T>(c); return cb; }
[ "public", "static", "<", "K", ",", "T", ">", "Cache2kBuilder", "<", "K", ",", "T", ">", "of", "(", "Cache2kConfiguration", "<", "K", ",", "T", ">", "c", ")", "{", "Cache2kBuilder", "<", "K", ",", "T", ">", "cb", "=", "new", "Cache2kBuilder", "<", ...
Create a builder from the configuration.
[ "Create", "a", "builder", "from", "the", "configuration", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L106-L109
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.manager
public final Cache2kBuilder<K, V> manager(CacheManager manager) { if (this.manager != null) { throw new IllegalStateException("manager() must be first operation on builder."); } this.manager = manager; return this; }
java
public final Cache2kBuilder<K, V> manager(CacheManager manager) { if (this.manager != null) { throw new IllegalStateException("manager() must be first operation on builder."); } this.manager = manager; return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "manager", "(", "CacheManager", "manager", ")", "{", "if", "(", "this", ".", "manager", "!=", "null", ")", "{", "throw", "new", "IllegalStateException", "(", "\"manager() must be first operation on bu...
The manager, the created cache will belong to. If this is set, it must be the first method called. @param manager The manager the created cache should belong to, or {@code null} if the default cache manager should be used @throws IllegalStateException if the manager is not provided immediately after the builder is created.
[ "The", "manager", "the", "created", "cache", "will", "belong", "to", ".", "If", "this", "is", "set", "it", "must", "be", "the", "first", "method", "called", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L182-L188
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.valueType
@SuppressWarnings("unchecked") public final <T2> Cache2kBuilder<K, T2> valueType(CacheType<T2> t) { Cache2kBuilder<K, T2> me = (Cache2kBuilder<K, T2>) this; me.config().setValueType(t); return me; }
java
@SuppressWarnings("unchecked") public final <T2> Cache2kBuilder<K, T2> valueType(CacheType<T2> t) { Cache2kBuilder<K, T2> me = (Cache2kBuilder<K, T2>) this; me.config().setValueType(t); return me; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "final", "<", "T2", ">", "Cache2kBuilder", "<", "K", ",", "T2", ">", "valueType", "(", "CacheType", "<", "T2", ">", "t", ")", "{", "Cache2kBuilder", "<", "K", ",", "T2", ">", "me", "=", "(...
Sets the value type to use. Arrays are not supported. @throws IllegalArgumentException in case the type is illegal @see CacheType for a general discussion on types
[ "Sets", "the", "value", "type", "to", "use", ".", "Arrays", "are", "not", "supported", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L237-L242
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.name
public final Cache2kBuilder<K, V> name(Class<?> _class) { config().setName(_class.getName()); return this; }
java
public final Cache2kBuilder<K, V> name(Class<?> _class) { config().setName(_class.getName()); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "name", "(", "Class", "<", "?", ">", "_class", ")", "{", "config", "(", ")", ".", "setName", "(", "_class", ".", "getName", "(", ")", ")", ";", "return", "this", ";", "}" ]
Sets a cache name from the fully qualified class name. <p>See {@link #name(String)} for a general discussion about cache names. @see #name(String)
[ "Sets", "a", "cache", "name", "from", "the", "fully", "qualified", "class", "name", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L288-L291
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.wrapCustomizationInstance
private static <T> CustomizationReferenceSupplier<T> wrapCustomizationInstance(T obj) { if (obj == null) { return null; } return new CustomizationReferenceSupplier<T>(obj); }
java
private static <T> CustomizationReferenceSupplier<T> wrapCustomizationInstance(T obj) { if (obj == null) { return null; } return new CustomizationReferenceSupplier<T>(obj); }
[ "private", "static", "<", "T", ">", "CustomizationReferenceSupplier", "<", "T", ">", "wrapCustomizationInstance", "(", "T", "obj", ")", "{", "if", "(", "obj", "==", "null", ")", "{", "return", "null", ";", "}", "return", "new", "CustomizationReferenceSupplier"...
Wraps to factory but passes on nulls.
[ "Wraps", "to", "factory", "but", "passes", "on", "nulls", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L424-L427
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.wrappingLoader
@SuppressWarnings("unchecked") public final Cache2kBuilder<K, V> wrappingLoader(AdvancedCacheLoader<K, LoadDetail<V>> l) { config().setAdvancedLoader(( CustomizationSupplier<AdvancedCacheLoader<K, V>>) (Object) wrapCustomizationInstance(l)); return this; }
java
@SuppressWarnings("unchecked") public final Cache2kBuilder<K, V> wrappingLoader(AdvancedCacheLoader<K, LoadDetail<V>> l) { config().setAdvancedLoader(( CustomizationSupplier<AdvancedCacheLoader<K, V>>) (Object) wrapCustomizationInstance(l)); return this; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "wrappingLoader", "(", "AdvancedCacheLoader", "<", "K", ",", "LoadDetail", "<", "V", ">", ">", "l", ")", "{", "config", "(", ")", ".", "setA...
Enables read through operation and sets a cache loader @see CacheLoader for general discussion on cache loaders
[ "Enables", "read", "through", "operation", "and", "sets", "a", "cache", "loader" ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L482-L487
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.writer
public final Cache2kBuilder<K, V> writer(CacheWriter<K, V> w) { config().setWriter(wrapCustomizationInstance(w)); return this; }
java
public final Cache2kBuilder<K, V> writer(CacheWriter<K, V> w) { config().setWriter(wrapCustomizationInstance(w)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "writer", "(", "CacheWriter", "<", "K", ",", "V", ">", "w", ")", "{", "config", "(", ")", ".", "setWriter", "(", "wrapCustomizationInstance", "(", "w", ")", ")", ";", "return", "this", ";"...
Enables write through operation and sets a writer customization that gets called synchronously upon cache mutations. By default write through is not enabled.
[ "Enables", "write", "through", "operation", "and", "sets", "a", "writer", "customization", "that", "gets", "called", "synchronously", "upon", "cache", "mutations", ".", "By", "default", "write", "through", "is", "not", "enabled", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L517-L520
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.addCacheClosedListener
public final Cache2kBuilder<K, V> addCacheClosedListener(CacheClosedListener listener) { config().getCacheClosedListeners().add(wrapCustomizationInstance(listener)); return this; }
java
public final Cache2kBuilder<K, V> addCacheClosedListener(CacheClosedListener listener) { config().getCacheClosedListeners().add(wrapCustomizationInstance(listener)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "addCacheClosedListener", "(", "CacheClosedListener", "listener", ")", "{", "config", "(", ")", ".", "getCacheClosedListeners", "(", ")", ".", "add", "(", "wrapCustomizationInstance", "(", "listener", ...
Listener that is called after a cache is closed. This is mainly used for the JCache integration.
[ "Listener", "that", "is", "called", "after", "a", "cache", "is", "closed", ".", "This", "is", "mainly", "used", "for", "the", "JCache", "integration", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L525-L528
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.addListener
public final Cache2kBuilder<K, V> addListener(CacheEntryOperationListener<K,V> listener) { config().getListeners().add(wrapCustomizationInstance(listener)); return this; }
java
public final Cache2kBuilder<K, V> addListener(CacheEntryOperationListener<K,V> listener) { config().getListeners().add(wrapCustomizationInstance(listener)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "addListener", "(", "CacheEntryOperationListener", "<", "K", ",", "V", ">", "listener", ")", "{", "config", "(", ")", ".", "getListeners", "(", ")", ".", "add", "(", "wrapCustomizationInstance", ...
Add a listener. The listeners will be executed in a synchronous mode, meaning, further processing for an entry will stall until a registered listener is executed. The expiry will be always executed asynchronously. @throws IllegalArgumentException if an identical listener is already added. @param listener The listener to add
[ "Add", "a", "listener", ".", "The", "listeners", "will", "be", "executed", "in", "a", "synchronous", "mode", "meaning", "further", "processing", "for", "an", "entry", "will", "stall", "until", "a", "registered", "listener", "is", "executed", ".", "The", "exp...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L538-L541
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.addAsyncListener
public final Cache2kBuilder<K,V> addAsyncListener(CacheEntryOperationListener<K,V> listener) { config().getAsyncListeners().add(wrapCustomizationInstance(listener)); return this; }
java
public final Cache2kBuilder<K,V> addAsyncListener(CacheEntryOperationListener<K,V> listener) { config().getAsyncListeners().add(wrapCustomizationInstance(listener)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "addAsyncListener", "(", "CacheEntryOperationListener", "<", "K", ",", "V", ">", "listener", ")", "{", "config", "(", ")", ".", "getAsyncListeners", "(", ")", ".", "add", "(", "wrapCustomizationIn...
A set of listeners. Listeners added in this collection will be executed in a asynchronous mode. @throws IllegalArgumentException if an identical listener is already added. @param listener The listener to add
[ "A", "set", "of", "listeners", ".", "Listeners", "added", "in", "this", "collection", "will", "be", "executed", "in", "a", "asynchronous", "mode", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L550-L553
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.expiryPolicy
public final Cache2kBuilder<K, V> expiryPolicy(ExpiryPolicy<K, V> c) { config().setExpiryPolicy(wrapCustomizationInstance(c)); return this; }
java
public final Cache2kBuilder<K, V> expiryPolicy(ExpiryPolicy<K, V> c) { config().setExpiryPolicy(wrapCustomizationInstance(c)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "expiryPolicy", "(", "ExpiryPolicy", "<", "K", ",", "V", ">", "c", ")", "{", "config", "(", ")", ".", "setExpiryPolicy", "(", "wrapCustomizationInstance", "(", "c", ")", ")", ";", "return", ...
Set expiry policy to use. <p>If this is specified the maximum expiry time is still limited to the value in {@link #expireAfterWrite}. If {@link #expireAfterWrite(long, java.util.concurrent.TimeUnit)} is set to 0 then expiry calculation is not used, all entries expire immediately. <p>If no maximum expiry is specified via {@link #expireAfterWrite} at least the {@link #resilienceDuration} needs to be specified, if resilience should be enabled.
[ "Set", "expiry", "policy", "to", "use", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L565-L568
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.maxRetryInterval
public final Cache2kBuilder<K, V> maxRetryInterval(long v, TimeUnit u) { config().setMaxRetryInterval(u.toMillis(v)); return this; }
java
public final Cache2kBuilder<K, V> maxRetryInterval(long v, TimeUnit u) { config().setMaxRetryInterval(u.toMillis(v)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "maxRetryInterval", "(", "long", "v", ",", "TimeUnit", "u", ")", "{", "config", "(", ")", ".", "setMaxRetryInterval", "(", "u", ".", "toMillis", "(", "v", ")", ")", ";", "return", "this", ...
If a loader exception happens, this is the maximum time interval after a retry attempt is made. For retries an exponential backoff algorithm is used. It starts with the retry time and then increases the time to the maximum according to an exponential pattern. <p>By default identical to {@link #resilienceDuration}
[ "If", "a", "loader", "exception", "happens", "this", "is", "the", "maximum", "time", "interval", "after", "a", "retry", "attempt", "is", "made", ".", "For", "retries", "an", "exponential", "backoff", "algorithm", "is", "used", ".", "It", "starts", "with", ...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L656-L659
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.with
public final Cache2kBuilder<K, V> with(ConfigurationSectionBuilder<? extends ConfigurationSection>... sectionBuilders) { for (ConfigurationSectionBuilder<? extends ConfigurationSection> b : sectionBuilders) { config().getSections().add(b.buildConfigurationSection()); } return this; }
java
public final Cache2kBuilder<K, V> with(ConfigurationSectionBuilder<? extends ConfigurationSection>... sectionBuilders) { for (ConfigurationSectionBuilder<? extends ConfigurationSection> b : sectionBuilders) { config().getSections().add(b.buildConfigurationSection()); } return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "with", "(", "ConfigurationSectionBuilder", "<", "?", "extends", "ConfigurationSection", ">", "...", "sectionBuilders", ")", "{", "for", "(", "ConfigurationSectionBuilder", "<", "?", "extends", "Configu...
Add a new configuration sub section. @see org.cache2k.configuration.ConfigurationWithSections
[ "Add", "a", "new", "configuration", "sub", "section", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L690-L695
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.asyncListenerExecutor
public final Cache2kBuilder<K,V> asyncListenerExecutor(Executor v) { config().setAsyncListenerExecutor(new CustomizationReferenceSupplier<Executor>(v)); return this; }
java
public final Cache2kBuilder<K,V> asyncListenerExecutor(Executor v) { config().setAsyncListenerExecutor(new CustomizationReferenceSupplier<Executor>(v)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "asyncListenerExecutor", "(", "Executor", "v", ")", "{", "config", "(", ")", ".", "setAsyncListenerExecutor", "(", "new", "CustomizationReferenceSupplier", "<", "Executor", ">", "(", "v", ")", ")", ...
Executor for asynchronous listeners. If no executor is specified, an internal executor is used that has unbounded thread capacity. @see #addAsyncListener(CacheEntryOperationListener)
[ "Executor", "for", "asynchronous", "listeners", ".", "If", "no", "executor", "is", "specified", "an", "internal", "executor", "is", "used", "that", "has", "unbounded", "thread", "capacity", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L806-L809
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java
Cache2kBuilder.timeReference
public final Cache2kBuilder<K, V> timeReference(TimeReference v) { config().setTimeReference(new CustomizationReferenceSupplier<TimeReference>(v)); return this; }
java
public final Cache2kBuilder<K, V> timeReference(TimeReference v) { config().setTimeReference(new CustomizationReferenceSupplier<TimeReference>(v)); return this; }
[ "public", "final", "Cache2kBuilder", "<", "K", ",", "V", ">", "timeReference", "(", "TimeReference", "v", ")", "{", "config", "(", ")", ".", "setTimeReference", "(", "new", "CustomizationReferenceSupplier", "<", "TimeReference", ">", "(", "v", ")", ")", ";",...
Clock to be used by the cache as time reference.
[ "Clock", "to", "be", "used", "by", "the", "cache", "as", "time", "reference", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/Cache2kBuilder.java#L814-L817
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/TimingHandler.java
TimingHandler.limitExpiryToMaxLinger
static long limitExpiryToMaxLinger(long now, long _maxLinger, long _requestedExpiryTime, boolean _sharpExpiryEnabled) { if (_sharpExpiryEnabled && _requestedExpiryTime > ExpiryPolicy.REFRESH && _requestedExpiryTime < ExpiryPolicy.ETERNAL) { _requestedExpiryTime = -_requestedExpiryTime; } return Expiry.mixTimeSpanAndPointInTime(now, _maxLinger, _requestedExpiryTime); }
java
static long limitExpiryToMaxLinger(long now, long _maxLinger, long _requestedExpiryTime, boolean _sharpExpiryEnabled) { if (_sharpExpiryEnabled && _requestedExpiryTime > ExpiryPolicy.REFRESH && _requestedExpiryTime < ExpiryPolicy.ETERNAL) { _requestedExpiryTime = -_requestedExpiryTime; } return Expiry.mixTimeSpanAndPointInTime(now, _maxLinger, _requestedExpiryTime); }
[ "static", "long", "limitExpiryToMaxLinger", "(", "long", "now", ",", "long", "_maxLinger", ",", "long", "_requestedExpiryTime", ",", "boolean", "_sharpExpiryEnabled", ")", "{", "if", "(", "_sharpExpiryEnabled", "&&", "_requestedExpiryTime", ">", "ExpiryPolicy", ".", ...
Ignore the value of the expiry policy if later then the maximum expiry time. If max linger takes over, we do not request sharp expiry. <p>The situation becomes messy if the point in time for the maximum expiry is close to the requested expiry time and sharp expiry is requested. The expiry or a reload (with refresh ahead) may come to late and overlap the expiry time. As incomplete fix we use the safety gap, but if loaders are taking longer then the safety gap a value becomes visible that should be expired. The solutions would be to pass on two times from here: a refresh time and the point in time for sharp expiry, and expiry correctly while a concurrent load is proceeding.
[ "Ignore", "the", "value", "of", "the", "expiry", "policy", "if", "later", "then", "the", "maximum", "expiry", "time", ".", "If", "max", "linger", "takes", "over", "we", "do", "not", "request", "sharp", "expiry", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/TimingHandler.java#L619-L624
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java
CacheConfigurationProviderImpl.getDefaultManagerName
@Override public String getDefaultManagerName(ClassLoader cl) { ConfigurationContext ctx = classLoader2config.get(cl); if (ctx == null) { ctx = createContext(cl, null, DEFAULT_CONFIGURATION_FILE); Map<ClassLoader, ConfigurationContext> m2 = new HashMap<ClassLoader, ConfigurationContext>(classLoader2config); m2.put(cl, ctx); classLoader2config = m2; } return ctx.getManagerConfiguration().getDefaultManagerName(); }
java
@Override public String getDefaultManagerName(ClassLoader cl) { ConfigurationContext ctx = classLoader2config.get(cl); if (ctx == null) { ctx = createContext(cl, null, DEFAULT_CONFIGURATION_FILE); Map<ClassLoader, ConfigurationContext> m2 = new HashMap<ClassLoader, ConfigurationContext>(classLoader2config); m2.put(cl, ctx); classLoader2config = m2; } return ctx.getManagerConfiguration().getDefaultManagerName(); }
[ "@", "Override", "public", "String", "getDefaultManagerName", "(", "ClassLoader", "cl", ")", "{", "ConfigurationContext", "ctx", "=", "classLoader2config", ".", "get", "(", "cl", ")", ";", "if", "(", "ctx", "==", "null", ")", "{", "ctx", "=", "createContext"...
The name of the default manager may be changed in the configuration file. Load the default configuration file and save the loaded context for the respective classloader, so we do not load the context twice when we create the first cache.
[ "The", "name", "of", "the", "default", "manager", "may", "be", "changed", "in", "the", "configuration", "file", ".", "Load", "the", "default", "configuration", "file", "and", "save", "the", "loaded", "context", "for", "the", "respective", "classloader", "so", ...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java#L76-L86
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java
CacheConfigurationProviderImpl.getManagerContext
private ConfigurationContext getManagerContext(final CacheManager mgr) { ConfigurationContext ctx = manager2defaultConfig.get(mgr); if (ctx != null) { return ctx; } synchronized (this) { ctx = manager2defaultConfig.get(mgr); if (ctx != null) { return ctx; } if (mgr.isDefaultManager()) { ctx = classLoader2config.get(mgr.getClassLoader()); } if (ctx == null) { ctx = createContext(mgr.getClassLoader(), mgr.getName(), getFileName(mgr)); } Map<CacheManager, ConfigurationContext> m2 = new HashMap<CacheManager, ConfigurationContext>(manager2defaultConfig); m2.put(mgr, ctx); manager2defaultConfig = m2; return ctx; } }
java
private ConfigurationContext getManagerContext(final CacheManager mgr) { ConfigurationContext ctx = manager2defaultConfig.get(mgr); if (ctx != null) { return ctx; } synchronized (this) { ctx = manager2defaultConfig.get(mgr); if (ctx != null) { return ctx; } if (mgr.isDefaultManager()) { ctx = classLoader2config.get(mgr.getClassLoader()); } if (ctx == null) { ctx = createContext(mgr.getClassLoader(), mgr.getName(), getFileName(mgr)); } Map<CacheManager, ConfigurationContext> m2 = new HashMap<CacheManager, ConfigurationContext>(manager2defaultConfig); m2.put(mgr, ctx); manager2defaultConfig = m2; return ctx; } }
[ "private", "ConfigurationContext", "getManagerContext", "(", "final", "CacheManager", "mgr", ")", "{", "ConfigurationContext", "ctx", "=", "manager2defaultConfig", ".", "get", "(", "mgr", ")", ";", "if", "(", "ctx", "!=", "null", ")", "{", "return", "ctx", ";"...
Hold the cache default configuration of a manager in a hash table. This is reused for all caches of one manager.
[ "Hold", "the", "cache", "default", "configuration", "of", "a", "manager", "in", "a", "hash", "table", ".", "This", "is", "reused", "for", "all", "caches", "of", "one", "manager", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java#L186-L208
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java
CacheConfigurationProviderImpl.apply
void apply(final ConfigurationContext ctx, final ParsedConfiguration _parsedCfg, final Object cfg) { ParsedConfiguration _templates = ctx.getTemplates(); ConfigurationTokenizer.Property _include = _parsedCfg.getPropertyMap().get("include"); if (_include != null) { for (String _template : _include.getValue().split(",")) { ParsedConfiguration c2 = null; if (_templates != null) { c2 = _templates.getSection(_template); } if (c2 == null) { throw new ConfigurationException("Template not found \'" + _template + "\'", _include); } apply(ctx, c2, cfg); } } applyPropertyValues(_parsedCfg, cfg); if (!(cfg instanceof ConfigurationWithSections)) { return; } ConfigurationWithSections _configurationWithSections = (ConfigurationWithSections) cfg; for(ParsedConfiguration _parsedSection : _parsedCfg.getSections()) { String _sectionType = ctx.getPredefinedSectionTypes().get(_parsedSection.getName()); if (_sectionType == null) { _sectionType = _parsedSection.getType(); } if (_sectionType == null) { throw new ConfigurationException("type missing or unknown", _parsedSection); } Class<?> _type; try { _type = Class.forName(_sectionType); } catch (ClassNotFoundException ex) { throw new ConfigurationException( "class not found '" + _sectionType + "'", _parsedSection); } if (!handleSection(ctx, _type, _configurationWithSections, _parsedSection) && !handleCollection(ctx, _type, cfg, _parsedSection) && !handleBean(ctx, _type, cfg, _parsedSection)) { throw new ConfigurationException("Unknown property '" + _parsedSection.getContainer() + "'", _parsedSection); } } }
java
void apply(final ConfigurationContext ctx, final ParsedConfiguration _parsedCfg, final Object cfg) { ParsedConfiguration _templates = ctx.getTemplates(); ConfigurationTokenizer.Property _include = _parsedCfg.getPropertyMap().get("include"); if (_include != null) { for (String _template : _include.getValue().split(",")) { ParsedConfiguration c2 = null; if (_templates != null) { c2 = _templates.getSection(_template); } if (c2 == null) { throw new ConfigurationException("Template not found \'" + _template + "\'", _include); } apply(ctx, c2, cfg); } } applyPropertyValues(_parsedCfg, cfg); if (!(cfg instanceof ConfigurationWithSections)) { return; } ConfigurationWithSections _configurationWithSections = (ConfigurationWithSections) cfg; for(ParsedConfiguration _parsedSection : _parsedCfg.getSections()) { String _sectionType = ctx.getPredefinedSectionTypes().get(_parsedSection.getName()); if (_sectionType == null) { _sectionType = _parsedSection.getType(); } if (_sectionType == null) { throw new ConfigurationException("type missing or unknown", _parsedSection); } Class<?> _type; try { _type = Class.forName(_sectionType); } catch (ClassNotFoundException ex) { throw new ConfigurationException( "class not found '" + _sectionType + "'", _parsedSection); } if (!handleSection(ctx, _type, _configurationWithSections, _parsedSection) && !handleCollection(ctx, _type, cfg, _parsedSection) && !handleBean(ctx, _type, cfg, _parsedSection)) { throw new ConfigurationException("Unknown property '" + _parsedSection.getContainer() + "'", _parsedSection); } } }
[ "void", "apply", "(", "final", "ConfigurationContext", "ctx", ",", "final", "ParsedConfiguration", "_parsedCfg", ",", "final", "Object", "cfg", ")", "{", "ParsedConfiguration", "_templates", "=", "ctx", ".", "getTemplates", "(", ")", ";", "ConfigurationTokenizer", ...
Set properties in configuration bean based on the parsed configuration. Called by unit test.
[ "Set", "properties", "in", "configuration", "bean", "based", "on", "the", "parsed", "configuration", ".", "Called", "by", "unit", "test", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java#L272-L311
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java
CacheConfigurationProviderImpl.handleBean
private boolean handleBean( final ConfigurationContext ctx, final Class<?> _type, final Object cfg, final ParsedConfiguration _parsedCfg) { String _containerName = _parsedCfg.getContainer(); BeanPropertyMutator m = provideMutator(cfg.getClass()); Class<?> _targetType = m.getType(_containerName); if (_targetType == null) { return false; } if (!_targetType.isAssignableFrom(_type)) { throw new ConfigurationException("Type mismatch, expected: '" + _targetType.getName() + "'", _parsedCfg); } Object _bean = createBeanAndApplyConfiguration(ctx, _type, _parsedCfg); mutateAndCatch(cfg, m, _containerName, _bean, _parsedCfg, _bean); return true; }
java
private boolean handleBean( final ConfigurationContext ctx, final Class<?> _type, final Object cfg, final ParsedConfiguration _parsedCfg) { String _containerName = _parsedCfg.getContainer(); BeanPropertyMutator m = provideMutator(cfg.getClass()); Class<?> _targetType = m.getType(_containerName); if (_targetType == null) { return false; } if (!_targetType.isAssignableFrom(_type)) { throw new ConfigurationException("Type mismatch, expected: '" + _targetType.getName() + "'", _parsedCfg); } Object _bean = createBeanAndApplyConfiguration(ctx, _type, _parsedCfg); mutateAndCatch(cfg, m, _containerName, _bean, _parsedCfg, _bean); return true; }
[ "private", "boolean", "handleBean", "(", "final", "ConfigurationContext", "ctx", ",", "final", "Class", "<", "?", ">", "_type", ",", "final", "Object", "cfg", ",", "final", "ParsedConfiguration", "_parsedCfg", ")", "{", "String", "_containerName", "=", "_parsedC...
Create the bean, apply configuration to it and set it. @return true, if applied, false if not a property
[ "Create", "the", "bean", "apply", "configuration", "to", "it", "and", "set", "it", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java#L318-L335
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java
CacheConfigurationProviderImpl.handleSection
private boolean handleSection( final ConfigurationContext ctx, final Class<?> _type, final ConfigurationWithSections cfg, final ParsedConfiguration sc) { String _containerName = sc.getContainer(); if (!"sections".equals(_containerName)) { return false; } @SuppressWarnings("unchecked") ConfigurationSection _sectionBean = cfg.getSections().getSection((Class<ConfigurationSection>) _type); if (!(_sectionBean instanceof SingletonConfigurationSection)) { try { _sectionBean = (ConfigurationSection) _type.newInstance(); } catch (Exception ex) { throw new ConfigurationException("Cannot instantiate section class: " + ex, sc); } cfg.getSections().add(_sectionBean); } apply(ctx, sc, _sectionBean); return true; }
java
private boolean handleSection( final ConfigurationContext ctx, final Class<?> _type, final ConfigurationWithSections cfg, final ParsedConfiguration sc) { String _containerName = sc.getContainer(); if (!"sections".equals(_containerName)) { return false; } @SuppressWarnings("unchecked") ConfigurationSection _sectionBean = cfg.getSections().getSection((Class<ConfigurationSection>) _type); if (!(_sectionBean instanceof SingletonConfigurationSection)) { try { _sectionBean = (ConfigurationSection) _type.newInstance(); } catch (Exception ex) { throw new ConfigurationException("Cannot instantiate section class: " + ex, sc); } cfg.getSections().add(_sectionBean); } apply(ctx, sc, _sectionBean); return true; }
[ "private", "boolean", "handleSection", "(", "final", "ConfigurationContext", "ctx", ",", "final", "Class", "<", "?", ">", "_type", ",", "final", "ConfigurationWithSections", "cfg", ",", "final", "ParsedConfiguration", "sc", ")", "{", "String", "_containerName", "=...
Create a new configuration section or reuse an existing section, if it is a singleton. <p>No support for writing on existing sections, which means it is not possible to define a non singleton in the defaults section and then override values later in the cache specific configuration. This is not needed for version 1.0. If we want to add it later, it is best to use the name to select the correct section. @return true if applied, false if not a section.
[ "Create", "a", "new", "configuration", "section", "or", "reuse", "an", "existing", "section", "if", "it", "is", "a", "singleton", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/impl/xmlConfiguration/CacheConfigurationProviderImpl.java#L410-L430
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/EntryAction.java
EntryAction.checkKeepOrRemove
public void checkKeepOrRemove() { boolean _hasKeepAfterExpired = heapCache.isKeepAfterExpired(); if (expiry != 0 || remove || _hasKeepAfterExpired) { mutationUpdateHeap(); return; } if (_hasKeepAfterExpired) { expiredImmediatelyKeepData(); return; } expiredImmediatelyAndRemove(); }
java
public void checkKeepOrRemove() { boolean _hasKeepAfterExpired = heapCache.isKeepAfterExpired(); if (expiry != 0 || remove || _hasKeepAfterExpired) { mutationUpdateHeap(); return; } if (_hasKeepAfterExpired) { expiredImmediatelyKeepData(); return; } expiredImmediatelyAndRemove(); }
[ "public", "void", "checkKeepOrRemove", "(", ")", "{", "boolean", "_hasKeepAfterExpired", "=", "heapCache", ".", "isKeepAfterExpired", "(", ")", ";", "if", "(", "expiry", "!=", "0", "||", "remove", "||", "_hasKeepAfterExpired", ")", "{", "mutationUpdateHeap", "("...
In case we have a expiry of 0, this means that the entry should not be cached. If there is a valid entry, we remove it if we do not keep the data.
[ "In", "case", "we", "have", "a", "expiry", "of", "0", "this", "means", "that", "the", "entry", "should", "not", "be", "cached", ".", "If", "there", "is", "a", "valid", "entry", "we", "remove", "it", "if", "we", "do", "not", "keep", "the", "data", "...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/EntryAction.java#L773-L784
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/EntryAction.java
EntryAction.asyncOperationStarted
public void asyncOperationStarted() { if (syncThread == Thread.currentThread()) { synchronized (entry) { while (entry.isProcessing()) { try { entry.wait(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } } else { entryLocked = false; } }
java
public void asyncOperationStarted() { if (syncThread == Thread.currentThread()) { synchronized (entry) { while (entry.isProcessing()) { try { entry.wait(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } } else { entryLocked = false; } }
[ "public", "void", "asyncOperationStarted", "(", ")", "{", "if", "(", "syncThread", "==", "Thread", ".", "currentThread", "(", ")", ")", "{", "synchronized", "(", "entry", ")", "{", "while", "(", "entry", ".", "isProcessing", "(", ")", ")", "{", "try", ...
If thread is a synchronous call, wait until operation is complete. There is a little chance that the call back completes before we get here as well as some other operation changing the entry again.
[ "If", "thread", "is", "a", "synchronous", "call", "wait", "until", "operation", "is", "complete", ".", "There", "is", "a", "little", "chance", "that", "the", "call", "back", "completes", "before", "we", "get", "here", "as", "well", "as", "some", "other", ...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/EntryAction.java#L1004-L1018
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/util/Log.java
Log.initializeLogFactory
private static void initializeLogFactory() { ServiceLoader<LogFactory> loader = ServiceLoader.load(LogFactory.class); for (LogFactory lf : loader) { logFactory = lf; log("New instance, using: " + logFactory.getClass().getName()); return; } try { final org.slf4j.ILoggerFactory lf = org.slf4j.LoggerFactory.getILoggerFactory(); logFactory = new LogFactory() { @Override public Log getLog(String s) { return new Slf4jLogger(lf.getLogger(s)); } }; log("New instance, using SLF4J logging"); return; } catch (NoClassDefFoundError ignore) { } try { final org.apache.commons.logging.LogFactory cl = org.apache.commons.logging.LogFactory.getFactory(); logFactory = new LogFactory() { @Override public Log getLog(String s) { return new CommonsLogger(cl.getInstance(s)); } }; log("New instance, using commons logging"); return; } catch (NoClassDefFoundError ignore) { } logFactory = new LogFactory() { @Override public Log getLog(String s) { return new JdkLogger(Logger.getLogger(s)); } }; log("New instance, using JDK logging"); }
java
private static void initializeLogFactory() { ServiceLoader<LogFactory> loader = ServiceLoader.load(LogFactory.class); for (LogFactory lf : loader) { logFactory = lf; log("New instance, using: " + logFactory.getClass().getName()); return; } try { final org.slf4j.ILoggerFactory lf = org.slf4j.LoggerFactory.getILoggerFactory(); logFactory = new LogFactory() { @Override public Log getLog(String s) { return new Slf4jLogger(lf.getLogger(s)); } }; log("New instance, using SLF4J logging"); return; } catch (NoClassDefFoundError ignore) { } try { final org.apache.commons.logging.LogFactory cl = org.apache.commons.logging.LogFactory.getFactory(); logFactory = new LogFactory() { @Override public Log getLog(String s) { return new CommonsLogger(cl.getInstance(s)); } }; log("New instance, using commons logging"); return; } catch (NoClassDefFoundError ignore) { } logFactory = new LogFactory() { @Override public Log getLog(String s) { return new JdkLogger(Logger.getLogger(s)); } }; log("New instance, using JDK logging"); }
[ "private", "static", "void", "initializeLogFactory", "(", ")", "{", "ServiceLoader", "<", "LogFactory", ">", "loader", "=", "ServiceLoader", ".", "load", "(", "LogFactory", ".", "class", ")", ";", "for", "(", "LogFactory", "lf", ":", "loader", ")", "{", "l...
Finds a logger we can use. First we start with looking for a registered service provider. Then apache commons logging. As a fallback we use JDK logging.
[ "Finds", "a", "logger", "we", "can", "use", ".", "First", "we", "start", "with", "looking", "for", "a", "registered", "service", "provider", ".", "Then", "apache", "commons", "logging", ".", "As", "a", "fallback", "we", "use", "JDK", "logging", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/util/Log.java#L73-L112
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/spi/SingleProviderResolver.java
SingleProviderResolver.readFile
private static String readFile(String _name) throws IOException { InputStream in = SingleProviderResolver.class.getClassLoader().getResourceAsStream(_name); if (in == null) { return null; } try { LineNumberReader r = new LineNumberReader(new InputStreamReader(in)); String l = r.readLine(); while (l != null) { if (!l.startsWith("#")) { return l; } l = r.readLine(); } } finally { in.close(); } return null; }
java
private static String readFile(String _name) throws IOException { InputStream in = SingleProviderResolver.class.getClassLoader().getResourceAsStream(_name); if (in == null) { return null; } try { LineNumberReader r = new LineNumberReader(new InputStreamReader(in)); String l = r.readLine(); while (l != null) { if (!l.startsWith("#")) { return l; } l = r.readLine(); } } finally { in.close(); } return null; }
[ "private", "static", "String", "readFile", "(", "String", "_name", ")", "throws", "IOException", "{", "InputStream", "in", "=", "SingleProviderResolver", ".", "class", ".", "getClassLoader", "(", ")", ".", "getResourceAsStream", "(", "_name", ")", ";", "if", "...
Read the first line of a file in the classpath into a string.
[ "Read", "the", "first", "line", "of", "a", "file", "in", "the", "classpath", "into", "a", "string", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/spi/SingleProviderResolver.java#L127-L145
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java
CacheManagerImpl.constructAllServiceImplementations
@SuppressWarnings("unchecked") private static <S> Iterable<S> constructAllServiceImplementations(Class<S> _service) { ClassLoader cl = CacheManagerImpl.class.getClassLoader(); ArrayList<S> li = new ArrayList<S>(); Iterator<S> it = ServiceLoader.load(_service, cl).iterator(); while (it.hasNext()) { try { li.add(it.next()); } catch (ServiceConfigurationError ex) { Log.getLog(CacheManager.class.getName()).debug("Error loading service '" + _service + "'", ex); } } final S[] a = (S[]) Array.newInstance(_service, li.size()); li.toArray(a); return new Iterable<S>() { public Iterator<S> iterator() { return new Iterator<S>() { private int pos = 0; public boolean hasNext() { return pos < a.length; } public S next() { return a[pos++]; } public void remove() { throw new UnsupportedOperationException(); } }; } }; }
java
@SuppressWarnings("unchecked") private static <S> Iterable<S> constructAllServiceImplementations(Class<S> _service) { ClassLoader cl = CacheManagerImpl.class.getClassLoader(); ArrayList<S> li = new ArrayList<S>(); Iterator<S> it = ServiceLoader.load(_service, cl).iterator(); while (it.hasNext()) { try { li.add(it.next()); } catch (ServiceConfigurationError ex) { Log.getLog(CacheManager.class.getName()).debug("Error loading service '" + _service + "'", ex); } } final S[] a = (S[]) Array.newInstance(_service, li.size()); li.toArray(a); return new Iterable<S>() { public Iterator<S> iterator() { return new Iterator<S>() { private int pos = 0; public boolean hasNext() { return pos < a.length; } public S next() { return a[pos++]; } public void remove() { throw new UnsupportedOperationException(); } }; } }; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "static", "<", "S", ">", "Iterable", "<", "S", ">", "constructAllServiceImplementations", "(", "Class", "<", "S", ">", "_service", ")", "{", "ClassLoader", "cl", "=", "CacheManagerImpl", ".", "clas...
The service loader works lazy, however, we want to have all implementations constructed. Retrieve all implementations from the service loader and return an read-only iterable backed by an array.
[ "The", "service", "loader", "works", "lazy", "however", "we", "want", "to", "have", "all", "implementations", "constructed", ".", "Retrieve", "all", "implementations", "from", "the", "service", "loader", "and", "return", "an", "read", "-", "only", "iterable", ...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java#L65-L95
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java
CacheManagerImpl.checkName
public static void checkName(String s) { for (char c : s.toCharArray()) { if (c == '.' || c == '-' || c == '~' || c == ',' || c == '@' || c == ' ' || c == '(' || c == ')' || c == '+' || c == '!' || c == '\'' || c == '%' || c == '#') { continue; } if (c < 32 || c >= 127 || !Character.isJavaIdentifierPart(c)) { throw new IllegalArgumentException( "Cache name contains illegal character: '" + c + "', name=\"" + s + "\""); } } }
java
public static void checkName(String s) { for (char c : s.toCharArray()) { if (c == '.' || c == '-' || c == '~' || c == ',' || c == '@' || c == ' ' || c == '(' || c == ')' || c == '+' || c == '!' || c == '\'' || c == '%' || c == '#') { continue; } if (c < 32 || c >= 127 || !Character.isJavaIdentifierPart(c)) { throw new IllegalArgumentException( "Cache name contains illegal character: '" + c + "', name=\"" + s + "\""); } } }
[ "public", "static", "void", "checkName", "(", "String", "s", ")", "{", "for", "(", "char", "c", ":", "s", ".", "toCharArray", "(", ")", ")", "{", "if", "(", "c", "==", "'", "'", "||", "c", "==", "'", "'", "||", "c", "==", "'", "'", "||", "c...
Don't accept a cache or manager names with too weird characters. @see org.cache2k.Cache2kBuilder#name(String)
[ "Don", "t", "accept", "a", "cache", "or", "manager", "names", "with", "too", "weird", "characters", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java#L140-L162
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java
CacheManagerImpl.close
@Override public void close() { if (isDefaultManager() && getClass().getClassLoader() == classLoader) { log.info("Closing default CacheManager"); } Iterable<Cache> _caches; synchronized (lock) { if (closing) { return; } _caches = cachesCopy(); closing = true; } logPhase("close"); List<Throwable> _suppressedExceptions = new ArrayList<Throwable>(); for (Cache c : _caches) { ((InternalCache) c).cancelTimerJobs(); } for (Cache c : _caches) { try { c.close(); } catch (Throwable t) { _suppressedExceptions.add(t); } } try { for (CacheManagerLifeCycleListener lc : cacheManagerLifeCycleListeners) { lc.managerDestroyed(this); } } catch (Throwable t) { _suppressedExceptions.add(t); } ((Cache2kCoreProviderImpl) PROVIDER).removeManager(this); synchronized (lock) { for (Cache c : cacheNames.values()) { log.warn("unable to close cache: " + c.getName()); } } eventuallyThrowException(_suppressedExceptions); cacheNames = null; }
java
@Override public void close() { if (isDefaultManager() && getClass().getClassLoader() == classLoader) { log.info("Closing default CacheManager"); } Iterable<Cache> _caches; synchronized (lock) { if (closing) { return; } _caches = cachesCopy(); closing = true; } logPhase("close"); List<Throwable> _suppressedExceptions = new ArrayList<Throwable>(); for (Cache c : _caches) { ((InternalCache) c).cancelTimerJobs(); } for (Cache c : _caches) { try { c.close(); } catch (Throwable t) { _suppressedExceptions.add(t); } } try { for (CacheManagerLifeCycleListener lc : cacheManagerLifeCycleListeners) { lc.managerDestroyed(this); } } catch (Throwable t) { _suppressedExceptions.add(t); } ((Cache2kCoreProviderImpl) PROVIDER).removeManager(this); synchronized (lock) { for (Cache c : cacheNames.values()) { log.warn("unable to close cache: " + c.getName()); } } eventuallyThrowException(_suppressedExceptions); cacheNames = null; }
[ "@", "Override", "public", "void", "close", "(", ")", "{", "if", "(", "isDefaultManager", "(", ")", "&&", "getClass", "(", ")", ".", "getClassLoader", "(", ")", "==", "classLoader", ")", "{", "log", ".", "info", "(", "\"Closing default CacheManager\"", ")"...
The shutdown takes place in two phases. First all caches are notified to cancel their scheduled timer jobs, after that the shutdown is done. Cancelling the timer jobs first is needed, because there may be cache stacking and a timer job of one cache may call an already closed cache. <p>Rationale exception handling: Exceptions on shutdown just could silently ignored, because a shutdown is done any way. Exceptions could be happened long before in a parallel task, shutdown is the last point where this could be propagated to the application. Silently ignoring is bad anyway, because this will cause that serious problems keep undetected. The exception and error handling within the cache tries everything that exceptions will be routed through as early and directly as possible.
[ "The", "shutdown", "takes", "place", "in", "two", "phases", ".", "First", "all", "caches", "are", "notified", "to", "cancel", "their", "scheduled", "timer", "jobs", "after", "that", "the", "shutdown", "is", "done", ".", "Cancelling", "the", "timer", "jobs", ...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java#L275-L315
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java
CacheManagerImpl.eventuallyThrowException
static void eventuallyThrowException(List<Throwable> _suppressedExceptions) { if (_suppressedExceptions.isEmpty()) { return; } Throwable _error = null; for (Throwable t : _suppressedExceptions) { if (t instanceof Error) { _error = t; break; } if (t instanceof ExecutionException && t.getCause() instanceof Error) { _error = t.getCause(); break; } } String _text = "Exception(s) during shutdown"; if (_suppressedExceptions.size() > 1) { _text = " (" + (_suppressedExceptions.size() - 1)+ " more suppressed exceptions)"; } if (_error != null) { throw new CacheInternalError(_text, _error); } throw new CacheException(_text, _suppressedExceptions.get(0)); }
java
static void eventuallyThrowException(List<Throwable> _suppressedExceptions) { if (_suppressedExceptions.isEmpty()) { return; } Throwable _error = null; for (Throwable t : _suppressedExceptions) { if (t instanceof Error) { _error = t; break; } if (t instanceof ExecutionException && t.getCause() instanceof Error) { _error = t.getCause(); break; } } String _text = "Exception(s) during shutdown"; if (_suppressedExceptions.size() > 1) { _text = " (" + (_suppressedExceptions.size() - 1)+ " more suppressed exceptions)"; } if (_error != null) { throw new CacheInternalError(_text, _error); } throw new CacheException(_text, _suppressedExceptions.get(0)); }
[ "static", "void", "eventuallyThrowException", "(", "List", "<", "Throwable", ">", "_suppressedExceptions", ")", "{", "if", "(", "_suppressedExceptions", ".", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "Throwable", "_error", "=", "null", ";", "for", "...
During the shutdown of the cache manager multiple exceptions can happen from various caches. The list of exceptions gets examined to throw one exception. <p>If an error is present, the first found gets thrown as CacheInternalError. If no error is present the first normal exception gets thrown as CacheException. <p>The suppressed exceptions will be added to the single exception that gets thrown. @throws org.cache2k.core.CacheInternalError if list contains an error @throws org.cache2k.CacheException if list does not contain an error
[ "During", "the", "shutdown", "of", "the", "cache", "manager", "multiple", "exceptions", "can", "happen", "from", "various", "caches", ".", "The", "list", "of", "exceptions", "gets", "examined", "to", "throw", "one", "exception", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java#L330-L351
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java
CacheManagerImpl.getManagerId
private String getManagerId() { return "name='" + name + "', objectId=" + Integer.toString(System.identityHashCode(this), 36) + ", classloaderId=" + Integer.toString(System.identityHashCode(classLoader), 36) + ", default=" + defaultManager; }
java
private String getManagerId() { return "name='" + name + "', objectId=" + Integer.toString(System.identityHashCode(this), 36) + ", classloaderId=" + Integer.toString(System.identityHashCode(classLoader), 36) + ", default=" + defaultManager; }
[ "private", "String", "getManagerId", "(", ")", "{", "return", "\"name='\"", "+", "name", "+", "\"', objectId=\"", "+", "Integer", ".", "toString", "(", "System", ".", "identityHashCode", "(", "this", ")", ",", "36", ")", "+", "\", classloaderId=\"", "+", "In...
Relevant information to id a manager. Since there could be multiple cache managers for each class loader, better
[ "Relevant", "information", "to", "id", "a", "manager", ".", "Since", "there", "could", "be", "multiple", "cache", "managers", "for", "each", "class", "loader", "better" ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/CacheManagerImpl.java#L399-L404
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Entry.java
Entry.checkAndSwitchProcessingState
public boolean checkAndSwitchProcessingState(int ps0, int ps) { long rt = refreshTimeAndState; long _expect = withState(rt, ps0); long _update = withState(rt, ps); return STATE_UPDATER.compareAndSet(this, _expect, _update); }
java
public boolean checkAndSwitchProcessingState(int ps0, int ps) { long rt = refreshTimeAndState; long _expect = withState(rt, ps0); long _update = withState(rt, ps); return STATE_UPDATER.compareAndSet(this, _expect, _update); }
[ "public", "boolean", "checkAndSwitchProcessingState", "(", "int", "ps0", ",", "int", "ps", ")", "{", "long", "rt", "=", "refreshTimeAndState", ";", "long", "_expect", "=", "withState", "(", "rt", ",", "ps0", ")", ";", "long", "_update", "=", "withState", "...
Check and switch the processing state atomically.
[ "Check", "and", "switch", "the", "processing", "state", "atomically", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Entry.java#L315-L320
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Entry.java
Entry.existingPiggyBackForInserting
private PiggyBack existingPiggyBackForInserting() { Object _misc = misc; if (_misc instanceof SimpleTimerTask) { return new TaskPiggyBack((SimpleTimerTask) _misc, null); } return (PiggyBack) _misc; }
java
private PiggyBack existingPiggyBackForInserting() { Object _misc = misc; if (_misc instanceof SimpleTimerTask) { return new TaskPiggyBack((SimpleTimerTask) _misc, null); } return (PiggyBack) _misc; }
[ "private", "PiggyBack", "existingPiggyBackForInserting", "(", ")", "{", "Object", "_misc", "=", "misc", ";", "if", "(", "_misc", "instanceof", "SimpleTimerTask", ")", "{", "return", "new", "TaskPiggyBack", "(", "(", "SimpleTimerTask", ")", "_misc", ",", "null", ...
We want to add a new piggy back. Check for timer task and convert it to piggy back.
[ "We", "want", "to", "add", "a", "new", "piggy", "back", ".", "Check", "for", "timer", "task", "and", "convert", "it", "to", "piggy", "back", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Entry.java#L644-L650
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Entry.java
Entry.resetSuppressedLoadExceptionInformation
public void resetSuppressedLoadExceptionInformation() { LoadExceptionPiggyBack inf = getPiggyBack(LoadExceptionPiggyBack.class); if (inf != null) { inf.info = null; } }
java
public void resetSuppressedLoadExceptionInformation() { LoadExceptionPiggyBack inf = getPiggyBack(LoadExceptionPiggyBack.class); if (inf != null) { inf.info = null; } }
[ "public", "void", "resetSuppressedLoadExceptionInformation", "(", ")", "{", "LoadExceptionPiggyBack", "inf", "=", "getPiggyBack", "(", "LoadExceptionPiggyBack", ".", "class", ")", ";", "if", "(", "inf", "!=", "null", ")", "{", "inf", ".", "info", "=", "null", ...
If the entry carries information about a suppressed exception, clear it.
[ "If", "the", "entry", "carries", "information", "about", "a", "suppressed", "exception", "clear", "it", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Entry.java#L664-L669
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.lookup
public Entry<K,V> lookup(K key, int _hash, int _keyValue) { OptimisticLock[] _locks = locks; int si = _hash & LOCK_MASK; OptimisticLock l = _locks[si]; long _stamp = l.tryOptimisticRead(); Entry<K,V>[] tab = entries; if (tab == null) { throw new CacheClosedException(cache); } Entry<K,V> e; int n = tab.length; int _mask = n - 1; int idx = _hash & (_mask); e = tab[idx]; while (e != null) { if (e.hashCode == _keyValue && keyObjIsEqual(key, e)) { return e; } e = e.another; } if (l.validate(_stamp)) { return null; } _stamp = l.readLock(); try { tab = entries; if (tab == null) { throw new CacheClosedException(cache); } n = tab.length; _mask = n - 1; idx = _hash & (_mask); e = tab[idx]; while (e != null) { if (e.hashCode == _keyValue && (keyObjIsEqual(key, e))) { return e; } e = e.another; } return null; } finally { l.unlockRead(_stamp); } }
java
public Entry<K,V> lookup(K key, int _hash, int _keyValue) { OptimisticLock[] _locks = locks; int si = _hash & LOCK_MASK; OptimisticLock l = _locks[si]; long _stamp = l.tryOptimisticRead(); Entry<K,V>[] tab = entries; if (tab == null) { throw new CacheClosedException(cache); } Entry<K,V> e; int n = tab.length; int _mask = n - 1; int idx = _hash & (_mask); e = tab[idx]; while (e != null) { if (e.hashCode == _keyValue && keyObjIsEqual(key, e)) { return e; } e = e.another; } if (l.validate(_stamp)) { return null; } _stamp = l.readLock(); try { tab = entries; if (tab == null) { throw new CacheClosedException(cache); } n = tab.length; _mask = n - 1; idx = _hash & (_mask); e = tab[idx]; while (e != null) { if (e.hashCode == _keyValue && (keyObjIsEqual(key, e))) { return e; } e = e.another; } return null; } finally { l.unlockRead(_stamp); } }
[ "public", "Entry", "<", "K", ",", "V", ">", "lookup", "(", "K", "key", ",", "int", "_hash", ",", "int", "_keyValue", ")", "{", "OptimisticLock", "[", "]", "_locks", "=", "locks", ";", "int", "si", "=", "_hash", "&", "LOCK_MASK", ";", "OptimisticLock"...
Lookup the entry in the hash table and return it. First tries an optimistic read.
[ "Lookup", "the", "entry", "in", "the", "hash", "table", "and", "return", "it", ".", "First", "tries", "an", "optimistic", "read", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L109-L152
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.insertWithinLock
public Entry<K,V> insertWithinLock(Entry<K,V> e, int _hash, int _keyValue) { K key = e.getKeyObj(); int si = _hash & LOCK_MASK; Entry<K,V> f; Object ek; Entry<K,V>[] tab = entries; if (tab == null) { throw new CacheClosedException(cache); } int n = tab.length, _mask = n - 1, idx = _hash & (_mask); f = tab[idx]; while (f != null) { if (f.hashCode == _keyValue && ((ek = f.getKeyObj()) == key || (ek.equals(key)))) { return f; } f = f.another; } e.another = tab[idx]; tab[idx] = e; segmentSize[si].incrementAndGet(); return e; }
java
public Entry<K,V> insertWithinLock(Entry<K,V> e, int _hash, int _keyValue) { K key = e.getKeyObj(); int si = _hash & LOCK_MASK; Entry<K,V> f; Object ek; Entry<K,V>[] tab = entries; if (tab == null) { throw new CacheClosedException(cache); } int n = tab.length, _mask = n - 1, idx = _hash & (_mask); f = tab[idx]; while (f != null) { if (f.hashCode == _keyValue && ((ek = f.getKeyObj()) == key || (ek.equals(key)))) { return f; } f = f.another; } e.another = tab[idx]; tab[idx] = e; segmentSize[si].incrementAndGet(); return e; }
[ "public", "Entry", "<", "K", ",", "V", ">", "insertWithinLock", "(", "Entry", "<", "K", ",", "V", ">", "e", ",", "int", "_hash", ",", "int", "_keyValue", ")", "{", "K", "key", "=", "e", ".", "getKeyObj", "(", ")", ";", "int", "si", "=", "_hash"...
Insert an entry. Checks if an entry already exists.
[ "Insert", "an", "entry", ".", "Checks", "if", "an", "entry", "already", "exists", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L164-L183
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.remove
public boolean remove(Entry<K,V> e) { int _hash = modifiedHashCode(e.hashCode); OptimisticLock[] _locks = locks; int si = _hash & LOCK_MASK; OptimisticLock l = _locks[si]; long _stamp = l.writeLock(); try { Entry<K,V> f; Entry<K,V>[] tab = entries; if (tab == null) { throw new CacheClosedException(cache); } int n = tab.length, _mask = n - 1, idx = _hash & (_mask); f = tab[idx]; if (f == e) { tab[idx] = f.another; segmentSize[si].decrementAndGet(); return true; } while (f != null) { Entry<K,V> _another = f.another; if (_another == e) { f.another = _another.another; segmentSize[si].decrementAndGet(); return true; } f = _another; } } finally { l.unlockWrite(_stamp); } return false; }
java
public boolean remove(Entry<K,V> e) { int _hash = modifiedHashCode(e.hashCode); OptimisticLock[] _locks = locks; int si = _hash & LOCK_MASK; OptimisticLock l = _locks[si]; long _stamp = l.writeLock(); try { Entry<K,V> f; Entry<K,V>[] tab = entries; if (tab == null) { throw new CacheClosedException(cache); } int n = tab.length, _mask = n - 1, idx = _hash & (_mask); f = tab[idx]; if (f == e) { tab[idx] = f.another; segmentSize[si].decrementAndGet(); return true; } while (f != null) { Entry<K,V> _another = f.another; if (_another == e) { f.another = _another.another; segmentSize[si].decrementAndGet(); return true; } f = _another; } } finally { l.unlockWrite(_stamp); } return false; }
[ "public", "boolean", "remove", "(", "Entry", "<", "K", ",", "V", ">", "e", ")", "{", "int", "_hash", "=", "modifiedHashCode", "(", "e", ".", "hashCode", ")", ";", "OptimisticLock", "[", "]", "_locks", "=", "locks", ";", "int", "si", "=", "_hash", "...
Remove existing entry from the hash. @return true, if entry was found and removed.
[ "Remove", "existing", "entry", "from", "the", "hash", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L210-L241
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.eventuallyExpand
private void eventuallyExpand(int _segmentIndex) { long[] _stamps = lockAll(); try { long _size = segmentSize[_segmentIndex].get(); if (_size <= segmentMaxFill) { return; } rehash(); } finally { unlockAll(_stamps); } }
java
private void eventuallyExpand(int _segmentIndex) { long[] _stamps = lockAll(); try { long _size = segmentSize[_segmentIndex].get(); if (_size <= segmentMaxFill) { return; } rehash(); } finally { unlockAll(_stamps); } }
[ "private", "void", "eventuallyExpand", "(", "int", "_segmentIndex", ")", "{", "long", "[", "]", "_stamps", "=", "lockAll", "(", ")", ";", "try", "{", "long", "_size", "=", "segmentSize", "[", "_segmentIndex", "]", ".", "get", "(", ")", ";", "if", "(", ...
Acquire all segment locks and rehash, if really needed.
[ "Acquire", "all", "segment", "locks", "and", "rehash", "if", "really", "needed", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L272-L283
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.lockAll
private long[] lockAll() { OptimisticLock[] _locks = locks; int sn = _locks.length; long[] _stamps = new long[locks.length]; for (int i = 0; i < sn; i++) { OptimisticLock l = _locks[i]; _stamps[i] = l.writeLock(); } return _stamps; }
java
private long[] lockAll() { OptimisticLock[] _locks = locks; int sn = _locks.length; long[] _stamps = new long[locks.length]; for (int i = 0; i < sn; i++) { OptimisticLock l = _locks[i]; _stamps[i] = l.writeLock(); } return _stamps; }
[ "private", "long", "[", "]", "lockAll", "(", ")", "{", "OptimisticLock", "[", "]", "_locks", "=", "locks", ";", "int", "sn", "=", "_locks", ".", "length", ";", "long", "[", "]", "_stamps", "=", "new", "long", "[", "locks", ".", "length", "]", ";", ...
Acquire all segment locks and return an array with the lock stamps.
[ "Acquire", "all", "segment", "locks", "and", "return", "an", "array", "with", "the", "lock", "stamps", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L288-L297
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.unlockAll
private void unlockAll(long[] _stamps) { OptimisticLock[] _locks = locks; int sn = _locks.length; for (int i = 0; i < sn; i++) { _locks[i].unlockWrite(_stamps[i]); } }
java
private void unlockAll(long[] _stamps) { OptimisticLock[] _locks = locks; int sn = _locks.length; for (int i = 0; i < sn; i++) { _locks[i].unlockWrite(_stamps[i]); } }
[ "private", "void", "unlockAll", "(", "long", "[", "]", "_stamps", ")", "{", "OptimisticLock", "[", "]", "_locks", "=", "locks", ";", "int", "sn", "=", "_locks", ".", "length", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "sn", ";", "i", ...
Release the all segment locks. @param _stamps array with the lock stamps.
[ "Release", "the", "all", "segment", "locks", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L304-L310
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.rehash
@SuppressWarnings("unchecked") void rehash() { Entry<K,V>[] src = entries; if (src == null) { throw new CacheClosedException(cache); } int i, sl = src.length, n = sl * 2, _mask = n - 1, idx; Entry<K,V>[] tab = new Entry[n]; long _count = 0; Entry _next, e; for (i = 0; i < sl; i++) { e = src[i]; while (e != null) { _count++; _next = e.another; idx = modifiedHashCode(e.hashCode) & _mask; e.another = tab[idx]; tab[idx] = e; e = _next; } } entries = tab; calcMaxFill(); }
java
@SuppressWarnings("unchecked") void rehash() { Entry<K,V>[] src = entries; if (src == null) { throw new CacheClosedException(cache); } int i, sl = src.length, n = sl * 2, _mask = n - 1, idx; Entry<K,V>[] tab = new Entry[n]; long _count = 0; Entry _next, e; for (i = 0; i < sl; i++) { e = src[i]; while (e != null) { _count++; _next = e.another; idx = modifiedHashCode(e.hashCode) & _mask; e.another = tab[idx]; tab[idx] = e; e = _next; } } entries = tab; calcMaxFill(); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "void", "rehash", "(", ")", "{", "Entry", "<", "K", ",", "V", ">", "[", "]", "src", "=", "entries", ";", "if", "(", "src", "==", "null", ")", "{", "throw", "new", "CacheClosedException", "(", "cache...
Double the hash table size and rehash the entries. Assumes total lock.
[ "Double", "the", "hash", "table", "size", "and", "rehash", "the", "entries", ".", "Assumes", "total", "lock", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L319-L338
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.runTotalLocked
public <T> T runTotalLocked(Job<T> j) { long[] _stamps = lockAll(); try { return j.call(); } finally { unlockAll(_stamps); } }
java
public <T> T runTotalLocked(Job<T> j) { long[] _stamps = lockAll(); try { return j.call(); } finally { unlockAll(_stamps); } }
[ "public", "<", "T", ">", "T", "runTotalLocked", "(", "Job", "<", "T", ">", "j", ")", "{", "long", "[", "]", "_stamps", "=", "lockAll", "(", ")", ";", "try", "{", "return", "j", ".", "call", "(", ")", ";", "}", "finally", "{", "unlockAll", "(", ...
Lock all segments and run the job.
[ "Lock", "all", "segments", "and", "run", "the", "job", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L351-L358
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Hash2.java
Hash2.calcEntryCount
public long calcEntryCount() { long _count = 0; for (Entry e : entries) { while (e != null) { _count++; e = e.another; } } return _count; }
java
public long calcEntryCount() { long _count = 0; for (Entry e : entries) { while (e != null) { _count++; e = e.another; } } return _count; }
[ "public", "long", "calcEntryCount", "(", ")", "{", "long", "_count", "=", "0", ";", "for", "(", "Entry", "e", ":", "entries", ")", "{", "while", "(", "e", "!=", "null", ")", "{", "_count", "++", ";", "e", "=", "e", ".", "another", ";", "}", "}"...
Count the entries in the hash table, by scanning through the hash table. This is used for integrity checks.
[ "Count", "the", "entries", "in", "the", "hash", "table", "by", "scanning", "through", "the", "hash", "table", ".", "This", "is", "used", "for", "integrity", "checks", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Hash2.java#L409-L418
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheManagerAdapter.java
JCacheManagerAdapter.findJCacheJmxSupportInstance
private static JCacheJmxSupport findJCacheJmxSupportInstance() { for (CacheLifeCycleListener l : CacheManagerImpl.getCacheLifeCycleListeners()) { if (l instanceof JCacheJmxSupport) { return (JCacheJmxSupport) l; } } throw new LinkageError("JCacheJmxSupport not loaded"); }
java
private static JCacheJmxSupport findJCacheJmxSupportInstance() { for (CacheLifeCycleListener l : CacheManagerImpl.getCacheLifeCycleListeners()) { if (l instanceof JCacheJmxSupport) { return (JCacheJmxSupport) l; } } throw new LinkageError("JCacheJmxSupport not loaded"); }
[ "private", "static", "JCacheJmxSupport", "findJCacheJmxSupportInstance", "(", ")", "{", "for", "(", "CacheLifeCycleListener", "l", ":", "CacheManagerImpl", ".", "getCacheLifeCycleListeners", "(", ")", ")", "{", "if", "(", "l", "instanceof", "JCacheJmxSupport", ")", ...
The JMX support is already created via the serviceloader
[ "The", "JMX", "support", "is", "already", "created", "via", "the", "serviceloader" ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheManagerAdapter.java#L52-L59
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheManagerAdapter.java
JCacheManagerAdapter.resolveCacheWrapper
public Cache resolveCacheWrapper(org.cache2k.Cache _c2kCache) { synchronized (getLockObject()) { return c2k2jCache.get(_c2kCache); } }
java
public Cache resolveCacheWrapper(org.cache2k.Cache _c2kCache) { synchronized (getLockObject()) { return c2k2jCache.get(_c2kCache); } }
[ "public", "Cache", "resolveCacheWrapper", "(", "org", ".", "cache2k", ".", "Cache", "_c2kCache", ")", "{", "synchronized", "(", "getLockObject", "(", ")", ")", "{", "return", "c2k2jCache", ".", "get", "(", "_c2kCache", ")", ";", "}", "}" ]
Return the JCache wrapper for a c2k cache.
[ "Return", "the", "JCache", "wrapper", "for", "a", "c2k", "cache", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheManagerAdapter.java#L302-L306
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/ClockProPlusEviction.java
ClockProPlusEviction.removeFromReplacementList
@Override protected void removeFromReplacementList(Entry e) { if (e.isHot()) { hotHits += e.hitCnt; handHot = Entry.removeFromCyclicList(handHot, e); hotSize--; } else { coldHits += e.hitCnt; handCold = Entry.removeFromCyclicList(handCold, e); coldSize--; } }
java
@Override protected void removeFromReplacementList(Entry e) { if (e.isHot()) { hotHits += e.hitCnt; handHot = Entry.removeFromCyclicList(handHot, e); hotSize--; } else { coldHits += e.hitCnt; handCold = Entry.removeFromCyclicList(handCold, e); coldSize--; } }
[ "@", "Override", "protected", "void", "removeFromReplacementList", "(", "Entry", "e", ")", "{", "if", "(", "e", ".", "isHot", "(", ")", ")", "{", "hotHits", "+=", "e", ".", "hitCnt", ";", "handHot", "=", "Entry", ".", "removeFromCyclicList", "(", "handHo...
Remove, expire or eviction of an entry happens. Remove the entry from the replacement list data structure. <p>Why don't generate ghosts here? If the entry is removed because of a programmatic remove or expiry we should not occupy any resources. Removing and expiry may also take place when no eviction is needed at all, which happens when the cache size did not hit the maximum yet. Producing ghosts would add additional overhead, when it is not needed.
[ "Remove", "expire", "or", "eviction", "of", "an", "entry", "happens", ".", "Remove", "the", "entry", "from", "the", "replacement", "list", "data", "structure", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/ClockProPlusEviction.java#L151-L162
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/ClockProPlusEviction.java
ClockProPlusEviction.findEvictionCandidate
@Override protected Entry findEvictionCandidate(Entry _previous) { coldRunCnt++; Entry _hand = handCold; int _scanCnt = 1; if (_hand == null) { _hand = refillFromHot(_hand); } if (_hand.hitCnt > 0) { _hand = refillFromHot(_hand); do { _scanCnt++; coldHits += _hand.hitCnt; _hand.hitCnt = 0; Entry e = _hand; _hand = Entry.removeFromCyclicList(e); coldSize--; e.setHot(true); hotSize++; handHot = Entry.insertIntoTailCyclicList(handHot, e); } while (_hand != null && _hand.hitCnt > 0); } if (_hand == null) { _hand = refillFromHot(_hand); } coldScanCnt += _scanCnt; handCold = _hand.next; return _hand; }
java
@Override protected Entry findEvictionCandidate(Entry _previous) { coldRunCnt++; Entry _hand = handCold; int _scanCnt = 1; if (_hand == null) { _hand = refillFromHot(_hand); } if (_hand.hitCnt > 0) { _hand = refillFromHot(_hand); do { _scanCnt++; coldHits += _hand.hitCnt; _hand.hitCnt = 0; Entry e = _hand; _hand = Entry.removeFromCyclicList(e); coldSize--; e.setHot(true); hotSize++; handHot = Entry.insertIntoTailCyclicList(handHot, e); } while (_hand != null && _hand.hitCnt > 0); } if (_hand == null) { _hand = refillFromHot(_hand); } coldScanCnt += _scanCnt; handCold = _hand.next; return _hand; }
[ "@", "Override", "protected", "Entry", "findEvictionCandidate", "(", "Entry", "_previous", ")", "{", "coldRunCnt", "++", ";", "Entry", "_hand", "=", "handCold", ";", "int", "_scanCnt", "=", "1", ";", "if", "(", "_hand", "==", "null", ")", "{", "_hand", "...
Runs cold hand an in turn hot hand to find eviction candidate.
[ "Runs", "cold", "hand", "an", "in", "turn", "hot", "hand", "to", "find", "eviction", "candidate", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/ClockProPlusEviction.java#L247-L276
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/IntHeapCache.java
IntHeapCache.createHashTable
@Override public Hash2<Integer, V> createHashTable() { return new Hash2<Integer, V>(this) { @Override protected int modifiedHashCode(final int hc) { return IntHeapCache.this.modifiedHash(hc); } @Override protected boolean keyObjIsEqual(final Integer key, final Entry e) { return true; } }; }
java
@Override public Hash2<Integer, V> createHashTable() { return new Hash2<Integer, V>(this) { @Override protected int modifiedHashCode(final int hc) { return IntHeapCache.this.modifiedHash(hc); } @Override protected boolean keyObjIsEqual(final Integer key, final Entry e) { return true; } }; }
[ "@", "Override", "public", "Hash2", "<", "Integer", ",", "V", ">", "createHashTable", "(", ")", "{", "return", "new", "Hash2", "<", "Integer", ",", "V", ">", "(", "this", ")", "{", "@", "Override", "protected", "int", "modifiedHashCode", "(", "final", ...
Modified hash table implementation. Rehash needs to calculate the correct hash code again.
[ "Modified", "hash", "table", "implementation", ".", "Rehash", "needs", "to", "calculate", "the", "correct", "hash", "code", "again", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/IntHeapCache.java#L58-L71
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/integration/Loaders.java
Loaders.wrapRefreshedTime
@SuppressWarnings("unchecked") public static <V> LoadDetail<V> wrapRefreshedTime(V value, long refreshedTimeInMillis) { return new RefreshedTimeWrapper<V>(value, refreshedTimeInMillis); }
java
@SuppressWarnings("unchecked") public static <V> LoadDetail<V> wrapRefreshedTime(V value, long refreshedTimeInMillis) { return new RefreshedTimeWrapper<V>(value, refreshedTimeInMillis); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "V", ">", "LoadDetail", "<", "V", ">", "wrapRefreshedTime", "(", "V", "value", ",", "long", "refreshedTimeInMillis", ")", "{", "return", "new", "RefreshedTimeWrapper", "<", "V", ">", ...
Wraps a loaded value to add the refreshed value. @see CacheLoader#load(Object) @see AdvancedCacheLoader#load(Object, long, CacheEntry) @see FunctionalCacheLoader#load(Object)
[ "Wraps", "a", "loaded", "value", "to", "add", "the", "refreshed", "value", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/integration/Loaders.java#L39-L42
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Cache2kCoreProviderImpl.java
Cache2kCoreProviderImpl.registerExtensions
private void registerExtensions() { Iterator<Cache2kExtensionProvider> it = ServiceLoader.load(Cache2kExtensionProvider.class, CacheManager.class.getClassLoader()).iterator(); while (it.hasNext()) { try { it.next().registerCache2kExtension(); } catch (ServiceConfigurationError ex) { Log.getLog(CacheManager.class.getName()).debug("Error loading cache2k extension", ex); } } }
java
private void registerExtensions() { Iterator<Cache2kExtensionProvider> it = ServiceLoader.load(Cache2kExtensionProvider.class, CacheManager.class.getClassLoader()).iterator(); while (it.hasNext()) { try { it.next().registerCache2kExtension(); } catch (ServiceConfigurationError ex) { Log.getLog(CacheManager.class.getName()).debug("Error loading cache2k extension", ex); } } }
[ "private", "void", "registerExtensions", "(", ")", "{", "Iterator", "<", "Cache2kExtensionProvider", ">", "it", "=", "ServiceLoader", ".", "load", "(", "Cache2kExtensionProvider", ".", "class", ",", "CacheManager", ".", "class", ".", "getClassLoader", "(", ")", ...
ignore load errors, so we can remove the serverSide or the xmlConfiguration code and cache2k core still works
[ "ignore", "load", "errors", "so", "we", "can", "remove", "the", "serverSide", "or", "the", "xmlConfiguration", "code", "and", "cache2k", "core", "still", "works" ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Cache2kCoreProviderImpl.java#L74-L84
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/Cache2kCoreProviderImpl.java
Cache2kCoreProviderImpl.removeManager
void removeManager(CacheManager cm) { synchronized (getLockObject()) { Map<String, CacheManager> _name2managers = loader2name2manager.get(cm.getClassLoader()); _name2managers = new HashMap<String, CacheManager>(_name2managers); Object _removed = _name2managers.remove(cm.getName()); Map<ClassLoader, Map<String, CacheManager>> _copy = new WeakHashMap<ClassLoader, Map<String, CacheManager>>(loader2name2manager); _copy.put(cm.getClassLoader(), _name2managers); loader2name2manager = _copy; if (cm.isDefaultManager()) { Map<ClassLoader, String> _defaultNameCopy = new WeakHashMap<ClassLoader, String>(loader2defaultName); _defaultNameCopy.remove(cm.getClassLoader()); loader2defaultName = _defaultNameCopy; } } }
java
void removeManager(CacheManager cm) { synchronized (getLockObject()) { Map<String, CacheManager> _name2managers = loader2name2manager.get(cm.getClassLoader()); _name2managers = new HashMap<String, CacheManager>(_name2managers); Object _removed = _name2managers.remove(cm.getName()); Map<ClassLoader, Map<String, CacheManager>> _copy = new WeakHashMap<ClassLoader, Map<String, CacheManager>>(loader2name2manager); _copy.put(cm.getClassLoader(), _name2managers); loader2name2manager = _copy; if (cm.isDefaultManager()) { Map<ClassLoader, String> _defaultNameCopy = new WeakHashMap<ClassLoader, String>(loader2defaultName); _defaultNameCopy.remove(cm.getClassLoader()); loader2defaultName = _defaultNameCopy; } } }
[ "void", "removeManager", "(", "CacheManager", "cm", ")", "{", "synchronized", "(", "getLockObject", "(", ")", ")", "{", "Map", "<", "String", ",", "CacheManager", ">", "_name2managers", "=", "loader2name2manager", ".", "get", "(", "cm", ".", "getClassLoader", ...
Called from the manager after a close. Removes the manager from the known managers.
[ "Called", "from", "the", "manager", "after", "a", "close", ".", "Removes", "the", "manager", "from", "the", "known", "managers", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/Cache2kCoreProviderImpl.java#L170-L184
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/WiredCache.java
WiredCache.loadAllWithAsyncLoader
private void loadAllWithAsyncLoader(final CacheOperationCompletionListener _listener, final Set<K> _keysToLoad) { final AtomicInteger _countDown = new AtomicInteger(_keysToLoad.size()); EntryAction.ActionCompletedCallback cb = new EntryAction.ActionCompletedCallback() { @Override public void entryActionCompleted(final EntryAction ea) { int v = _countDown.decrementAndGet(); if (v == 0) { _listener.onCompleted(); return; } } }; for (K k : _keysToLoad) { final K key = k; executeAsync(key, null, SPEC.GET, cb); } }
java
private void loadAllWithAsyncLoader(final CacheOperationCompletionListener _listener, final Set<K> _keysToLoad) { final AtomicInteger _countDown = new AtomicInteger(_keysToLoad.size()); EntryAction.ActionCompletedCallback cb = new EntryAction.ActionCompletedCallback() { @Override public void entryActionCompleted(final EntryAction ea) { int v = _countDown.decrementAndGet(); if (v == 0) { _listener.onCompleted(); return; } } }; for (K k : _keysToLoad) { final K key = k; executeAsync(key, null, SPEC.GET, cb); } }
[ "private", "void", "loadAllWithAsyncLoader", "(", "final", "CacheOperationCompletionListener", "_listener", ",", "final", "Set", "<", "K", ">", "_keysToLoad", ")", "{", "final", "AtomicInteger", "_countDown", "=", "new", "AtomicInteger", "(", "_keysToLoad", ".", "si...
Load the keys into the cache via the async path. The key set must always be non empty. The completion listener is called when all keys are loaded.
[ "Load", "the", "keys", "into", "the", "cache", "via", "the", "async", "path", ".", "The", "key", "set", "must", "always", "be", "non", "empty", ".", "The", "completion", "listener", "is", "called", "when", "all", "keys", "are", "loaded", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/WiredCache.java#L282-L298
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/WiredCache.java
WiredCache.peekAll
@Override public Map<K, V> peekAll(final Iterable<? extends K> keys) { Map<K, CacheEntry<K, V>> map = new HashMap<K, CacheEntry<K, V>>(); for (K k : keys) { CacheEntry<K, V> e = execute(k, SPEC.peekEntry(k)); if (e != null) { map.put(k, e); } } return heapCache.convertCacheEntry2ValueMap(map); }
java
@Override public Map<K, V> peekAll(final Iterable<? extends K> keys) { Map<K, CacheEntry<K, V>> map = new HashMap<K, CacheEntry<K, V>>(); for (K k : keys) { CacheEntry<K, V> e = execute(k, SPEC.peekEntry(k)); if (e != null) { map.put(k, e); } } return heapCache.convertCacheEntry2ValueMap(map); }
[ "@", "Override", "public", "Map", "<", "K", ",", "V", ">", "peekAll", "(", "final", "Iterable", "<", "?", "extends", "K", ">", "keys", ")", "{", "Map", "<", "K", ",", "CacheEntry", "<", "K", ",", "V", ">", ">", "map", "=", "new", "HashMap", "<"...
We need to deal with possible null values and exceptions. This is a simple placeholder implementation that covers it all by working on the entry.
[ "We", "need", "to", "deal", "with", "possible", "null", "values", "and", "exceptions", ".", "This", "is", "a", "simple", "placeholder", "implementation", "that", "covers", "it", "all", "by", "working", "on", "the", "entry", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/WiredCache.java#L515-L525
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/WiredCache.java
WiredCache.onEvictionFromHeap
@Override public void onEvictionFromHeap(final Entry<K, V> e) { CacheEntry<K,V> _currentEntry = heapCache.returnCacheEntry(e); if (syncEntryEvictedListeners != null) { for (CacheEntryEvictedListener<K, V> l : syncEntryEvictedListeners) { l.onEntryEvicted(this, _currentEntry); } } }
java
@Override public void onEvictionFromHeap(final Entry<K, V> e) { CacheEntry<K,V> _currentEntry = heapCache.returnCacheEntry(e); if (syncEntryEvictedListeners != null) { for (CacheEntryEvictedListener<K, V> l : syncEntryEvictedListeners) { l.onEntryEvicted(this, _currentEntry); } } }
[ "@", "Override", "public", "void", "onEvictionFromHeap", "(", "final", "Entry", "<", "K", ",", "V", ">", "e", ")", "{", "CacheEntry", "<", "K", ",", "V", ">", "_currentEntry", "=", "heapCache", ".", "returnCacheEntry", "(", "e", ")", ";", "if", "(", ...
Nothing done here. Will notify the storage about eviction in some future version.
[ "Nothing", "done", "here", ".", "Will", "notify", "the", "storage", "about", "eviction", "in", "some", "future", "version", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/WiredCache.java#L667-L675
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/expiry/Expiry.java
Expiry.mixTimeSpanAndPointInTime
public static long mixTimeSpanAndPointInTime(long loadTime, long refreshAfter, long pointInTime) { long _refreshTime = loadTime + refreshAfter; if (_refreshTime < 0) { _refreshTime = ETERNAL; } if (pointInTime == ETERNAL) { return _refreshTime; } if (pointInTime > _refreshTime) { return _refreshTime; } long _absPointInTime = Math.abs(pointInTime); if (_absPointInTime <= _refreshTime) { return pointInTime; } long _pointInTimeMinusDelta = _absPointInTime - refreshAfter; if (_pointInTimeMinusDelta < _refreshTime) { return _pointInTimeMinusDelta; } return _refreshTime; }
java
public static long mixTimeSpanAndPointInTime(long loadTime, long refreshAfter, long pointInTime) { long _refreshTime = loadTime + refreshAfter; if (_refreshTime < 0) { _refreshTime = ETERNAL; } if (pointInTime == ETERNAL) { return _refreshTime; } if (pointInTime > _refreshTime) { return _refreshTime; } long _absPointInTime = Math.abs(pointInTime); if (_absPointInTime <= _refreshTime) { return pointInTime; } long _pointInTimeMinusDelta = _absPointInTime - refreshAfter; if (_pointInTimeMinusDelta < _refreshTime) { return _pointInTimeMinusDelta; } return _refreshTime; }
[ "public", "static", "long", "mixTimeSpanAndPointInTime", "(", "long", "loadTime", ",", "long", "refreshAfter", ",", "long", "pointInTime", ")", "{", "long", "_refreshTime", "=", "loadTime", "+", "refreshAfter", ";", "if", "(", "_refreshTime", "<", "0", ")", "{...
Combine a refresh time span and an expiry at a specified point in time. <p>If the expiry time is far ahead of time the refresh time span takes precedence. If the point in time is close by this time takes precedence. If the refresh time is too close to the requested point an earlier refresh time is used to keep maximum distance to the requested point time, which is {@code abs(pointInTime) - refreshAfter} <p>Rationale: Usually the expiry is allowed to lag behind. This is okay when a normal expiry interval is used. If sharp expiry is requested an old value may not be visible at or after the expiry time. Refresh ahead implies lagging expiry, since the refresh is triggered when the value would usually expire. The two concepts can be combined in the expiry policy, e.g. using an interval for triggering refresh ahead and requesting a sharp expiry only when needed. If effective expiry time for the lagging variant and the for the sharp variant are in close proximity, conflicts need to be resolved. @param loadTime time when the load was started @param refreshAfter time span in milliseconds when the next refresh should happen @param pointInTime time in milliseconds since epoch for the next expiry. Can be negative if sharp expiry is requested, or {@link #ETERNAL} if no point in time expiry is needed.
[ "Combine", "a", "refresh", "time", "span", "and", "an", "expiry", "at", "a", "specified", "point", "in", "time", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/expiry/Expiry.java#L98-L118
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/event/AsyncDispatcher.java
AsyncDispatcher.getLockObject
private static Object getLockObject(Object key) { int hc = key.hashCode(); return KEY_LOCKS[hc & KEY_LOCKS_MASK]; }
java
private static Object getLockObject(Object key) { int hc = key.hashCode(); return KEY_LOCKS[hc & KEY_LOCKS_MASK]; }
[ "private", "static", "Object", "getLockObject", "(", "Object", "key", ")", "{", "int", "hc", "=", "key", ".", "hashCode", "(", ")", ";", "return", "KEY_LOCKS", "[", "hc", "&", "KEY_LOCKS_MASK", "]", ";", "}" ]
Simulate locking by key, use the hash code to spread and avoid lock contention. The additional locking we introduce here is currently run synchronously inside the entry mutation operation.
[ "Simulate", "locking", "by", "key", "use", "the", "hash", "code", "to", "spread", "and", "avoid", "lock", "contention", ".", "The", "additional", "locking", "we", "introduce", "here", "is", "currently", "run", "synchronously", "inside", "the", "entry", "mutati...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/event/AsyncDispatcher.java#L55-L58
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/event/AsyncDispatcher.java
AsyncDispatcher.queue
public void queue(final AsyncEvent<K> _event) { final K key = _event.getKey(); synchronized (getLockObject(key)) { Queue<AsyncEvent<K>> q = keyQueue.get(key); if (q != null) { q.add(_event); return; } q = new LinkedList<AsyncEvent<K>>(); keyQueue.put(key, q); } Runnable r = new Runnable() { @Override public void run() { runMoreOrStop(_event); } }; executor.execute(r); }
java
public void queue(final AsyncEvent<K> _event) { final K key = _event.getKey(); synchronized (getLockObject(key)) { Queue<AsyncEvent<K>> q = keyQueue.get(key); if (q != null) { q.add(_event); return; } q = new LinkedList<AsyncEvent<K>>(); keyQueue.put(key, q); } Runnable r = new Runnable() { @Override public void run() { runMoreOrStop(_event); } }; executor.execute(r); }
[ "public", "void", "queue", "(", "final", "AsyncEvent", "<", "K", ">", "_event", ")", "{", "final", "K", "key", "=", "_event", ".", "getKey", "(", ")", ";", "synchronized", "(", "getLockObject", "(", "key", ")", ")", "{", "Queue", "<", "AsyncEvent", "...
Immediately executes an event with the provided executor. If an event is already executing for the identical key, queue the event and execute the event with FIFO scheme, preserving the order of the arrival.
[ "Immediately", "executes", "an", "event", "with", "the", "provided", "executor", ".", "If", "an", "event", "is", "already", "executing", "for", "the", "identical", "key", "queue", "the", "event", "and", "execute", "the", "event", "with", "FIFO", "scheme", "p...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/event/AsyncDispatcher.java#L74-L92
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/event/AsyncDispatcher.java
AsyncDispatcher.runMoreOrStop
public void runMoreOrStop(AsyncEvent<K> _event) { for (;;) { try { _event.execute(); } catch (Throwable t) { cache.getLog().warn("Async event exception", t); } final K key = _event.getKey(); synchronized (getLockObject(key)) { Queue<AsyncEvent<K>> q = keyQueue.get(key); if (q.isEmpty()) { keyQueue.remove(key); return; } _event = q.remove(); } } }
java
public void runMoreOrStop(AsyncEvent<K> _event) { for (;;) { try { _event.execute(); } catch (Throwable t) { cache.getLog().warn("Async event exception", t); } final K key = _event.getKey(); synchronized (getLockObject(key)) { Queue<AsyncEvent<K>> q = keyQueue.get(key); if (q.isEmpty()) { keyQueue.remove(key); return; } _event = q.remove(); } } }
[ "public", "void", "runMoreOrStop", "(", "AsyncEvent", "<", "K", ">", "_event", ")", "{", "for", "(", ";", ";", ")", "{", "try", "{", "_event", ".", "execute", "(", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "cache", ".", "getLog", "...
Run as long there is still an event for the key.
[ "Run", "as", "long", "there", "is", "still", "an", "event", "for", "the", "key", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/event/AsyncDispatcher.java#L97-L114
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/BaseCache.java
BaseCache.keys
@Override public Iterable<K> keys() { return new Iterable<K>() { @Override public Iterator<K> iterator() { final Iterator<CacheEntry<K,V>> it = BaseCache.this.iterator(); return new Iterator<K>() { @Override public boolean hasNext() { return it.hasNext(); } @Override public K next() { return it.next().getKey(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
java
@Override public Iterable<K> keys() { return new Iterable<K>() { @Override public Iterator<K> iterator() { final Iterator<CacheEntry<K,V>> it = BaseCache.this.iterator(); return new Iterator<K>() { @Override public boolean hasNext() { return it.hasNext(); } @Override public K next() { return it.next().getKey(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; }
[ "@", "Override", "public", "Iterable", "<", "K", ">", "keys", "(", ")", "{", "return", "new", "Iterable", "<", "K", ">", "(", ")", "{", "@", "Override", "public", "Iterator", "<", "K", ">", "iterator", "(", ")", "{", "final", "Iterator", "<", "Cach...
Key iteration on top of normal iterator.
[ "Key", "iteration", "on", "top", "of", "normal", "iterator", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/BaseCache.java#L65-L89
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.setCacheConfig
public void setCacheConfig(final Cache2kConfiguration c) { valueType = c.getValueType(); keyType = c.getKeyType(); if (name != null) { throw new IllegalStateException("already configured"); } setName(c.getName()); setFeatureBit(KEEP_AFTER_EXPIRED, c.isKeepDataAfterExpired()); setFeatureBit(REJECT_NULL_VALUES, !c.isPermitNullValues()); setFeatureBit(BACKGROUND_REFRESH, c.isRefreshAhead()); setFeatureBit(UPDATE_TIME_NEEDED, c.isRecordRefreshedTime()); setFeatureBit(RECORD_REFRESH_TIME, c.isRecordRefreshedTime()); metrics = TUNABLE.commonMetricsFactory.create(new CommonMetricsFactory.Parameters() { @Override public boolean isDisabled() { return c.isDisableStatistics(); } @Override public boolean isPrecise() { return false; } }); if (c.getLoaderExecutor() != null) { loaderExecutor = createCustomization((CustomizationSupplier<Executor>) c.getLoaderExecutor()); } else { if (c.getLoaderThreadCount() > 0) { loaderExecutor = provideDefaultLoaderExecutor(c.getLoaderThreadCount()); } } if (c.getPrefetchExecutor() != null) { prefetchExecutor = createCustomization((CustomizationSupplier<Executor>) c.getPrefetchExecutor()); } }
java
public void setCacheConfig(final Cache2kConfiguration c) { valueType = c.getValueType(); keyType = c.getKeyType(); if (name != null) { throw new IllegalStateException("already configured"); } setName(c.getName()); setFeatureBit(KEEP_AFTER_EXPIRED, c.isKeepDataAfterExpired()); setFeatureBit(REJECT_NULL_VALUES, !c.isPermitNullValues()); setFeatureBit(BACKGROUND_REFRESH, c.isRefreshAhead()); setFeatureBit(UPDATE_TIME_NEEDED, c.isRecordRefreshedTime()); setFeatureBit(RECORD_REFRESH_TIME, c.isRecordRefreshedTime()); metrics = TUNABLE.commonMetricsFactory.create(new CommonMetricsFactory.Parameters() { @Override public boolean isDisabled() { return c.isDisableStatistics(); } @Override public boolean isPrecise() { return false; } }); if (c.getLoaderExecutor() != null) { loaderExecutor = createCustomization((CustomizationSupplier<Executor>) c.getLoaderExecutor()); } else { if (c.getLoaderThreadCount() > 0) { loaderExecutor = provideDefaultLoaderExecutor(c.getLoaderThreadCount()); } } if (c.getPrefetchExecutor() != null) { prefetchExecutor = createCustomization((CustomizationSupplier<Executor>) c.getPrefetchExecutor()); } }
[ "public", "void", "setCacheConfig", "(", "final", "Cache2kConfiguration", "c", ")", "{", "valueType", "=", "c", ".", "getValueType", "(", ")", ";", "keyType", "=", "c", ".", "getKeyType", "(", ")", ";", "if", "(", "name", "!=", "null", ")", "{", "throw...
called from CacheBuilder
[ "called", "from", "CacheBuilder" ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L252-L287
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.setName
public void setName(String n) { if (n == null) { n = this.getClass().getSimpleName() + "#" + cacheCnt++; } name = n; }
java
public void setName(String n) { if (n == null) { n = this.getClass().getSimpleName() + "#" + cacheCnt++; } name = n; }
[ "public", "void", "setName", "(", "String", "n", ")", "{", "if", "(", "n", "==", "null", ")", "{", "n", "=", "this", ".", "getClass", "(", ")", ".", "getSimpleName", "(", ")", "+", "\"#\"", "+", "cacheCnt", "++", ";", "}", "name", "=", "n", ";"...
Set the name and configure a logging, used within cache construction.
[ "Set", "the", "name", "and", "configure", "a", "logging", "used", "within", "cache", "construction", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L319-L324
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.returnEntry
protected CacheEntry<K, V> returnEntry(final ExaminationEntry<K, V> e) { if (e == null) { return null; } return returnCacheEntry(e); }
java
protected CacheEntry<K, V> returnEntry(final ExaminationEntry<K, V> e) { if (e == null) { return null; } return returnCacheEntry(e); }
[ "protected", "CacheEntry", "<", "K", ",", "V", ">", "returnEntry", "(", "final", "ExaminationEntry", "<", "K", ",", "V", ">", "e", ")", "{", "if", "(", "e", "==", "null", ")", "{", "return", "null", ";", "}", "return", "returnCacheEntry", "(", "e", ...
Wrap entry in a separate object instance. We can return the entry directly, however we lock on the entry object.
[ "Wrap", "entry", "in", "a", "separate", "object", "instance", ".", "We", "can", "return", "the", "entry", "directly", "however", "we", "lock", "on", "the", "entry", "object", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L556-L561
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.putValue
protected final void putValue(final Entry e, final V _value) { if (!isUpdateTimeNeeded()) { insertOrUpdateAndCalculateExpiry(e, _value, 0, 0, 0 , INSERT_STAT_PUT); } else { long t = clock.millis(); insertOrUpdateAndCalculateExpiry(e, _value, t, t, t, INSERT_STAT_PUT); } }
java
protected final void putValue(final Entry e, final V _value) { if (!isUpdateTimeNeeded()) { insertOrUpdateAndCalculateExpiry(e, _value, 0, 0, 0 , INSERT_STAT_PUT); } else { long t = clock.millis(); insertOrUpdateAndCalculateExpiry(e, _value, t, t, t, INSERT_STAT_PUT); } }
[ "protected", "final", "void", "putValue", "(", "final", "Entry", "e", ",", "final", "V", "_value", ")", "{", "if", "(", "!", "isUpdateTimeNeeded", "(", ")", ")", "{", "insertOrUpdateAndCalculateExpiry", "(", "e", ",", "_value", ",", "0", ",", "0", ",", ...
Update the value directly within entry lock. Since we did not start entry processing we do not need to notify any waiting threads.
[ "Update", "the", "value", "directly", "within", "entry", "lock", ".", "Since", "we", "did", "not", "start", "entry", "processing", "we", "do", "not", "need", "to", "notify", "any", "waiting", "threads", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L764-L771
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.replace
protected boolean replace(final K key, final boolean _compare, final V _oldValue, final V _newValue) { Entry e = lookupEntry(key); if (e == null) { metrics.peekMiss(); return false; } synchronized (e) { e.waitForProcessing(); if (e.isGone() || !e.hasFreshData(clock)) { return false; } if (_compare && !e.equalsValue(_oldValue)) { return false; } putValue(e, _newValue); } return true; }
java
protected boolean replace(final K key, final boolean _compare, final V _oldValue, final V _newValue) { Entry e = lookupEntry(key); if (e == null) { metrics.peekMiss(); return false; } synchronized (e) { e.waitForProcessing(); if (e.isGone() || !e.hasFreshData(clock)) { return false; } if (_compare && !e.equalsValue(_oldValue)) { return false; } putValue(e, _newValue); } return true; }
[ "protected", "boolean", "replace", "(", "final", "K", "key", ",", "final", "boolean", "_compare", ",", "final", "V", "_oldValue", ",", "final", "V", "_newValue", ")", "{", "Entry", "e", "=", "lookupEntry", "(", "key", ")", ";", "if", "(", "e", "==", ...
replace if value matches. if value not matches, return the existing entry or the dummy entry.
[ "replace", "if", "value", "matches", ".", "if", "value", "not", "matches", "return", "the", "existing", "entry", "or", "the", "dummy", "entry", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L786-L803
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.peekEntryInternal
final protected Entry<K, V> peekEntryInternal(K key) { int hc = modifiedHash(key.hashCode()); return peekEntryInternal(key, hc, extractIntKeyValue(key, hc)); }
java
final protected Entry<K, V> peekEntryInternal(K key) { int hc = modifiedHash(key.hashCode()); return peekEntryInternal(key, hc, extractIntKeyValue(key, hc)); }
[ "final", "protected", "Entry", "<", "K", ",", "V", ">", "peekEntryInternal", "(", "K", "key", ")", "{", "int", "hc", "=", "modifiedHash", "(", "key", ".", "hashCode", "(", ")", ")", ";", "return", "peekEntryInternal", "(", "key", ",", "hc", ",", "ext...
Return the entry, if it is in the cache, without invoking the cache source. <p>The cache storage is asked whether the entry is present. If the entry is not present, this result is cached in the local cache.
[ "Return", "the", "entry", "if", "it", "is", "in", "the", "cache", "without", "invoking", "the", "cache", "source", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L813-L816
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.removeIfEquals
@Override public boolean removeIfEquals(K key, V _value) { Entry e = lookupEntry(key); if (e == null) { metrics.peekMiss(); return false; } synchronized (e) { e.waitForProcessing(); if (e.isGone()) { metrics.peekMiss(); return false; } boolean f = e.hasFreshData(clock); if (f) { if (!e.equalsValue(_value)) { return false; } } else { metrics.peekHitNotFresh(); return false; } removeEntry(e); return f; } }
java
@Override public boolean removeIfEquals(K key, V _value) { Entry e = lookupEntry(key); if (e == null) { metrics.peekMiss(); return false; } synchronized (e) { e.waitForProcessing(); if (e.isGone()) { metrics.peekMiss(); return false; } boolean f = e.hasFreshData(clock); if (f) { if (!e.equalsValue(_value)) { return false; } } else { metrics.peekHitNotFresh(); return false; } removeEntry(e); return f; } }
[ "@", "Override", "public", "boolean", "removeIfEquals", "(", "K", "key", ",", "V", "_value", ")", "{", "Entry", "e", "=", "lookupEntry", "(", "key", ")", ";", "if", "(", "e", "==", "null", ")", "{", "metrics", ".", "peekMiss", "(", ")", ";", "retur...
Remove the object from the cache.
[ "Remove", "the", "object", "from", "the", "cache", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L968-L993
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.loadAndReplace
protected void loadAndReplace(K key) { Entry e; for (;;) { e = lookupOrNewEntry(key); synchronized (e) { e.waitForProcessing(); if (e.isGone()) { metrics.goneSpin(); continue; } e.startProcessing(Entry.ProcessingState.LOAD); break; } } boolean _finished = false; try { load(e); _finished = true; } finally { e.ensureAbort(_finished); } }
java
protected void loadAndReplace(K key) { Entry e; for (;;) { e = lookupOrNewEntry(key); synchronized (e) { e.waitForProcessing(); if (e.isGone()) { metrics.goneSpin(); continue; } e.startProcessing(Entry.ProcessingState.LOAD); break; } } boolean _finished = false; try { load(e); _finished = true; } finally { e.ensureAbort(_finished); } }
[ "protected", "void", "loadAndReplace", "(", "K", "key", ")", "{", "Entry", "e", ";", "for", "(", ";", ";", ")", "{", "e", "=", "lookupOrNewEntry", "(", "key", ")", ";", "synchronized", "(", "e", ")", "{", "e", ".", "waitForProcessing", "(", ")", ";...
Always fetch the value from the source. That is a copy of getEntryInternal without freshness checks.
[ "Always", "fetch", "the", "value", "from", "the", "source", ".", "That", "is", "a", "copy", "of", "getEntryInternal", "without", "freshness", "checks", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1198-L1219
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.checkForHashCodeChange
private void checkForHashCodeChange(Entry<K, V> e) { K key = extractKeyObj(e); if (extractIntKeyValue(key, modifiedHash(key.hashCode())) != e.hashCode) { if (keyMutationCnt == 0) { getLog().warn("Key mismatch! Key hashcode changed! keyClass=" + e.getKey().getClass().getName()); String s; try { s = e.getKey().toString(); if (s != null) { getLog().warn("Key mismatch! key.toString(): " + s); } } catch (Throwable t) { getLog().warn("Key mismatch! key.toString() threw exception", t); } } keyMutationCnt++; } }
java
private void checkForHashCodeChange(Entry<K, V> e) { K key = extractKeyObj(e); if (extractIntKeyValue(key, modifiedHash(key.hashCode())) != e.hashCode) { if (keyMutationCnt == 0) { getLog().warn("Key mismatch! Key hashcode changed! keyClass=" + e.getKey().getClass().getName()); String s; try { s = e.getKey().toString(); if (s != null) { getLog().warn("Key mismatch! key.toString(): " + s); } } catch (Throwable t) { getLog().warn("Key mismatch! key.toString() threw exception", t); } } keyMutationCnt++; } }
[ "private", "void", "checkForHashCodeChange", "(", "Entry", "<", "K", ",", "V", ">", "e", ")", "{", "K", "key", "=", "extractKeyObj", "(", "e", ")", ";", "if", "(", "extractIntKeyValue", "(", "key", ",", "modifiedHash", "(", "key", ".", "hashCode", "(",...
Check whether the key was modified during the stay of the entry in the cache. We only need to check this when the entry is removed, since we expect that if the key has changed, the stored hash code in the cache will not match any more and the item is evicted very fast.
[ "Check", "whether", "the", "key", "was", "modified", "during", "the", "stay", "of", "the", "entry", "in", "the", "cache", ".", "We", "only", "need", "to", "check", "this", "when", "the", "entry", "is", "removed", "since", "we", "expect", "that", "if", ...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1335-L1352
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.entryInRefreshProbationAccessed
private boolean entryInRefreshProbationAccessed(final Entry<K, V> e, final long now) { long nrt = e.getRefreshProbationNextRefreshTime(); if (nrt > now) { reviveRefreshedEntry(e, nrt); return true; } return false; }
java
private boolean entryInRefreshProbationAccessed(final Entry<K, V> e, final long now) { long nrt = e.getRefreshProbationNextRefreshTime(); if (nrt > now) { reviveRefreshedEntry(e, nrt); return true; } return false; }
[ "private", "boolean", "entryInRefreshProbationAccessed", "(", "final", "Entry", "<", "K", ",", "V", ">", "e", ",", "final", "long", "now", ")", "{", "long", "nrt", "=", "e", ".", "getRefreshProbationNextRefreshTime", "(", ")", ";", "if", "(", "nrt", ">", ...
Entry was refreshed before, reset timer and make entry visible again.
[ "Entry", "was", "refreshed", "before", "reset", "timer", "and", "make", "entry", "visible", "again", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1393-L1400
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.resiliencePolicyException
private void resiliencePolicyException(final Entry<K, V> e, final long t0, final long t, Throwable _exception) { ExceptionWrapper<K> _value = new ExceptionWrapper(extractKeyObj(e), _exception, t0, e); insert(e, (V) _value, t0, t, t0, INSERT_STAT_LOAD, 0); }
java
private void resiliencePolicyException(final Entry<K, V> e, final long t0, final long t, Throwable _exception) { ExceptionWrapper<K> _value = new ExceptionWrapper(extractKeyObj(e), _exception, t0, e); insert(e, (V) _value, t0, t, t0, INSERT_STAT_LOAD, 0); }
[ "private", "void", "resiliencePolicyException", "(", "final", "Entry", "<", "K", ",", "V", ">", "e", ",", "final", "long", "t0", ",", "final", "long", "t", ",", "Throwable", "_exception", ")", "{", "ExceptionWrapper", "<", "K", ">", "_value", "=", "new",...
Exception from the resilience policy. We have two exceptions now. One from the loader or the expiry policy, one from the resilience policy. We propagate the more severe one from the resilience policy.
[ "Exception", "from", "the", "resilience", "policy", ".", "We", "have", "two", "exceptions", "now", ".", "One", "from", "the", "loader", "or", "the", "expiry", "policy", "one", "from", "the", "resilience", "policy", ".", "We", "propagate", "the", "more", "s...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1445-L1448
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.refreshEntry
private void refreshEntry(final Entry<K, V> e) { synchronized (e) { e.waitForProcessing(); if (e.isGone()) { return; } e.startProcessing(Entry.ProcessingState.REFRESH); } boolean _finished = false; try { load(e); _finished = true; } catch (CacheClosedException ignore) { } catch (Throwable ex) { logAndCountInternalException("Refresh exception", ex); try { synchronized (e) { expireEntry(e); } } catch (CacheClosedException ignore) { } } finally { e.ensureAbort(_finished); } }
java
private void refreshEntry(final Entry<K, V> e) { synchronized (e) { e.waitForProcessing(); if (e.isGone()) { return; } e.startProcessing(Entry.ProcessingState.REFRESH); } boolean _finished = false; try { load(e); _finished = true; } catch (CacheClosedException ignore) { } catch (Throwable ex) { logAndCountInternalException("Refresh exception", ex); try { synchronized (e) { expireEntry(e); } } catch (CacheClosedException ignore) { } } finally { e.ensureAbort(_finished); } }
[ "private", "void", "refreshEntry", "(", "final", "Entry", "<", "K", ",", "V", ">", "e", ")", "{", "synchronized", "(", "e", ")", "{", "e", ".", "waitForProcessing", "(", ")", ";", "if", "(", "e", ".", "isGone", "(", ")", ")", "{", "return", ";", ...
Executed in loader thread. Load the entry again. After the load we copy the entry to the refresh hash and expire it in the main hash. The entry needs to stay in the main hash during the load, to block out concurrent reads.
[ "Executed", "in", "loader", "thread", ".", "Load", "the", "entry", "again", ".", "After", "the", "load", "we", "copy", "the", "entry", "to", "the", "refresh", "hash", "and", "expire", "it", "in", "the", "main", "hash", ".", "The", "entry", "needs", "to...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1565-L1589
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.expireAndRemoveEventually
private void expireAndRemoveEventually(final Entry e) { if (isKeepAfterExpired() || e.isProcessing()) { metrics.expiredKept(); } else { removeEntry(e); } }
java
private void expireAndRemoveEventually(final Entry e) { if (isKeepAfterExpired() || e.isProcessing()) { metrics.expiredKept(); } else { removeEntry(e); } }
[ "private", "void", "expireAndRemoveEventually", "(", "final", "Entry", "e", ")", "{", "if", "(", "isKeepAfterExpired", "(", ")", "||", "e", ".", "isProcessing", "(", ")", ")", "{", "metrics", ".", "expiredKept", "(", ")", ";", "}", "else", "{", "removeEn...
Remove expired from heap and increment statistics. The entry is not removed when there is processing going on in parallel. @see #expireAndRemoveEventuallyAfterProcessing(Entry)
[ "Remove", "expired", "from", "heap", "and", "increment", "statistics", ".", "The", "entry", "is", "not", "removed", "when", "there", "is", "processing", "going", "on", "in", "parallel", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1656-L1663
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.getAll
public Map<K, V> getAll(final Iterable<? extends K> _inputKeys) { Map<K, ExaminationEntry<K, V>> map = new HashMap<K, ExaminationEntry<K, V>>(); for (K k : _inputKeys) { Entry<K,V> e = getEntryInternal(k); if (e != null) { map.put(extractKeyObj(e), ReadOnlyCacheEntry.of(e)); } } return convertValueMap(map); }
java
public Map<K, V> getAll(final Iterable<? extends K> _inputKeys) { Map<K, ExaminationEntry<K, V>> map = new HashMap<K, ExaminationEntry<K, V>>(); for (K k : _inputKeys) { Entry<K,V> e = getEntryInternal(k); if (e != null) { map.put(extractKeyObj(e), ReadOnlyCacheEntry.of(e)); } } return convertValueMap(map); }
[ "public", "Map", "<", "K", ",", "V", ">", "getAll", "(", "final", "Iterable", "<", "?", "extends", "K", ">", "_inputKeys", ")", "{", "Map", "<", "K", ",", "ExaminationEntry", "<", "K", ",", "V", ">", ">", "map", "=", "new", "HashMap", "<", "K", ...
JSR107 bulk interface. The behaviour is compatible to the JSR107 TCK. We also need to be compatible to the exception handling policy, which says that the exception is to be thrown when most specific. So exceptions are only thrown, when the value which has produced an exception is requested from the map.
[ "JSR107", "bulk", "interface", ".", "The", "behaviour", "is", "compatible", "to", "the", "JSR107", "TCK", ".", "We", "also", "need", "to", "be", "compatible", "to", "the", "exception", "handling", "policy", "which", "says", "that", "the", "exception", "is", ...
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1693-L1702
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/HeapCache.java
HeapCache.checkIntegrity
public final void checkIntegrity() { executeWithGlobalLock(new Job<Void>() { @Override public Void call() { IntegrityState is = getIntegrityState(); if (is.getStateFlags() > 0) { throw new Error( "cache2k integrity error: " + is.getStateDescriptor() + ", " + is.getFailingChecks() + ", " + generateInfoUnderLock(HeapCache.this, clock.millis()).toString()); } return null; } }); }
java
public final void checkIntegrity() { executeWithGlobalLock(new Job<Void>() { @Override public Void call() { IntegrityState is = getIntegrityState(); if (is.getStateFlags() > 0) { throw new Error( "cache2k integrity error: " + is.getStateDescriptor() + ", " + is.getFailingChecks() + ", " + generateInfoUnderLock(HeapCache.this, clock.millis()).toString()); } return null; } }); }
[ "public", "final", "void", "checkIntegrity", "(", ")", "{", "executeWithGlobalLock", "(", "new", "Job", "<", "Void", ">", "(", ")", "{", "@", "Override", "public", "Void", "call", "(", ")", "{", "IntegrityState", "is", "=", "getIntegrityState", "(", ")", ...
Check internal data structures and throw and exception if something is wrong, used for unit testing
[ "Check", "internal", "data", "structures", "and", "throw", "and", "exception", "if", "something", "is", "wrong", "used", "for", "unit", "testing" ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/HeapCache.java#L1802-L1815
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/configuration/DefaultCustomizationCollection.java
DefaultCustomizationCollection.add
@Override public boolean add(final CustomizationSupplier<T> entry) { if (list.contains(entry)) { throw new IllegalArgumentException("duplicate entry"); } return list.add(entry); }
java
@Override public boolean add(final CustomizationSupplier<T> entry) { if (list.contains(entry)) { throw new IllegalArgumentException("duplicate entry"); } return list.add(entry); }
[ "@", "Override", "public", "boolean", "add", "(", "final", "CustomizationSupplier", "<", "T", ">", "entry", ")", "{", "if", "(", "list", ".", "contains", "(", "entry", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"duplicate entry\"", ")"...
Adds a customization to the collection. @return always {@code true} @throws IllegalArgumentException if the entry is already existing.
[ "Adds", "a", "customization", "to", "the", "collection", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/configuration/DefaultCustomizationCollection.java#L59-L65
train
cache2k/cache2k
cache2k-core/src/main/java/org/cache2k/core/concurrency/Locks.java
Locks.newOptimistic
public static OptimisticLock newOptimistic() { if (optimisticLockImplementation == null) { initializeOptimisticLock(); } try { return optimisticLockImplementation.newInstance(); } catch (Exception ex) { throw new Error(ex); } }
java
public static OptimisticLock newOptimistic() { if (optimisticLockImplementation == null) { initializeOptimisticLock(); } try { return optimisticLockImplementation.newInstance(); } catch (Exception ex) { throw new Error(ex); } }
[ "public", "static", "OptimisticLock", "newOptimistic", "(", ")", "{", "if", "(", "optimisticLockImplementation", "==", "null", ")", "{", "initializeOptimisticLock", "(", ")", ";", "}", "try", "{", "return", "optimisticLockImplementation", ".", "newInstance", "(", ...
Returns a new lock implementation depending on the platform support.
[ "Returns", "a", "new", "lock", "implementation", "depending", "on", "the", "platform", "support", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-core/src/main/java/org/cache2k/core/concurrency/Locks.java#L37-L46
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/TouchyJCacheAdapter.java
TouchyJCacheAdapter.returnEntry
private Entry<K, V> returnEntry(final Entry<K, V> e) { touchEntry(e.getKey()); return e; }
java
private Entry<K, V> returnEntry(final Entry<K, V> e) { touchEntry(e.getKey()); return e; }
[ "private", "Entry", "<", "K", ",", "V", ">", "returnEntry", "(", "final", "Entry", "<", "K", ",", "V", ">", "e", ")", "{", "touchEntry", "(", "e", ".", "getKey", "(", ")", ")", ";", "return", "e", ";", "}" ]
Entry is accessed update expiry if needed.
[ "Entry", "is", "accessed", "update", "expiry", "if", "needed", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/TouchyJCacheAdapter.java#L499-L502
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/TouchyJCacheAdapter.java
TouchyJCacheAdapter.returnValue
private V returnValue(K key, V _value) { if (_value != null) { Duration d = expiryPolicy.getExpiryForAccess(); if (d != null) { c2kCache.expireAt(key, calculateExpiry(d)); } return _value; } return null; }
java
private V returnValue(K key, V _value) { if (_value != null) { Duration d = expiryPolicy.getExpiryForAccess(); if (d != null) { c2kCache.expireAt(key, calculateExpiry(d)); } return _value; } return null; }
[ "private", "V", "returnValue", "(", "K", "key", ",", "V", "_value", ")", "{", "if", "(", "_value", "!=", "null", ")", "{", "Duration", "d", "=", "expiryPolicy", ".", "getExpiryForAccess", "(", ")", ";", "if", "(", "d", "!=", "null", ")", "{", "c2kC...
Entry was accessed update expiry if value is non null.
[ "Entry", "was", "accessed", "update", "expiry", "if", "value", "is", "non", "null", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/TouchyJCacheAdapter.java#L507-L516
train
cache2k/cache2k
cache2k-api/src/main/java/org/cache2k/integration/CacheLoader.java
CacheLoader.loadAll
public Map<K, V> loadAll(Iterable<? extends K> keys, Executor executor) throws Exception { throw new UnsupportedOperationException(); }
java
public Map<K, V> loadAll(Iterable<? extends K> keys, Executor executor) throws Exception { throw new UnsupportedOperationException(); }
[ "public", "Map", "<", "K", ",", "V", ">", "loadAll", "(", "Iterable", "<", "?", "extends", "K", ">", "keys", ",", "Executor", "executor", ")", "throws", "Exception", "{", "throw", "new", "UnsupportedOperationException", "(", ")", ";", "}" ]
Loads multiple values to the cache. <p>From inside this method it is illegal to call methods on the same cache. This may cause a deadlock. <p>The method is provided to complete the API. At the moment cache2k is not using it. Please see the road map. @param keys set of keys for the values to be loaded @param executor an executor for concurrent loading @return The loaded values. A key may map to {@code null} if the cache permits {@code null} values. @throws Exception Unhandled exception from the loader. Exceptions are suppressed or wrapped and rethrown via a {@link CacheLoaderException}. If an exception happens the cache may retry the load with the single value load method.
[ "Loads", "multiple", "values", "to", "the", "cache", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-api/src/main/java/org/cache2k/integration/CacheLoader.java#L107-L109
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheBuilder.java
JCacheBuilder.setupTypes
private void setupTypes() { if (!cache2kConfigurationWasProvided) { cache2kConfiguration.setKeyType(config.getKeyType()); cache2kConfiguration.setValueType(config.getValueType()); } else { if (cache2kConfiguration.getKeyType() == null) { cache2kConfiguration.setKeyType(config.getKeyType()); } if (cache2kConfiguration.getValueType() == null) { cache2kConfiguration.setValueType(config.getValueType()); } } keyType = cache2kConfiguration.getKeyType(); valueType = cache2kConfiguration.getValueType(); if (!config.getKeyType().equals(Object.class) && !config.getKeyType().equals(keyType.getType())) { throw new IllegalArgumentException("Key type mismatch between JCache and cache2k configuration"); } if (!config.getValueType().equals(Object.class) && !config.getValueType().equals(valueType.getType())) { throw new IllegalArgumentException("Value type mismatch between JCache and cache2k configuration"); } }
java
private void setupTypes() { if (!cache2kConfigurationWasProvided) { cache2kConfiguration.setKeyType(config.getKeyType()); cache2kConfiguration.setValueType(config.getValueType()); } else { if (cache2kConfiguration.getKeyType() == null) { cache2kConfiguration.setKeyType(config.getKeyType()); } if (cache2kConfiguration.getValueType() == null) { cache2kConfiguration.setValueType(config.getValueType()); } } keyType = cache2kConfiguration.getKeyType(); valueType = cache2kConfiguration.getValueType(); if (!config.getKeyType().equals(Object.class) && !config.getKeyType().equals(keyType.getType())) { throw new IllegalArgumentException("Key type mismatch between JCache and cache2k configuration"); } if (!config.getValueType().equals(Object.class) && !config.getValueType().equals(valueType.getType())) { throw new IllegalArgumentException("Value type mismatch between JCache and cache2k configuration"); } }
[ "private", "void", "setupTypes", "(", ")", "{", "if", "(", "!", "cache2kConfigurationWasProvided", ")", "{", "cache2kConfiguration", ".", "setKeyType", "(", "config", ".", "getKeyType", "(", ")", ")", ";", "cache2kConfiguration", ".", "setValueType", "(", "confi...
If there is a cache2k configuration, we take the types from there.
[ "If", "there", "is", "a", "cache2k", "configuration", "we", "take", "the", "types", "from", "there", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheBuilder.java#L154-L174
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheBuilder.java
JCacheBuilder.setupExceptionPropagator
private void setupExceptionPropagator() { if (cache2kConfiguration.getExceptionPropagator() != null) { return; } cache2kConfiguration.setExceptionPropagator( new CustomizationReferenceSupplier<ExceptionPropagator<K>>(new ExceptionPropagator<K>() { @Override public RuntimeException propagateException(Object key, final ExceptionInformation exceptionInformation) { return new CacheLoaderException("propagate previous loader exception", exceptionInformation.getException()); } })); }
java
private void setupExceptionPropagator() { if (cache2kConfiguration.getExceptionPropagator() != null) { return; } cache2kConfiguration.setExceptionPropagator( new CustomizationReferenceSupplier<ExceptionPropagator<K>>(new ExceptionPropagator<K>() { @Override public RuntimeException propagateException(Object key, final ExceptionInformation exceptionInformation) { return new CacheLoaderException("propagate previous loader exception", exceptionInformation.getException()); } })); }
[ "private", "void", "setupExceptionPropagator", "(", ")", "{", "if", "(", "cache2kConfiguration", ".", "getExceptionPropagator", "(", ")", "!=", "null", ")", "{", "return", ";", "}", "cache2kConfiguration", ".", "setExceptionPropagator", "(", "new", "CustomizationRef...
If an exception propagator is configured, take this one, otherwise go with default that is providing JCache compatible behavior.
[ "If", "an", "exception", "propagator", "is", "configured", "take", "this", "one", "otherwise", "go", "with", "default", "that", "is", "providing", "JCache", "compatible", "behavior", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheBuilder.java#L190-L201
train
cache2k/cache2k
cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheBuilder.java
JCacheBuilder.setupCacheThrough
private void setupCacheThrough() { if (config.getCacheLoaderFactory() != null) { final CacheLoader<K, V> clf = config.getCacheLoaderFactory().create(); cache2kConfiguration.setAdvancedLoader( new CustomizationReferenceSupplier<AdvancedCacheLoader<K, V>>( new CloseableLoader() { @Override public void close() throws IOException { if (clf instanceof Closeable) { ((Closeable) clf).close(); } } @Override public V load(final K key, final long currentTime, final CacheEntry<K, V> currentEntry) { return clf.load(key); } })); } if (config.getCacheWriterFactory() != null) { final javax.cache.integration.CacheWriter<? super K, ? super V> cw = config.getCacheWriterFactory().create(); cache2kConfiguration.setWriter(new CustomizationReferenceSupplier<CacheWriter<K, V>>(new CloseableWriter() { @Override public void write(final K key, final V value) { Cache.Entry<K, V> ce = new Cache.Entry<K, V>() { @Override public K getKey() { return key; } @Override public V getValue() { return value; } @Override public <T> T unwrap(Class<T> clazz) { throw new UnsupportedOperationException("unwrap entry not supported"); } }; cw.write(ce); } @Override public void delete(final Object key) { cw.delete(key); } @Override public void close() throws IOException { if (cw instanceof Closeable) { ((Closeable) cw).close(); } } })); } }
java
private void setupCacheThrough() { if (config.getCacheLoaderFactory() != null) { final CacheLoader<K, V> clf = config.getCacheLoaderFactory().create(); cache2kConfiguration.setAdvancedLoader( new CustomizationReferenceSupplier<AdvancedCacheLoader<K, V>>( new CloseableLoader() { @Override public void close() throws IOException { if (clf instanceof Closeable) { ((Closeable) clf).close(); } } @Override public V load(final K key, final long currentTime, final CacheEntry<K, V> currentEntry) { return clf.load(key); } })); } if (config.getCacheWriterFactory() != null) { final javax.cache.integration.CacheWriter<? super K, ? super V> cw = config.getCacheWriterFactory().create(); cache2kConfiguration.setWriter(new CustomizationReferenceSupplier<CacheWriter<K, V>>(new CloseableWriter() { @Override public void write(final K key, final V value) { Cache.Entry<K, V> ce = new Cache.Entry<K, V>() { @Override public K getKey() { return key; } @Override public V getValue() { return value; } @Override public <T> T unwrap(Class<T> clazz) { throw new UnsupportedOperationException("unwrap entry not supported"); } }; cw.write(ce); } @Override public void delete(final Object key) { cw.delete(key); } @Override public void close() throws IOException { if (cw instanceof Closeable) { ((Closeable) cw).close(); } } })); } }
[ "private", "void", "setupCacheThrough", "(", ")", "{", "if", "(", "config", ".", "getCacheLoaderFactory", "(", ")", "!=", "null", ")", "{", "final", "CacheLoader", "<", "K", ",", "V", ">", "clf", "=", "config", ".", "getCacheLoaderFactory", "(", ")", "."...
Configure loader and writer.
[ "Configure", "loader", "and", "writer", "." ]
3c9ccff12608c598c387ec50957089784cc4b618
https://github.com/cache2k/cache2k/blob/3c9ccff12608c598c387ec50957089784cc4b618/cache2k-jcache/src/main/java/org/cache2k/jcache/provider/JCacheBuilder.java#L209-L267
train