Remove class to use local AtomicInteger property.

This commit is contained in:
Angel Borroy
2019-08-28 15:15:41 +02:00
parent 5a45b040bc
commit eba5581355
7 changed files with 74 additions and 64 deletions
+9
View File
@@ -39,4 +39,13 @@
<module>search-services</module>
<module>insight-engine</module>
</modules>
<dependencies>
<!-- Used to declare false positives for FindBugs -->
<dependency>
<groupId>findbugs</groupId>
<artifactId>annotations</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -472,12 +472,7 @@ public class AsyncBuildSuggestComponent extends SearchComponent implements SolrC
@Override
public long ramBytesUsed() {
long sizeInBytes = 0;
for (Entry<String, SuggesterCache> suggester : suggesters.entrySet())
{
sizeInBytes += suggester.getValue().get(ASYNC_CACHE_KEY).ramBytesUsed();
}
return sizeInBytes;
return suggesters.values().stream().mapToLong(value -> value.get(ASYNC_CACHE_KEY).ramBytesUsed()).sum();
}
private Set<SolrSuggester> getSuggesters(SolrParams params) {
@@ -19,12 +19,16 @@
package org.alfresco.solr.component;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import org.slf4j.Logger;
import org.springframework.util.StringUtils;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
/**
* Temp files may take up a lot of space, warn administrators
* of their existence, giving them the chance to manage them.
@@ -45,6 +49,8 @@ public class TempFileWarningLogger
glob = prefix + ".{"+ StringUtils.arrayToCommaDelimitedString(extensions) + "}";
}
// Avoid FindBugs false positive (https://github.com/spotbugs/spotbugs/issues/756)
@SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public boolean checkFiles()
{
if (log.isDebugEnabled())
@@ -52,9 +58,9 @@ public class TempFileWarningLogger
log.debug("Looking for temp files matching " + glob + " in directory " + dir);
}
try
try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir, glob))
{
for (Path file : Files.newDirectoryStream(dir, glob))
for (Path file : stream)
{
if (log.isDebugEnabled())
{
@@ -71,11 +77,13 @@ public class TempFileWarningLogger
}
}
// Avoid FindBugs false positive (https://github.com/spotbugs/spotbugs/issues/756)
@SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public void removeFiles()
{
try
try(DirectoryStream<Path> stream = Files.newDirectoryStream(dir, glob))
{
for (Path file : Files.newDirectoryStream(dir, glob))
for (Path file : stream)
{
file.toFile().delete();
}
@@ -19,6 +19,7 @@
package org.alfresco.solr.query;
import java.io.IOException;
import java.util.stream.LongStream;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.DocIdSetIterator;
@@ -43,12 +44,7 @@ public abstract class AbstractSolrCachingScorer extends Scorer
private LongCache(){}
static final Long cache[] = new Long[CACHE_SIZE];
static {
for(int i = 0; i < cache.length; i++)
cache[i] = Long.valueOf(i);
}
static final long cache[] = LongStream.range(0, CACHE_SIZE).toArray();
}
protected static Long getLong(long l) {
@@ -144,6 +144,8 @@ import org.jaxen.saxpath.base.XPathReader;
import org.json.JSONObject;
import org.springframework.extensions.surf.util.I18NUtil;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
/**
* @author Andy
*
@@ -3299,39 +3301,50 @@ public class Solr4QueryParser extends QueryParser implements QueryConstants
namespacePrefixResolver, field.substring(1));
}
// Avoid FindBugs false positive (https://github.com/spotbugs/spotbugs/issues/756)
@SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
protected String getToken(String field, String value, AnalysisMode analysisMode) throws ParseException
{
TokenStream source = getAnalyzer().tokenStream(field, new StringReader(value));
try (TokenStream source = getAnalyzer().tokenStream(field, new StringReader(value)))
{
String tokenised = null;
CharTermAttribute cta = source.getAttribute(CharTermAttribute.class);
OffsetAttribute offsetAtt = source.getAttribute(OffsetAttribute.class);
TypeAttribute typeAtt = null;
if (source.hasAttribute(TypeAttribute.class))
while (source.incrementToken())
{
CharTermAttribute cta = source.getAttribute(CharTermAttribute.class);
OffsetAttribute offsetAtt = source.getAttribute(OffsetAttribute.class);
TypeAttribute typeAtt = null;
if (source.hasAttribute(TypeAttribute.class))
{
typeAtt = source.getAttribute(TypeAttribute.class);
}
PositionIncrementAttribute posIncAtt = null;
if (source.hasAttribute(PositionIncrementAttribute.class))
{
posIncAtt = source.getAttribute(PositionIncrementAttribute.class);
}
PackedTokenAttributeImpl token = new PackedTokenAttributeImpl();
token.setEmpty().copyBuffer(cta.buffer(), 0, cta.length());
token.setOffset(offsetAtt.startOffset(), offsetAtt.endOffset());
if (typeAtt != null)
{
token.setType(typeAtt.type());
}
if (posIncAtt != null)
{
token.setPositionIncrement(posIncAtt.getPositionIncrement());
}
tokenised = token.toString();
}
return tokenised;
} catch (IOException e)
{
typeAtt = source.getAttribute(TypeAttribute.class);
}
PositionIncrementAttribute posIncAtt = null;
if (source.hasAttribute(PositionIncrementAttribute.class))
{
posIncAtt = source.getAttribute(PositionIncrementAttribute.class);
}
PackedTokenAttributeImpl token = new PackedTokenAttributeImpl();
token.setEmpty().copyBuffer(cta.buffer(), 0, cta.length());
token.setOffset(offsetAtt.startOffset(), offsetAtt.endOffset());
if (typeAtt != null)
{
token.setType(typeAtt.type());
}
if (posIncAtt != null)
{
token.setPositionIncrement(posIncAtt.getPositionIncrement());
throw new ParseException("IO" + e.getMessage());
}
return token.toString();
}
@Override
public Query getPrefixQuery(String field, String termStr) throws ParseException
{
@@ -5462,14 +5475,14 @@ public class Solr4QueryParser extends QueryParser implements QueryConstants
return analyzeMultitermTerm(field, part, getAnalyzer());
}
// Avoid FindBugs false positive (https://github.com/spotbugs/spotbugs/issues/756)
@SuppressWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
protected BytesRef analyzeMultitermTerm(String field, String part, Analyzer analyzerIn) {
if (analyzerIn == null) analyzerIn = getAnalyzer();
try
{
try (TokenStream source = analyzerIn.tokenStream(field, part)) {
source.reset();
TokenStream source = analyzerIn.tokenStream(field, part);
TermToBytesRefAttribute termAtt = source.getAttribute(TermToBytesRefAttribute.class);
if (!source.incrementToken())
@@ -5483,7 +5496,7 @@ public class Solr4QueryParser extends QueryParser implements QueryConstants
throw new RuntimeException("Error analyzing multiTerm term: " + part, e);
}
}
private boolean analyzeRangeTerms = true;
protected Query newRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) {
@@ -59,8 +59,8 @@ public class DateQuarterRouter implements DocRouter
// Avoid using Math.ceil with Integer
int countMonths = ((year * 12) + (month+1));
int grouping = 3;
int ceilGroupInstance = countMonths / grouping + ((countMonths % grouping == 0) ? 0 : 1);
int ceilGroupInstance = (countMonths + grouping - 1) / grouping;
return ceilGroupInstance % numShards == shardInstance;
}
@@ -68,19 +68,8 @@ public class TrackerState
private volatile boolean check = false;
// Handle Thread Safe operations
private volatile TrackerCyclesInteger trackerCycles;
class TrackerCyclesInteger
{
private AtomicInteger value = new AtomicInteger(0);
private void increase()
{
value.incrementAndGet();
}
private int getValue()
{
return value.get();
}
}
private volatile AtomicInteger trackerCycles;
private long timeToStopIndexing;
private long lastGoodChangeSetCommitTimeInIndex;
@@ -252,13 +241,13 @@ public class TrackerState
public int getTrackerCycles()
{
return this.trackerCycles.getValue();
return this.trackerCycles.get();
}
public synchronized void incrementTrackerCycles()
{
log.debug("incrementTrackerCycles from :" + trackerCycles);
this.trackerCycles.increase();
this.trackerCycles.incrementAndGet();
log.debug("incremented TrackerCycles to :" + trackerCycles);
}