use of java.util.concurrent.ConcurrentLinkedQueue in project elasticsearch by elastic.
the class TransportMultiSearchAction method doExecute.
@Override
protected void doExecute(MultiSearchRequest request, ActionListener<MultiSearchResponse> listener) {
ClusterState clusterState = clusterService.state();
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
int maxConcurrentSearches = request.maxConcurrentSearchRequests();
if (maxConcurrentSearches == 0) {
maxConcurrentSearches = defaultMaxConcurrentSearches(availableProcessors, clusterState);
}
Queue<SearchRequestSlot> searchRequestSlots = new ConcurrentLinkedQueue<>();
for (int i = 0; i < request.requests().size(); i++) {
SearchRequest searchRequest = request.requests().get(i);
searchRequestSlots.add(new SearchRequestSlot(searchRequest, i));
}
int numRequests = request.requests().size();
final AtomicArray<MultiSearchResponse.Item> responses = new AtomicArray<>(numRequests);
final AtomicInteger responseCounter = new AtomicInteger(numRequests);
int numConcurrentSearches = Math.min(numRequests, maxConcurrentSearches);
for (int i = 0; i < numConcurrentSearches; i++) {
executeSearch(searchRequestSlots, responses, responseCounter, listener);
}
}
use of java.util.concurrent.ConcurrentLinkedQueue in project tinker by Tencent.
the class FileUtil method findMatchFileOrMatchFileDirectory.
/**
* find match file or match file directory
*
* @param sourceDirectory
* @param fileSuffix
* @param somethingAppendToRear
* @param isFindMatchFile
* @param includeHidden
* @return List<String>
*/
private static List<String> findMatchFileOrMatchFileDirectory(String sourceDirectory, String fileSuffix, String somethingAppendToRear, boolean isFindMatchFile, boolean includeHidden) {
fileSuffix = StringUtil.nullToBlank(fileSuffix);
somethingAppendToRear = StringUtil.nullToBlank(somethingAppendToRear);
List<String> list = new ArrayList<String>();
File sourceDirectoryFile = new File(sourceDirectory);
Queue<File> queue = new ConcurrentLinkedQueue<File>();
queue.add(sourceDirectoryFile);
while (!queue.isEmpty()) {
File file = queue.poll();
boolean result = false;
if (!file.isHidden() || includeHidden) {
result = true;
}
if (result) {
if (file.isDirectory()) {
File[] fileArray = file.listFiles();
if (fileArray != null) {
queue.addAll(Arrays.asList(fileArray));
}
} else if (file.isFile()) {
if (file.getName().toLowerCase().endsWith(fileSuffix.toLowerCase())) {
if (isFindMatchFile) {
list.add(file.getAbsolutePath() + somethingAppendToRear);
} else {
String parentPath = file.getParent();
parentPath = parentPath + somethingAppendToRear;
if (!list.contains(parentPath)) {
list.add(parentPath);
}
}
}
}
}
}
return list;
}
use of java.util.concurrent.ConcurrentLinkedQueue in project tinker by Tencent.
the class FileUtil method isHasFile.
/**
* is has file from directory
*
* @param directory
* @param fileSuffix
* @return boolean
*/
public static boolean isHasFile(String directory, String fileSuffix) {
boolean result = false;
File directoryFile = new File(directory);
Queue<File> queue = new ConcurrentLinkedQueue<File>();
queue.add(directoryFile);
while (!queue.isEmpty()) {
File file = queue.poll();
if (file.isDirectory()) {
File[] fileArray = file.listFiles();
if (fileArray != null) {
queue.addAll(Arrays.asList(fileArray));
}
} else if (file.isFile()) {
if (file.getName().toLowerCase().endsWith(fileSuffix.toLowerCase())) {
result = true;
break;
}
}
}
return result;
}
use of java.util.concurrent.ConcurrentLinkedQueue in project tinker by Tencent.
the class FileUtil method deleteAllFile.
/**
* delete all file
*
* @param directory
*/
public static void deleteAllFile(String directory) {
List<File> fileList = new ArrayList<File>();
File directoryFile = new File(directory);
Queue<File> queue = new ConcurrentLinkedQueue<File>();
queue.add(directoryFile);
while (!queue.isEmpty()) {
File file = queue.poll();
if (file.isDirectory()) {
File[] fileArray = file.listFiles();
if (fileArray != null) {
queue.addAll(Arrays.asList(fileArray));
}
}
fileList.add(file);
}
for (int i = fileList.size() - 1; i >= 0; i--) {
fileList.get(i).delete();
}
}
use of java.util.concurrent.ConcurrentLinkedQueue in project mapdb by jankotek.
the class ConcurrentLinkedQueueTest method testAddAll2.
/**
* addAll of a collection with null elements throws NPE
*/
public void testAddAll2() {
ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
try {
q.addAll(Arrays.asList(new Integer[SIZE]));
shouldThrow();
} catch (NullPointerException success) {
}
}
Aggregations