SOLR-8750: replace anonymous inner class for callable, Runnable etc

This commit is contained in:
Noble Paul 2016-04-05 22:45:36 +05:30
parent 784e3e3863
commit d67ec54932
26 changed files with 210 additions and 370 deletions

View File

@ -28,16 +28,12 @@ public abstract class Expression {
public abstract Comparable getValue();
public Comparator<Expression> comparator(final FacetSortDirection direction) {
return new Comparator<Expression>(){
@SuppressWarnings("unchecked")
@Override
public int compare(Expression a, Expression b) {
return (a, b) -> {
if( direction == FacetSortDirection.ASCENDING ){
return a.getValue().compareTo(b.getValue());
} else {
return b.getValue().compareTo(a.getValue());
}
}
};
}
}

View File

@ -87,9 +87,7 @@ class GoLive {
baseUrl = baseUrl.substring(0, lastPathIndex);
final String mergeUrl = baseUrl;
Callable<Request> task = new Callable<Request>() {
@Override
public Request call() {
Callable<Request> task = () -> {
Request req = new Request();
LOG.info("Live merge " + dir.getPath() + " into " + mergeUrl);
try (final HttpSolrClient client = new HttpSolrClient(mergeUrl)) {
@ -102,7 +100,6 @@ class GoLive {
req.e = e;
}
return req;
}
};
pending.add(completionService.submit(task));
}

View File

@ -1188,12 +1188,7 @@ public class MapReduceIndexerTool extends Configured implements Tool {
}
// use alphanumeric sort (rather than lexicographical sort) to properly handle more than 99999 shards
Arrays.sort(dirs, new Comparator<FileStatus>() {
@Override
public int compare(FileStatus f1, FileStatus f2) {
return new AlphaNumericComparator().compare(f1.getPath().getName(), f2.getPath().getName());
}
});
Arrays.sort(dirs, (f1, f2) -> new AlphaNumericComparator().compare(f1.getPath().getName(), f2.getPath().getName()));
return dirs;
}

View File

@ -114,12 +114,9 @@ final class ZooKeeperInspector {
public List<Slice> getSortedSlices(Collection<Slice> slices) {
List<Slice> sorted = new ArrayList(slices);
Collections.sort(sorted, new Comparator<Slice>() {
@Override
public int compare(Slice slice1, Slice slice2) {
Collections.sort(sorted, (slice1, slice2) -> {
Comparator c = new AlphaNumericComparator();
return c.compare(slice1.getName(), slice2.getName());
}
});
LOG.trace("Sorted slices: {}", sorted);
return sorted;

View File

@ -79,12 +79,7 @@ public class SolrMorphlineZkAvroTest extends AbstractSolrMorphlineZkTestBase {
assertEquals(2104, collector.getRecords().size());
assertEquals(collector.getRecords().size(), rsp.getResults().size());
Collections.sort(collector.getRecords(), new Comparator<Record>() {
@Override
public int compare(Record r1, Record r2) {
return r1.get("id").toString().compareTo(r2.get("id").toString());
}
});
Collections.sort(collector.getRecords(), (r1, r2) -> r1.get("id").toString().compareTo(r2.get("id").toString()));
// fetch test input data and sort like solr result set
List<GenericData.Record> records = new ArrayList();
@ -94,12 +89,7 @@ public class SolrMorphlineZkAvroTest extends AbstractSolrMorphlineZkTestBase {
records.add(expected);
}
assertEquals(collector.getRecords().size(), records.size());
Collections.sort(records, new Comparator<GenericData.Record>() {
@Override
public int compare(GenericData.Record r1, GenericData.Record r2) {
return r1.get("id").toString().compareTo(r2.get("id").toString());
}
});
Collections.sort(records, (r1, r2) -> r1.get("id").toString().compareTo(r2.get("id").toString()));
Object lastId = null;
for (int i = 0; i < records.size(); i++) {

View File

@ -248,13 +248,7 @@ public class OverseerAutoReplicaFailoverThread implements Runnable, Closeable {
log.debug("submit call to {}", createUrl);
MDC.put("OverseerAutoReplicaFailoverThread.createUrl", createUrl);
try {
updateExecutor.submit(new Callable<Boolean>() {
@Override
public Boolean call() {
return createSolrCore(collection, createUrl, dataDir, ulogDir, coreNodeName, coreName);
}
});
updateExecutor.submit(() -> createSolrCore(collection, createUrl, dataDir, ulogDir, coreNodeName, coreName));
} finally {
MDC.remove("OverseerAutoReplicaFailoverThread.createUrl");
}

View File

@ -204,12 +204,9 @@ public abstract class ConfigSetService {
if (Files.exists(schemaFile)) {
try {
String cachedName = cacheName(schemaFile);
return schemaCache.get(cachedName, new Callable<IndexSchema>() {
@Override
public IndexSchema call() throws Exception {
return schemaCache.get(cachedName, () -> {
logger.info("Creating new index schema for core {}", cd.getName());
return IndexSchemaFactory.buildIndexSchema(cd.getSchemaName(), solrConfig);
}
});
} catch (ExecutionException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,

View File

@ -456,9 +456,7 @@ public class CoreContainer {
solrCores.markCoreAsLoading(cd);
}
if (cd.isLoadOnStartup()) {
futures.add(coreLoadExecutor.submit(new Callable<SolrCore>() {
@Override
public SolrCore call() throws Exception {
futures.add(coreLoadExecutor.submit(() -> {
SolrCore core;
try {
if (zkSys.getZkController() != null) {
@ -477,7 +475,6 @@ public class CoreContainer {
SolrException.log(log, "Error registering SolrCore", e);
}
return core;
}
}));
}
}

View File

@ -318,12 +318,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
FileSystem fileSystem = null;
try {
// no need to close the fs, the cache will do it
fileSystem = tmpFsCache.get(path, new Callable<FileSystem>() {
@Override
public FileSystem call() throws IOException {
return FileSystem.get(hdfsDirPath.toUri(), conf);
}
});
fileSystem = tmpFsCache.get(path, () -> FileSystem.get(hdfsDirPath.toUri(), conf));
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
@ -351,12 +346,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
try {
// no need to close the fs, the cache will do it
fileSystem = tmpFsCache.get(cacheValue.path, new Callable<FileSystem>() {
@Override
public FileSystem call() throws IOException {
return FileSystem.get(new Path(cacheValue.path).toUri(), conf);
}
});
fileSystem = tmpFsCache.get(cacheValue.path, () -> FileSystem.get(new Path(cacheValue.path).toUri(), conf));
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
@ -487,12 +477,7 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
final Configuration conf = getConf();
FileSystem fileSystem = null;
try {
fileSystem = tmpFsCache.get(dataDir, new Callable<FileSystem>() {
@Override
public FileSystem call() throws IOException {
return FileSystem.get(dataDirPath.toUri(), conf);
}
});
fileSystem = tmpFsCache.get(dataDir, () -> FileSystem.get(dataDirPath.toUri(), conf));
} catch (ExecutionException e) {
throw new RuntimeException(e);
}

View File

@ -735,12 +735,9 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
// cause the executor to stall so firstSearcher events won't fire
// until after inform() has been called for all components.
// searchExecutor must be single-threaded for this to work
searcherExecutor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
searcherExecutor.submit(() -> {
latch.await();
return null;
}
});
this.updateHandler = initUpdateHandler(updateHandler);
@ -854,14 +851,7 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
if (iwRef != null) {
final IndexWriter iw = iwRef.get();
final SolrCore core = this;
newReaderCreator = new Callable<DirectoryReader>() {
// this is used during a core reload
@Override
public DirectoryReader call() throws Exception {
return indexReaderFactory.newReader(iw, core);
}
};
newReaderCreator = () -> indexReaderFactory.newReader(iw, core);
}
}
@ -1779,9 +1769,7 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
// warm the new searcher based on the current searcher.
// should this go before the other event handlers or after?
if (currSearcher != null) {
future = searcherExecutor.submit(new Callable() {
@Override
public Object call() throws Exception {
future = searcherExecutor.submit(() -> {
try {
newSearcher.warm(currSearcher);
} catch (Throwable e) {
@ -1791,14 +1779,11 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
}
}
return null;
}
});
}
if (currSearcher == null) {
future = searcherExecutor.submit(new Callable() {
@Override
public Object call() throws Exception {
future = searcherExecutor.submit(() -> {
try {
for (SolrEventListener listener : firstSearcherListeners) {
listener.newSearcher(newSearcher, null);
@ -1810,14 +1795,11 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
}
}
return null;
}
});
}
if (currSearcher != null) {
future = searcherExecutor.submit(new Callable() {
@Override
public Object call() throws Exception {
future = searcherExecutor.submit(() -> {
try {
for (SolrEventListener listener : newSearcherListeners) {
listener.newSearcher(newSearcher, currSearcher);
@ -1829,7 +1811,6 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
}
}
return null;
}
});
}

View File

@ -127,9 +127,7 @@ class SolrCores {
new DefaultSolrThreadFactory("coreCloseExecutor"));
try {
for (SolrCore core : coreList) {
coreCloseExecutor.submit(new Callable<SolrCore>() {
@Override
public SolrCore call() throws Exception {
coreCloseExecutor.submit(() -> {
MDCLoggingContext.setCore(core);
try {
core.close();
@ -142,7 +140,6 @@ class SolrCores {
MDCLoggingContext.clear();
}
return core;
}
});
}
} finally {

View File

@ -73,10 +73,7 @@ class CdcrReplicatorScheduler {
for (int i = 0; i < nCandidates; i++) {
// a thread that poll one state from the queue, execute the replication task, and push back
// the state in the queue when the task is completed
replicatorsPool.execute(new Runnable() {
@Override
public void run() {
replicatorsPool.execute(() -> {
CdcrReplicatorState state = statesQueue.poll();
assert state != null; // Should never happen
try {
@ -84,8 +81,6 @@ class CdcrReplicatorScheduler {
} finally {
statesQueue.offer(state);
}
}
});
}

View File

@ -285,16 +285,6 @@ public class MoreLikeThisHandler extends RequestHandlerBase
public Term term;
public float boost;
public static Comparator<InterestingTerm> BOOST_ORDER = new Comparator<InterestingTerm>() {
@Override
public int compare(InterestingTerm t1, InterestingTerm t2) {
float d = t1.boost - t2.boost;
if( d == 0 ) {
return 0;
}
return (d>0)?1:-1;
}
};
}
/**

View File

@ -160,9 +160,7 @@ public class HttpShardHandler extends ShardHandler {
// do this outside of the callable for thread safety reasons
final List<String> urls = getURLs(shard, preferredHostAddress);
Callable<ShardResponse> task = new Callable<ShardResponse>() {
@Override
public ShardResponse call() throws Exception {
Callable<ShardResponse> task = () -> {
ShardResponse srsp = new ShardResponse();
if (sreq.nodeName != null) {
@ -217,7 +215,6 @@ public class HttpShardHandler extends ShardHandler {
ssr.elapsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
return transfomResponse(sreq, srsp, shard);
}
};
try {

View File

@ -103,12 +103,9 @@ class PerSegmentSingleValuedFaceting {
for (final LeafReaderContext leave : leaves) {
final SegFacet segFacet = new SegFacet(leave);
Callable<SegFacet> task = new Callable<SegFacet>() {
@Override
public SegFacet call() throws Exception {
Callable<SegFacet> task = () -> {
segFacet.countTerms();
return segFacet;
}
};
// TODO: if limiting threads, submit by largest segment first?

View File

@ -662,9 +662,7 @@ public class SimpleFacets {
final String termList = localParams == null ? null : localParams.get(CommonParams.TERMS);
final String key = parsed.key;
final String facetValue = parsed.facetValue;
Callable<NamedList> callable = new Callable<NamedList>() {
@Override
public NamedList call() throws Exception {
Callable<NamedList> callable = () -> {
try {
NamedList<Object> result = new SimpleOrderedMap<>();
if(termList != null) {
@ -682,7 +680,6 @@ public class SimpleFacets {
} finally {
semaphore.release();
}
}
};
RunnableFuture<NamedList> runnableFuture = new FutureTask<>(callable);

View File

@ -407,12 +407,7 @@ public abstract class AbstractSpatialFieldType<T extends SpatialStrategy> extend
*/
public T getStrategy(final String fieldName) {
try {
return fieldStrategyCache.get(fieldName, new Callable<T>() {
@Override
public T call() throws Exception {
return newSpatialStrategy(fieldName);
}
});
return fieldStrategyCache.get(fieldName, () -> newSpatialStrategy(fieldName));
} catch (ExecutionException e) {
throw Throwables.propagate(e.getCause());
}

View File

@ -279,14 +279,9 @@ public class SolrCmdDistributor {
// a commit using ConncurrentUpdateSolrServer is not async,
// so we make it async to prevent commits from happening
// serially across multiple nodes
pending.add(completionService.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
pending.add(completionService.submit(() -> {
doRequest(req);
return null;
}
}));
} else {
doRequest(req);

View File

@ -197,12 +197,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
}
};
UpdateLog.testing_logReplayFinishHook = new Runnable() {
@Override
public void run() {
logReplayFinish.release();
}
};
UpdateLog.testing_logReplayFinishHook = logReplayFinish::release;
SolrQueryRequest req = req();

View File

@ -161,7 +161,7 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 {
}
};
UpdateLog.testing_logReplayFinishHook = () -> logReplayFinish.release();
UpdateLog.testing_logReplayFinishHook = logReplayFinish::release;
clearIndex();
@ -257,7 +257,7 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 {
}
};
UpdateLog.testing_logReplayFinishHook = () -> logReplayFinish.release();
UpdateLog.testing_logReplayFinishHook = logReplayFinish::release;
SolrQueryRequest req = req();
@ -412,7 +412,7 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 {
}
};
UpdateLog.testing_logReplayFinishHook = () -> logReplayFinish.release();
UpdateLog.testing_logReplayFinishHook = logReplayFinish::release;
SolrQueryRequest req = req();
@ -722,12 +722,7 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 {
}
};
UpdateLog.testing_logReplayFinishHook = new Runnable() {
@Override
public void run() {
logReplayFinish.release();
}
};
UpdateLog.testing_logReplayFinishHook = logReplayFinish::release;
clearIndex();

View File

@ -575,22 +575,14 @@ public class AddBlockUpdateTest extends SolrTestCaseJ4 {
for (Document block : blocks) {
final String msg = block.asXML();
if (msg.length() > 0) {
rez.add(new Callable<Void>() {
@Override
public Void call() {
rez.add(() -> {
assertBlockU(msg);
return null;
}
});
if (rarely()) {
rez.add(new Callable<Void>() {
@Override
public Void call() {
rez.add(() -> {
assertBlockU(commit());
return null;
}
});
}
}

View File

@ -37,20 +37,12 @@ public class TestUpdate extends SolrTestCaseJ4 {
// Test both by running the same test with and without commits
// do without commits
doUpdateTest(new Callable() {
@Override
public Object call() throws Exception {
return null;
}
});
doUpdateTest(() -> null);
// do with commits
doUpdateTest(new Callable() {
@Override
public Object call() throws Exception {
doUpdateTest(() -> {
assertU(commit("softCommit","false"));
return null;
}
});

View File

@ -603,12 +603,7 @@ public class CloudSolrClient extends SolrClient {
final LBHttpSolrClient.Req lbRequest = entry.getValue();
try {
MDC.put("CloudSolrClient.url", url);
responseFutures.put(url, threadPool.submit(new Callable<NamedList<?>>() {
@Override
public NamedList<?> call() throws Exception {
return lbClient.request(lbRequest).getResponse();
}
}));
responseFutures.put(url, threadPool.submit(() -> lbClient.request(lbRequest).getResponse()));
} finally {
MDC.remove("CloudSolrClient.url");
}

View File

@ -278,12 +278,7 @@ public class HttpSolrClient extends SolrClient {
ExecutorService pool = ExecutorUtil.newMDCAwareFixedThreadPool(1, new SolrjNamedThreadFactory("httpUriRequest"));
try {
MDC.put("HttpSolrClient.url", baseUrl);
mrr.future = pool.submit(new Callable<NamedList<Object>>(){
@Override
public NamedList<Object> call() throws Exception {
return executeMethod(method, processor);
}});
mrr.future = pool.submit(() -> executeMethod(method, processor));
} finally {
pool.shutdown();

View File

@ -97,9 +97,7 @@ public class FieldComparator implements StreamComparator {
*/
private void assignComparator(){
if(ComparatorOrder.DESCENDING == order){
comparator = new ComparatorLambda() {
@Override
public int compare(Tuple leftTuple, Tuple rightTuple) {
comparator = (leftTuple, rightTuple) -> {
Comparable leftComp = (Comparable)leftTuple.get(leftFieldName);
Comparable rightComp = (Comparable)rightTuple.get(rightFieldName);
@ -108,14 +106,11 @@ public class FieldComparator implements StreamComparator {
if(null == rightComp){ return -1; }
return rightComp.compareTo(leftComp);
}
};
}
else{
// See above for black magic reasoning.
comparator = new ComparatorLambda() {
@Override
public int compare(Tuple leftTuple, Tuple rightTuple) {
comparator = (leftTuple, rightTuple) -> {
Comparable leftComp = (Comparable)leftTuple.get(leftFieldName);
Comparable rightComp = (Comparable)rightTuple.get(rightFieldName);
@ -124,7 +119,6 @@ public class FieldComparator implements StreamComparator {
if(null == rightComp){ return 1; }
return leftComp.compareTo(rightComp);
}
};
}
}

View File

@ -206,12 +206,7 @@ public class MiniSolrCloudCluster {
List<Callable<JettySolrRunner>> startups = new ArrayList<>(numServers);
for (int i = 0; i < numServers; ++i) {
startups.add(new Callable<JettySolrRunner>() {
@Override
public JettySolrRunner call() throws Exception {
return startJettySolrRunner(newNodeName(), jettyConfig.context, jettyConfig);
}
});
startups.add(() -> startJettySolrRunner(newNodeName(), jettyConfig.context, jettyConfig));
}
Collection<Future<JettySolrRunner>> futures = executor.invokeAll(startups);
@ -424,12 +419,7 @@ public class MiniSolrCloudCluster {
solrClient.close();
List<Callable<JettySolrRunner>> shutdowns = new ArrayList<>(jettys.size());
for (final JettySolrRunner jetty : jettys) {
shutdowns.add(new Callable<JettySolrRunner>() {
@Override
public JettySolrRunner call() throws Exception {
return stopJettySolrRunner(jetty);
}
});
shutdowns.add(() -> stopJettySolrRunner(jetty));
}
jettys.clear();
Collection<Future<JettySolrRunner>> futures = executor.invokeAll(shutdowns);