Java 类java.util.concurrent.BlockingDeque 实例源码

项目:guava-mock    文件:ArbitraryInstancesTest.java   
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class, BlockingDeque.class, PriorityBlockingQueue.class,
      DelayQueue.class, SynchronousQueue.class,
      ConcurrentMap.class, ConcurrentNavigableMap.class,
      AtomicReference.class, AtomicBoolean.class,
      AtomicInteger.class, AtomicLong.class, AtomicDouble.class);
}
项目:X4J    文件:DynamicParsers.java   
private <T> Collection<T> instantiateCollectionFromInterface(Class<? extends T> collectionType) {
    if (List.class.isAssignableFrom(collectionType)) {
        return new ArrayList<T>();
    } else if (SortedSet.class.isAssignableFrom(collectionType)) {
        return new TreeSet<T>();
    } else if (Set.class.isAssignableFrom(collectionType)) {
        return new LinkedHashSet<T>();
    } else if (BlockingDeque.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Deque.class.isAssignableFrom(collectionType)) {
        return new ArrayDeque<T>();
    } else if (BlockingQueue.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Queue.class.isAssignableFrom(collectionType)) {
        return new LinkedList<T>();
    }
    return new ArrayList<T>();
}
项目:X4J    文件:DynamicParsers.java   
private <T> Collection<T> instantiateCollectionFromInterface(Class<? extends T> collectionType) {
    if (List.class.isAssignableFrom(collectionType)) {
        return new ArrayList<T>();
    } else if (SortedSet.class.isAssignableFrom(collectionType)) {
        return new TreeSet<T>();
    } else if (Set.class.isAssignableFrom(collectionType)) {
        return new LinkedHashSet<T>();
    } else if (BlockingDeque.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Deque.class.isAssignableFrom(collectionType)) {
        return new ArrayDeque<T>();
    } else if (BlockingQueue.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Queue.class.isAssignableFrom(collectionType)) {
        return new LinkedList<T>();
    }
    return new ArrayList<T>();
}
项目:openjdk-jdk10    文件:LinkedBlockingDequeTest.java   
/**
 * takeFirst() blocks interruptibly when empty
 */
public void testTakeFirstFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadBlocks(t, Thread.State.WAITING);
    t.interrupt();
    awaitTermination(t);
}
项目:openjdk-jdk10    文件:LinkedBlockingDequeTest.java   
/**
 * takeLast() blocks interruptibly when empty
 */
public void testTakeLastFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadBlocks(t, Thread.State.WAITING);
    t.interrupt();
    awaitTermination(t);
}
项目:googles-monorepo-demo    文件:ArbitraryInstancesTest.java   
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class, BlockingDeque.class, PriorityBlockingQueue.class,
      DelayQueue.class, SynchronousQueue.class,
      ConcurrentMap.class, ConcurrentNavigableMap.class,
      AtomicReference.class, AtomicBoolean.class,
      AtomicInteger.class, AtomicLong.class, AtomicDouble.class);
}
项目:diorite-configs-java8    文件:YamlCollectionCreator.java   
static void putAllCollections(Map<Class<?>, IntFunction<?>> map, Map<Class<?>, Function<?, ?>> unmodMap)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
项目:openjdk9    文件:LinkedBlockingDequeTest.java   
/**
 * takeFirst() blocks interruptibly when empty
 */
public void testTakeFirstFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
项目:openjdk9    文件:LinkedBlockingDequeTest.java   
/**
 * takeLast() blocks interruptibly when empty
 */
public void testTakeLastFromEmptyBlocksInterruptibly() {
    final BlockingDeque q = new LinkedBlockingDeque();
    final CountDownLatch threadStarted = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            threadStarted.countDown();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    await(threadStarted);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
项目:BeaconFinder    文件:BluetoothScannerService.java   
private void finishScanningCycle() {
    for (Map.Entry<String, BlockingDeque<Integer>> entry : mScanHistory.entrySet()) {
        final BlockingDeque<Integer> values = entry.getValue();


        if (values.size() < BUFFER_SIZE) {
            Log.d(TAG, entry.getKey() + ": Sorry, only got " + values.size() + " out of " + BUFFER_SIZE);
        }

        DescriptiveStatistics stats = BeaconFilter.statistics(values);

        synchronized (mScanResults) {
            for (ScanItem info : mScanResults) {
                if (info.getMacAddress().equalsIgnoreCase((entry.getKey()))) {
                    info.setRssi((int) stats.getMean());
                    Log.d(TAG, entry.getKey() + ": Calculated mean of RSSI to " + info.getRssi());
                    break;
                }
            }
        }
        mScanHistory.get(entry.getKey()).clear();
    }
    parcelIntent.putParcelableArrayListExtra(BluetoothScannerService.TAG_PARCEL, mScanResults);
    sendBroadcast(parcelIntent);
}
项目:Diorite    文件:YamlCollectionCreator.java   
static void putAllCollections(Map<Class<?>, IntFunction<?>> map)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
项目:jeff    文件:Fuzzer.java   
private static void startFuzzer(String targetHost, Integer targetPort, Integer fuzzerPort, String fuzzType) throws IOException {
    BlockingDeque<String> queue = new LinkedBlockingDeque<String>();
    AgentEventReader reader = new AgentEventReader(queue, fuzzerPort);
    PayloadGenerator generator = new RandomBytesPayloadGenerator();

    PayloadSender sender = null;
    if ("TCP".equals(fuzzType)) {
        sender = new TCPSocketPayloadSender(targetHost, targetPort);
    } else if ("HTTP".equals(fuzzType)) {
        // TODO implement payload generator for http
    } else if ("JMX".equals(fuzzType)) {
        // TODO implement payload generator for jmx
    }

    PayloadService service = new PayloadService(queue, generator, sender);

    System.out.println(format("Fuzzer has started on %s:%d", targetHost, targetPort));

    ExecutorService executorService = Executors.newFixedThreadPool(2);
    executorService.execute(reader);
    executorService.execute(service);
}
项目:guava-libraries    文件:ArbitraryInstancesTest.java   
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class, BlockingDeque.class, PriorityBlockingQueue.class,
      DelayQueue.class, SynchronousQueue.class,
      ConcurrentMap.class, ConcurrentNavigableMap.class,
      AtomicReference.class, AtomicBoolean.class,
      AtomicInteger.class, AtomicLong.class, AtomicDouble.class);
}
项目:guava    文件:ArbitraryInstancesTest.java   
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class,
      BlockingDeque.class,
      PriorityBlockingQueue.class,
      DelayQueue.class,
      SynchronousQueue.class,
      ConcurrentMap.class,
      ConcurrentNavigableMap.class,
      AtomicReference.class,
      AtomicBoolean.class,
      AtomicInteger.class,
      AtomicLong.class,
      AtomicDouble.class);
}
项目:guava    文件:ArbitraryInstancesTest.java   
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class,
      BlockingDeque.class,
      PriorityBlockingQueue.class,
      DelayQueue.class,
      SynchronousQueue.class,
      ConcurrentMap.class,
      ConcurrentNavigableMap.class,
      AtomicReference.class,
      AtomicBoolean.class,
      AtomicInteger.class,
      AtomicLong.class,
      AtomicDouble.class);
}
项目:xapi    文件:GwtcJobMonitorImpl.java   
@SuppressWarnings("unchecked")
private static BlockingDeque<String> proxy(Object inputDeque) throws NoSuchMethodException {
    if (inputDeque instanceof BlockingDeque) {
        return (BlockingDeque<String>) inputDeque;
    }
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();

    final Method put = inputDeque.getClass().getMethod("put", Object.class);
    final Method take = inputDeque.getClass().getMethod("take");
    final Method isEmpty = inputDeque.getClass().getMethod("isEmpty");

    return (BlockingDeque<String>)Proxy.newProxyInstance(cl, new Class[]{BlockingDeque.class}, (proxy, method, args) -> {
        switch (method.getName()) {
            case "put":
                return put.invoke(inputDeque, args);
            case "take":
                return take.invoke(inputDeque, args);
            case "isEmpty":
                return isEmpty.invoke(inputDeque, args);
        }
        throw new UnsupportedOperationException(method.toGenericString() + " is not supported");
    });
}
项目:type-parser    文件:DynamicParsers.java   
private <T> Collection<T> instantiateCollectionFromInterface(Class<? extends T> collectionType) {
    if (List.class.isAssignableFrom(collectionType)) {
        return new ArrayList<T>();
    } else if (SortedSet.class.isAssignableFrom(collectionType)) {
        return new TreeSet<T>();
    } else if (Set.class.isAssignableFrom(collectionType)) {
        return new LinkedHashSet<T>();
    } else if (BlockingDeque.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Deque.class.isAssignableFrom(collectionType)) {
        return new ArrayDeque<T>();
    } else if (BlockingQueue.class.isAssignableFrom(collectionType)) {
        return new LinkedBlockingDeque<T>();
    } else if (Queue.class.isAssignableFrom(collectionType)) {
        return new LinkedList<T>();
    }
    return new ArrayList<T>();
}
项目:inpacker    文件:ZipPacker.java   
@Override
public void pack(BlockingDeque<PackItem> itemsDeque,
                 File packsDir,
                 String packId,
                 Consumer<PackItem> newItemSuccess,
                 Consumer<PackItem> newItemFail,
                 Consumer<File> done,
                 Runnable failed) {
    final File packFile = new File(packsDir, packId + ".zip");
    try (final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(packFile))) {
        PackItem item = takeItem(itemsDeque);
        if (item == null) {
            failed.run();
            return;
        }
        while (!item.getFileName().equals("end")) {
            final boolean added = PackSupport.saveToZip(item, zos);
            if (added) newItemSuccess.accept(item);
            else newItemFail.accept(item);
            item = takeItem(itemsDeque);
            if (item == null) {
                failed.run();
                return;
            }
        }
    } catch (IOException e) {
        failed.run();
        return;
    }
    done.accept(packFile);
}
项目:inpacker    文件:ZipPacker.java   
private <I extends PackItem> I takeItem(BlockingDeque<I> deque) {
    try {
        return deque.take();
    } catch (InterruptedException e) {
        return null;
    }
}
项目:inpacker    文件:Packer.java   
void pack(BlockingDeque<PackItem> itemsDeque,
File packsDir,
String packId,
Consumer<PackItem> newItemSuccess,
Consumer<PackItem> newItemFail,
Consumer<File> done,
Runnable failed);
项目:inpacker    文件:DirPacker.java   
@Override
public void pack(BlockingDeque<PackItem> itemsDeque,
                 File packsDir,
                 String packId,
                 Consumer<PackItem> newItemSuccess,
                 Consumer<PackItem> newItemFail,
                 Consumer<File> done,
                 Runnable failed) {
    if (!packsDir.exists())
        throw new IllegalArgumentException("packsDir does not exist");
    final File packDir = new File(packsDir, packId);
    if (!packDir.mkdir())
        throw new RuntimeException("unable to create pack directory");
    PackItem item = takeItem(itemsDeque);
    if (item == null) {
        failed.run();
        return;
    }
    while (!item.getFileName().equals("end")) {
        try {
            final File itemFile = new File(packDir, item.getFileName());
            PackSupport.save(new FileOutputStream(itemFile), item.getUrl());
            newItemSuccess.accept(item);
            item = takeItem(itemsDeque);
            if (item == null) {
                failed.run();
                return;
            }
        } catch (IOException e) {
            newItemFail.accept(item);
        }
    }
    done.accept(packDir);
}
项目:inpacker    文件:DirPacker.java   
private <I extends PackItem> I takeItem(BlockingDeque<I> deque) {
    try {
        return deque.take();
    } catch (InterruptedException e) {
        return null;
    }
}
项目:inpacker    文件:DefaultPackService.java   
@Override
public Pack createPack(C config) {
    requireNonNull(config, "required non null config");
    final String id = config.getUniqueId();
    if (packs.containsKey(id))
        return packs.get(id);
    final Pack pack = new Pack(id, config.numberOfItems());
    packs.put(id, pack);
    final BlockingDeque<PackItem> deque = new LinkedBlockingDeque<>();
    executorService.submit(() -> repository.getPackItems(config, deque));
    pack.processing();
    executorService.submit(() -> packer.pack(deque, packsDir, pack));
    return pack;
}
项目:openjdk-jdk10    文件:LinkedBlockingDequeTest.java   
/**
 * takeFirst() throws InterruptedException immediately if interrupted
 * before waiting
 */
public void testTakeFirstFromEmptyAfterInterrupt() {
    final BlockingDeque q = new LinkedBlockingDeque();
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    awaitTermination(t);
}
项目:openjdk-jdk10    文件:LinkedBlockingDequeTest.java   
/**
 * takeLast() throws InterruptedException immediately if interrupted
 * before waiting
 */
public void testTakeLastFromEmptyAfterInterrupt() {
    final BlockingDeque q = new LinkedBlockingDeque();
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    awaitTermination(t);
}
项目:openNaEF    文件:SimpleJunosConfigurationParser.java   
@Override
public void parse() throws IOException {
    BlockingDeque<ConfigElement> stack = new LinkedBlockingDeque<ConfigElement>();
    ConfigElement root = new ConfigElement("root");
    this.config = root;
    stack.addLast(root);
    ConfigElement current = root;
    StringBuilder sb = new StringBuilder();
    readConfigurationText(sb);
    List<String> tokens = tokenize(sb);
    int i = 1;
    for (String token : tokens) {
        if (log.isTraceEnabled()) {
            log.trace("token " + i++ + "/" + tokens.size() + ":" + token);
        }
        JunosElementType thisType = getType(token);
        if (thisType == JunosElementType.LAYER_ENTER) {
            String id = token.replaceAll("[ ]+\\{", "");
            ConfigElement e = new ConfigElement(id);
            current.addElement(e);
            stack.addLast(e);
            current = e;
        } else if (thisType.equals(JunosElementType.LAYER_LEAVE)) {
            stack.removeLast();
            current = stack.peekLast();
        } else if (thisType.equals(JunosElementType.ATTRIBUTE)) {
            token = token.substring(0, token.length() - 1);
            current.addAttribute(token);
        }
    }
}
项目:openjdk9    文件:LinkedBlockingDequeTest.java   
/**
 * takeFirst() throws InterruptedException immediately if interrupted
 * before waiting
 */
public void testTakeFirstFromEmptyAfterInterrupt() {
    final BlockingDeque q = new LinkedBlockingDeque();
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    awaitTermination(t);
}
项目:openjdk9    文件:LinkedBlockingDequeTest.java   
/**
 * takeLast() throws InterruptedException immediately if interrupted
 * before waiting
 */
public void testTakeLastFromEmptyAfterInterrupt() {
    final BlockingDeque q = new LinkedBlockingDeque();
    Thread t = newStartedThread(new CheckedRunnable() {
        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {}
            assertFalse(Thread.interrupted());
        }});

    awaitTermination(t);
}
项目:jeff    文件:PayloadService.java   
public PayloadService(BlockingDeque<String> queue,
                      PayloadGenerator generator,
                      PayloadSender sender) {
    this.queue = checkNotNull(queue);
    this.generator = checkNotNull(generator);
    this.sender = checkNotNull(sender);
}
项目:fim    文件:FileHasher.java   
public FileHasher(Context context, AtomicBoolean scanInProgress, HashProgress hashProgress, BlockingDeque<Path> filesToHashQueue, String rootDir) throws NoSuchAlgorithmException {
    this.context = context;
    this.scanInProgress = scanInProgress;
    this.hashProgress = hashProgress;
    this.filesToHashQueue = filesToHashQueue;
    this.rootDir = rootDir;

    this.fileStates = new ArrayList<>();
    this.frontHasher = new FrontHasher(context);
}
项目:fim    文件:StateGenerator.java   
private void scanFileTree(BlockingDeque<Path> filesToHashQueue, Path directory, FimIgnore parentFimIgnore) throws NoSuchAlgorithmException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
        FimIgnore fimIgnore = fimIgnoreManager.loadLocalIgnore(directory, parentFimIgnore);

        for (Path file : stream) {
            if (!hashProgress.isHashStarted() && filesToHashQueue.size() > FILES_QUEUE_CAPACITY / 2) {
                startFileHashers();
            }

            BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
            String fileName = file.getFileName().toString();
            if (fimIgnoreManager.isIgnored(fileName, attributes, fimIgnore)) {
                fimIgnoreManager.ignoreThisFiles(file, attributes);
            } else {
                if (attributes.isRegularFile()) {
                    if (FilePattern.matchPatterns(fileName, context.getIncludePatterns(), true) &&
                        !FilePattern.matchPatterns(fileName, context.getExcludePatterns(), false)) {
                        enqueueFile(filesToHashQueue, file);
                    }
                } else if (attributes.isDirectory()) {
                    scanFileTree(filesToHashQueue, file, fimIgnore);
                }
            }
        }
    } catch (IOException ex) {
        Logger.newLine();
        Logger.error("Skipping - Error scanning directory '" + directory + "'", ex, context.isDisplayStackTrace());
    }
}
项目:fim    文件:StateGenerator.java   
private void enqueueFile(BlockingDeque<Path> filesToHashQueue, Path file) {
    try {
        filesToHashQueue.offer(file, 120, TimeUnit.MINUTES);
    } catch (InterruptedException ex) {
        Logger.error("Exception while enqueuing file '" + file + "'", ex, context.isDisplayStackTrace());
    }
}
项目:ZhihuDailyPrue    文件:JobExecutor.java   
public JobExecutor() {
    BlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>();
    ThreadFactory threadFactory = new JobThreadFactory();
    this.threadPoolExecutor = new ThreadPoolExecutor(
            INITIAL_POOL_SIZE,
            MAX_POOL_SIZE,
            KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT,
            workQueue,
            threadFactory
    );
}
项目:guava-libraries    文件:ForwardingBlockingDequeTest.java   
@SuppressWarnings("unchecked")
@Override protected void setUp() throws Exception {
  super.setUp();
  final BlockingDeque<String> deque = createProxyInstance(BlockingDeque.class);
  forward = new ForwardingBlockingDeque<String>() {
    @Override protected BlockingDeque<String> delegate() {
      return deque;
    }
  };
}
项目:aquila    文件:BlockQueueTest.java   
public static void main(String[] args) throws InterruptedException {
    BlockingDeque<String> bq = new LinkedBlockingDeque<>();
    String str = "test";
    bq.put(str);
    str = "yesorno";
    bq.put(str);
    System.out.println(bq.size());
    System.out.println(bq.take());
    System.out.println(bq.take());
}
项目:code4fun    文件:WebCrawler.java   
public void driver(){
    BlockingDeque urls = new LinkedBlockingDeque(10);
    ExecutorService service = Executors.newFixedThreadPool(10);
    List<Crawler> runners = new ArrayList<Crawler>();
    for(int i=0; i<10; i++){
        Crawler c = new Crawler(urls, runners); 
        runners.add(c);
        service.submit(c);
    }
}
项目:reef    文件:AggregateContainer.java   
AggregateContainer(final HeartBeatTriggerManager heartBeatTriggerManager,
                   final KryoUtils kryoUtils,
                   final BlockingDeque<byte[]> workerReportsQueue,
                   final TaskletAggregationRequest taskletAggregationRequest) {
  this.heartBeatTriggerManager = heartBeatTriggerManager;
  this.kryoUtils = kryoUtils;
  this.workerReportsQueue = workerReportsQueue;
  this.taskletAggregationRequest = taskletAggregationRequest;
}
项目:xapi    文件:GwtcJobMonitorImpl.java   
public GwtcJobMonitorImpl(BlockingDeque<String> caller, BlockingDeque<String> compiler) {
    // We were instantiated directly, so assume we are running in a foreign classloader,
    // and that our parameters are a pair of LinkedBlockingDeque's that we can use to communicate with.
    readAsCaller = compiler::take;
    readAsCompiler = caller::take;
    writeAsCaller = caller::put;
    writeAsCompiler = compiler::put;
    hasCallerOutput = ()->!caller.isEmpty();
    hasCompilerOutput = ()->!compiler.isEmpty();
}
项目:health-and-care-developer-network    文件:AmqpRepositoryExampleWindowsApplication.java   
@NotNull
@Override
protected AtomicBoolean startMessageSender()
{
    final String ourContainerString = ourContainerString(OurProviderIdentifier, OurRepositoryIdentifier, instanceId);
    final Target target = new Target(newKnownGoodAddressString(queueName), unsettled_state, session_end, LinkExpiryZeroTimeout, true, new NodeProperties(DeleteOnClose.DeleteOnClose), EmptyTargetCapabilities);
    final BlockingQueue<MessageToEnqueue> messagesToEnqueue = sendingStuffEventMessageUser.messagesToEnqueue;
    return startMessageSendingOnlyAmqpConnectionThread(AttemptToNegotiateAmqpTlsSecurityLayer, hostName, virtualHostName, ourContainerString, user, base64urlEncodedPassword, (BlockingDeque<MessageToEnqueue>) messagesToEnqueue, target, persistedMessagesPath, true);
}
项目:health-and-care-developer-network    文件:AmqpRepositoryExampleApplication.java   
@Override
@NotNull
protected AtomicBoolean startMessageSender()
{
    final String ourContainerString = ourContainerString(OurProviderIdentifier, OurRepositoryIdentifier, instanceId);
    final Target target = new Target(newKnownGoodAddressString(queueName), unsettled_state, session_end, LinkExpiryZeroTimeout, true, new NodeProperties(DeleteOnClose.DeleteOnClose), EmptyTargetCapabilities);
    final BlockingQueue<MessageToEnqueue> messagesToEnqueue = sendingStuffEventMessageUser.messagesToEnqueue;
    return startMessageSendingOnlyAmqpConnectionThread(AttemptToNegotiateAmqpTlsSecurityLayer, hostName, virtualHostName, ourContainerString, user, base64urlEncodedPassword, (BlockingDeque<MessageToEnqueue>) messagesToEnqueue, target, persistedMessagesPath, true);
}