mirror of https://github.com/apache/lucene.git
SOLR-8750: replace anonymous inner class for callable, Runnable etc
This commit is contained in:
parent
784e3e3863
commit
d67ec54932
|
@ -28,15 +28,11 @@ 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) {
|
||||
if( direction == FacetSortDirection.ASCENDING ){
|
||||
return a.getValue().compareTo(b.getValue());
|
||||
} else {
|
||||
return b.getValue().compareTo(a.getValue());
|
||||
}
|
||||
return (a, b) -> {
|
||||
if( direction == FacetSortDirection.ASCENDING ){
|
||||
return a.getValue().compareTo(b.getValue());
|
||||
} else {
|
||||
return b.getValue().compareTo(a.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -87,22 +87,19 @@ class GoLive {
|
|||
baseUrl = baseUrl.substring(0, lastPathIndex);
|
||||
final String mergeUrl = baseUrl;
|
||||
|
||||
Callable<Request> task = new Callable<Request>() {
|
||||
@Override
|
||||
public Request call() {
|
||||
Request req = new Request();
|
||||
LOG.info("Live merge " + dir.getPath() + " into " + mergeUrl);
|
||||
try (final HttpSolrClient client = new HttpSolrClient(mergeUrl)) {
|
||||
CoreAdminRequest.MergeIndexes mergeRequest = new CoreAdminRequest.MergeIndexes();
|
||||
mergeRequest.setCoreName(name);
|
||||
mergeRequest.setIndexDirs(Arrays.asList(dir.getPath().toString() + "/data/index"));
|
||||
mergeRequest.process(client);
|
||||
req.success = true;
|
||||
} catch (SolrServerException | IOException e) {
|
||||
req.e = e;
|
||||
}
|
||||
return req;
|
||||
Callable<Request> task = () -> {
|
||||
Request req = new Request();
|
||||
LOG.info("Live merge " + dir.getPath() + " into " + mergeUrl);
|
||||
try (final HttpSolrClient client = new HttpSolrClient(mergeUrl)) {
|
||||
CoreAdminRequest.MergeIndexes mergeRequest = new CoreAdminRequest.MergeIndexes();
|
||||
mergeRequest.setCoreName(name);
|
||||
mergeRequest.setIndexDirs(Arrays.asList(dir.getPath().toString() + "/data/index"));
|
||||
mergeRequest.process(client);
|
||||
req.success = true;
|
||||
} catch (SolrServerException | IOException e) {
|
||||
req.e = e;
|
||||
}
|
||||
return req;
|
||||
};
|
||||
pending.add(completionService.submit(task));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
Comparator c = new AlphaNumericComparator();
|
||||
return c.compare(slice1.getName(), slice2.getName());
|
||||
}
|
||||
Collections.sort(sorted, (slice1, slice2) -> {
|
||||
Comparator c = new AlphaNumericComparator();
|
||||
return c.compare(slice1.getName(), slice2.getName());
|
||||
});
|
||||
LOG.trace("Sorted slices: {}", sorted);
|
||||
return sorted;
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
logger.info("Creating new index schema for core {}", cd.getName());
|
||||
return IndexSchemaFactory.buildIndexSchema(cd.getSchemaName(), solrConfig);
|
||||
}
|
||||
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,
|
||||
|
|
|
@ -456,28 +456,25 @@ public class CoreContainer {
|
|||
solrCores.markCoreAsLoading(cd);
|
||||
}
|
||||
if (cd.isLoadOnStartup()) {
|
||||
futures.add(coreLoadExecutor.submit(new Callable<SolrCore>() {
|
||||
@Override
|
||||
public SolrCore call() throws Exception {
|
||||
SolrCore core;
|
||||
try {
|
||||
if (zkSys.getZkController() != null) {
|
||||
zkSys.getZkController().throwErrorIfReplicaReplaced(cd);
|
||||
}
|
||||
futures.add(coreLoadExecutor.submit(() -> {
|
||||
SolrCore core;
|
||||
try {
|
||||
if (zkSys.getZkController() != null) {
|
||||
zkSys.getZkController().throwErrorIfReplicaReplaced(cd);
|
||||
}
|
||||
|
||||
core = create(cd, false);
|
||||
} finally {
|
||||
if (asyncSolrCoreLoad) {
|
||||
solrCores.markCoreAsNotLoading(cd);
|
||||
}
|
||||
core = create(cd, false);
|
||||
} finally {
|
||||
if (asyncSolrCoreLoad) {
|
||||
solrCores.markCoreAsNotLoading(cd);
|
||||
}
|
||||
try {
|
||||
zkSys.registerInZk(core, true);
|
||||
} catch (RuntimeException e) {
|
||||
SolrException.log(log, "Error registering SolrCore", e);
|
||||
}
|
||||
return core;
|
||||
}
|
||||
try {
|
||||
zkSys.registerInZk(core, true);
|
||||
} catch (RuntimeException e) {
|
||||
SolrException.log(log, "Error registering SolrCore", e);
|
||||
}
|
||||
return core;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
latch.await();
|
||||
return null;
|
||||
}
|
||||
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,57 +1769,48 @@ 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 {
|
||||
try {
|
||||
newSearcher.warm(currSearcher);
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
future = searcherExecutor.submit(() -> {
|
||||
try {
|
||||
newSearcher.warm(currSearcher);
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
if (currSearcher == null) {
|
||||
future = searcherExecutor.submit(new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
try {
|
||||
for (SolrEventListener listener : firstSearcherListeners) {
|
||||
listener.newSearcher(newSearcher, null);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, null, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
future = searcherExecutor.submit(() -> {
|
||||
try {
|
||||
for (SolrEventListener listener : firstSearcherListeners) {
|
||||
listener.newSearcher(newSearcher, null);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, null, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
if (currSearcher != null) {
|
||||
future = searcherExecutor.submit(new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
try {
|
||||
for (SolrEventListener listener : newSearcherListeners) {
|
||||
listener.newSearcher(newSearcher, currSearcher);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, null, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
future = searcherExecutor.submit(() -> {
|
||||
try {
|
||||
for (SolrEventListener listener : newSearcherListeners) {
|
||||
listener.newSearcher(newSearcher, currSearcher);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, null, e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -127,22 +127,19 @@ class SolrCores {
|
|||
new DefaultSolrThreadFactory("coreCloseExecutor"));
|
||||
try {
|
||||
for (SolrCore core : coreList) {
|
||||
coreCloseExecutor.submit(new Callable<SolrCore>() {
|
||||
@Override
|
||||
public SolrCore call() throws Exception {
|
||||
MDCLoggingContext.setCore(core);
|
||||
try {
|
||||
core.close();
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, "Error shutting down core", e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
} finally {
|
||||
MDCLoggingContext.clear();
|
||||
coreCloseExecutor.submit(() -> {
|
||||
MDCLoggingContext.setCore(core);
|
||||
try {
|
||||
core.close();
|
||||
} catch (Throwable e) {
|
||||
SolrException.log(log, "Error shutting down core", e);
|
||||
if (e instanceof Error) {
|
||||
throw (Error) e;
|
||||
}
|
||||
return core;
|
||||
} finally {
|
||||
MDCLoggingContext.clear();
|
||||
}
|
||||
return core;
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
|
|
|
@ -73,19 +73,14 @@ 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() {
|
||||
CdcrReplicatorState state = statesQueue.poll();
|
||||
assert state != null; // Should never happen
|
||||
try {
|
||||
new CdcrReplicator(state, batchSize).run();
|
||||
} finally {
|
||||
statesQueue.offer(state);
|
||||
}
|
||||
replicatorsPool.execute(() -> {
|
||||
CdcrReplicatorState state = statesQueue.poll();
|
||||
assert state != null; // Should never happen
|
||||
try {
|
||||
new CdcrReplicator(state, batchSize).run();
|
||||
} finally {
|
||||
statesQueue.offer(state);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -284,17 +284,7 @@ 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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -160,64 +160,61 @@ 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) {
|
||||
srsp.setNodeName(sreq.nodeName);
|
||||
}
|
||||
srsp.setShardRequest(sreq);
|
||||
srsp.setShard(shard);
|
||||
SimpleSolrResponse ssr = new SimpleSolrResponse();
|
||||
srsp.setSolrResponse(ssr);
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
try {
|
||||
params.remove(CommonParams.WT); // use default (currently javabin)
|
||||
params.remove(CommonParams.VERSION);
|
||||
|
||||
QueryRequest req = makeQueryRequest(sreq, params, shard);
|
||||
req.setMethod(SolrRequest.METHOD.POST);
|
||||
|
||||
// no need to set the response parser as binary is the default
|
||||
// req.setResponseParser(new BinaryResponseParser());
|
||||
|
||||
// if there are no shards available for a slice, urls.size()==0
|
||||
if (urls.size()==0) {
|
||||
// TODO: what's the right error code here? We should use the same thing when
|
||||
// all of the servers for a shard are down.
|
||||
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "no servers hosting shard: " + shard);
|
||||
}
|
||||
|
||||
if (urls.size() <= 1) {
|
||||
String url = urls.get(0);
|
||||
srsp.setShardAddress(url);
|
||||
try (SolrClient client = new HttpSolrClient(url, httpClient)) {
|
||||
ssr.nl = client.request(req);
|
||||
}
|
||||
} else {
|
||||
LBHttpSolrClient.Rsp rsp = httpShardHandlerFactory.makeLoadBalancedRequest(req, urls);
|
||||
ssr.nl = rsp.getResponse();
|
||||
srsp.setShardAddress(rsp.getServer());
|
||||
}
|
||||
}
|
||||
catch( ConnectException cex ) {
|
||||
srsp.setException(cex); //????
|
||||
} catch (Exception th) {
|
||||
srsp.setException(th);
|
||||
if (th instanceof SolrException) {
|
||||
srsp.setResponseCode(((SolrException)th).code());
|
||||
} else {
|
||||
srsp.setResponseCode(-1);
|
||||
}
|
||||
}
|
||||
|
||||
ssr.elapsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
|
||||
|
||||
return transfomResponse(sreq, srsp, shard);
|
||||
ShardResponse srsp = new ShardResponse();
|
||||
if (sreq.nodeName != null) {
|
||||
srsp.setNodeName(sreq.nodeName);
|
||||
}
|
||||
srsp.setShardRequest(sreq);
|
||||
srsp.setShard(shard);
|
||||
SimpleSolrResponse ssr = new SimpleSolrResponse();
|
||||
srsp.setSolrResponse(ssr);
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
try {
|
||||
params.remove(CommonParams.WT); // use default (currently javabin)
|
||||
params.remove(CommonParams.VERSION);
|
||||
|
||||
QueryRequest req = makeQueryRequest(sreq, params, shard);
|
||||
req.setMethod(SolrRequest.METHOD.POST);
|
||||
|
||||
// no need to set the response parser as binary is the default
|
||||
// req.setResponseParser(new BinaryResponseParser());
|
||||
|
||||
// if there are no shards available for a slice, urls.size()==0
|
||||
if (urls.size()==0) {
|
||||
// TODO: what's the right error code here? We should use the same thing when
|
||||
// all of the servers for a shard are down.
|
||||
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "no servers hosting shard: " + shard);
|
||||
}
|
||||
|
||||
if (urls.size() <= 1) {
|
||||
String url = urls.get(0);
|
||||
srsp.setShardAddress(url);
|
||||
try (SolrClient client = new HttpSolrClient(url, httpClient)) {
|
||||
ssr.nl = client.request(req);
|
||||
}
|
||||
} else {
|
||||
LBHttpSolrClient.Rsp rsp = httpShardHandlerFactory.makeLoadBalancedRequest(req, urls);
|
||||
ssr.nl = rsp.getResponse();
|
||||
srsp.setShardAddress(rsp.getServer());
|
||||
}
|
||||
}
|
||||
catch( ConnectException cex ) {
|
||||
srsp.setException(cex); //????
|
||||
} catch (Exception th) {
|
||||
srsp.setException(th);
|
||||
if (th instanceof SolrException) {
|
||||
srsp.setResponseCode(((SolrException)th).code());
|
||||
} else {
|
||||
srsp.setResponseCode(-1);
|
||||
}
|
||||
}
|
||||
|
||||
ssr.elapsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
|
||||
|
||||
return transfomResponse(sreq, srsp, shard);
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
|
@ -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 {
|
||||
segFacet.countTerms();
|
||||
return segFacet;
|
||||
}
|
||||
Callable<SegFacet> task = () -> {
|
||||
segFacet.countTerms();
|
||||
return segFacet;
|
||||
};
|
||||
|
||||
// TODO: if limiting threads, submit by largest segment first?
|
||||
|
|
|
@ -662,26 +662,23 @@ 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 {
|
||||
try {
|
||||
NamedList<Object> result = new SimpleOrderedMap<>();
|
||||
if(termList != null) {
|
||||
List<String> terms = StrUtils.splitSmart(termList, ",", true);
|
||||
result.add(key, getListedTermCounts(facetValue, parsed, terms));
|
||||
} else {
|
||||
result.add(key, getTermCounts(facetValue, parsed));
|
||||
}
|
||||
return result;
|
||||
} catch (SolrException se) {
|
||||
throw se;
|
||||
} catch (Exception e) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR,
|
||||
"Exception during facet.field: " + facetValue, e);
|
||||
} finally {
|
||||
semaphore.release();
|
||||
Callable<NamedList> callable = () -> {
|
||||
try {
|
||||
NamedList<Object> result = new SimpleOrderedMap<>();
|
||||
if(termList != null) {
|
||||
List<String> terms = StrUtils.splitSmart(termList, ",", true);
|
||||
result.add(key, getListedTermCounts(facetValue, parsed, terms));
|
||||
} else {
|
||||
result.add(key, getTermCounts(facetValue, parsed));
|
||||
}
|
||||
return result;
|
||||
} catch (SolrException se) {
|
||||
throw se;
|
||||
} catch (Exception e) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR,
|
||||
"Exception during facet.field: " + facetValue, e);
|
||||
} finally {
|
||||
semaphore.release();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
doRequest(req);
|
||||
return null;
|
||||
}
|
||||
|
||||
pending.add(completionService.submit(() -> {
|
||||
doRequest(req);
|
||||
return null;
|
||||
}));
|
||||
} else {
|
||||
doRequest(req);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
assertBlockU(msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
rez.add(() -> {
|
||||
assertBlockU(msg);
|
||||
return null;
|
||||
});
|
||||
if (rarely()) {
|
||||
rez.add(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() {
|
||||
assertBlockU(commit());
|
||||
return null;
|
||||
}
|
||||
|
||||
rez.add(() -> {
|
||||
assertBlockU(commit());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
assertU(commit("softCommit","false"));
|
||||
return null;
|
||||
}
|
||||
doUpdateTest(() -> {
|
||||
assertU(commit("softCommit","false"));
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -97,34 +97,28 @@ public class FieldComparator implements StreamComparator {
|
|||
*/
|
||||
private void assignComparator(){
|
||||
if(ComparatorOrder.DESCENDING == order){
|
||||
comparator = new ComparatorLambda() {
|
||||
@Override
|
||||
public int compare(Tuple leftTuple, Tuple rightTuple) {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftFieldName);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightFieldName);
|
||||
|
||||
if(leftComp == rightComp){ return 0; } // if both null then they are equal. if both are same ref then are equal
|
||||
if(null == leftComp){ return 1; }
|
||||
if(null == rightComp){ return -1; }
|
||||
|
||||
return rightComp.compareTo(leftComp);
|
||||
}
|
||||
comparator = (leftTuple, rightTuple) -> {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftFieldName);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightFieldName);
|
||||
|
||||
if(leftComp == rightComp){ return 0; } // if both null then they are equal. if both are same ref then are equal
|
||||
if(null == leftComp){ return 1; }
|
||||
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) {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftFieldName);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightFieldName);
|
||||
|
||||
if(leftComp == rightComp){ return 0; } // if both null then they are equal. if both are same ref then are equal
|
||||
if(null == leftComp){ return -1; }
|
||||
if(null == rightComp){ return 1; }
|
||||
|
||||
return leftComp.compareTo(rightComp);
|
||||
}
|
||||
comparator = (leftTuple, rightTuple) -> {
|
||||
Comparable leftComp = (Comparable)leftTuple.get(leftFieldName);
|
||||
Comparable rightComp = (Comparable)rightTuple.get(rightFieldName);
|
||||
|
||||
if(leftComp == rightComp){ return 0; } // if both null then they are equal. if both are same ref then are equal
|
||||
if(null == leftComp){ return -1; }
|
||||
if(null == rightComp){ return 1; }
|
||||
|
||||
return leftComp.compareTo(rightComp);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue