Search in sources :

Example 46 with ConcurrentLinkedQueue

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);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 47 with ConcurrentLinkedQueue

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;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 48 with ConcurrentLinkedQueue

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;
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 49 with ConcurrentLinkedQueue

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();
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 50 with ConcurrentLinkedQueue

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) {
    }
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Aggregations

ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)236 Test (org.junit.Test)102 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)56 Watermark (org.apache.flink.streaming.api.watermark.Watermark)52 KeyedOneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness)43 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)40 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)40 CountDownLatch (java.util.concurrent.CountDownLatch)37 ArrayList (java.util.ArrayList)31 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)28 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)18 ReducingStateDescriptor (org.apache.flink.api.common.state.ReducingStateDescriptor)17 IOException (java.io.IOException)15 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)15 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)14 ExecutionException (java.util.concurrent.ExecutionException)13 ExecutorService (java.util.concurrent.ExecutorService)13 Map (java.util.Map)12 OperatorStateHandles (org.apache.flink.streaming.runtime.tasks.OperatorStateHandles)12 Iterator (java.util.Iterator)11