java.util.concurrent.BlockingDeque Java Examples

The following examples show how to use java.util.concurrent.BlockingDeque. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: linstor-server   Author: LINBIT   File: OutputProxy.java    License: GNU General Public License v3.0 6 votes vote down vote up
public OutputProxy(
    final InputStream in,
    final BlockingDeque<Event> dequeRef,
    final byte delimiterPrm,
    final boolean useOutPrm
)
{
    dataIn = in;
    deque = dequeRef;
    delimiter = delimiterPrm;
    useOut = useOutPrm;
    data = new byte[INIT_DATA_SIZE];
    dataPos = 0;
    dataLimit = 0;

    shutdown = false;
}
 
Example #2
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: LinkedBlockingDequeTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: LinkedBlockingDequeTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source Project: replicator   Author: mysql-time-machine   File: StreamsBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private StreamsBuilder(
        int threads,
        int tasks,
        BiFunction<Input, Integer, Integer> partitioner,
        Class<? extends BlockingDeque> queueType,
        int queueSize,
        long queueTimeout,
        Function<Integer, Input> dataSupplierFn,
        Predicate<Input> filter,
        Function<Input, Output> process,
        Function<Output, Boolean> to,
        BiConsumer<Input, Integer> post) {
    this.threads = threads;
    this.tasks = tasks;
    this.partitioner = partitioner;
    this.queueType = queueType;
    this.queueSize = queueSize;
    this.queueTimeout = queueTimeout;
    this.dataSupplierFn = dataSupplierFn;
    this.filter = filter;
    this.process = process;
    this.to = to;
    this.post = post;
}
 
Example #5
Source Project: Diorite   Author: Diorite   File: YamlCollectionCreator.java    License: MIT License 6 votes vote down vote up
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<>());
}
 
Example #6
Source Project: baleen   Author: dstl   File: SharedMemoryQueueResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a (blocking) supplier for the given topic
 *
 * @param topic
 * @return the supplier
 */
public Supplier<String> createBlockingSupplier(final String topic) {
  final BlockingDeque<String> queue = getQueue(topic);
  return () -> {
    while (true) {
      try {
        final String s = queue.pollFirst(1, TimeUnit.MINUTES);
        if (s != null) {
          return s;
        }
      } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  };
}
 
Example #7
Source Project: j2objc   Author: google   File: LinkedBlockingDequeTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source Project: j2objc   Author: google   File: LinkedBlockingDequeTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #9
Source Project: type-parser   Author: drapostolos   File: DynamicParsers.java    License: MIT License 6 votes vote down vote up
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>();
}
 
Example #10
Source Project: redis-manager   Author: ngbdf   File: InstallationLogContainer.java    License: Apache License 2.0 5 votes vote down vote up
public static List<String> getLogs(String clusterName) {
    List<String> logs = new LinkedList<>();
    BlockingDeque<String> logContainer = getLogDeque(clusterName);
    try {
        while (!logContainer.isEmpty()) {
            String log = logContainer.pollFirst(1, TimeUnit.SECONDS);
            if (!Strings.isNullOrEmpty(log)) {
                logs.add(log);
            }
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return logs;
}
 
Example #11
Source Project: redis-manager   Author: ngbdf   File: InstallationLogContainer.java    License: Apache License 2.0 5 votes vote down vote up
private static BlockingDeque<String> getLogDeque(String clusterName) {
    BlockingDeque<String> logDeque = INSTALLATION_LOG.get(clusterName);
    if (logDeque == null) {
        logDeque = new LinkedBlockingDeque<>();
    }
    INSTALLATION_LOG.put(clusterName, logDeque);
    return logDeque;
}
 
Example #12
Source Project: hermes   Author: ctripcorp   File: DefaultCommitter.java    License: Apache License 2.0 5 votes vote down vote up
private PartitionOperation<T> mergeMoreOperation(PartitionOperation<T> op,
      BlockingDeque<PartitionOperation<T>> opQueue, int maxRecords) {

	while (!opQueue.isEmpty() && op.getRecords().size() < maxRecords) {
		if (op.getRecords().size() + opQueue.peek().getRecords().size() <= maxRecords) {
			PartitionOperation<T> moreOp = opQueue.poll();
			op.merge(moreOp);
		} else {
			break;
		}
	}

	return op;
}
 
Example #13
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: LinkedBlockingDequeTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #14
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: LinkedBlockingDequeTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #15
Source Project: rawhttp   Author: renatoathaydes   File: RawHttpDuplexOptions.java    License: Apache License 2.0 5 votes vote down vote up
public RawHttpDuplexOptions(RawHttpClient<?> client, Duration pingPeriod,
                            ScheduledExecutorService pingScheduler,
                            Supplier<BlockingDeque<MessageSender.Message>> messageQueueFactory) {
    this.client = client;
    this.pingPeriod = pingPeriod;
    this.pingScheduler = pingScheduler;
    this.messageQueueFactory = messageQueueFactory;
}
 
Example #16
Source Project: rawhttp   Author: renatoathaydes   File: RawHttpDuplexOptions.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Build a {@link RawHttpDuplexOptions} instance with the configured options.
 *
 * @return new instance
 */
public RawHttpDuplexOptions build() {
    RawHttpClient<?> client = getOrDefault(this.client, TcpRawHttpClient::new);
    Duration pingPeriod = getOrDefault(this.pingPeriod, () -> Duration.ofSeconds(5));
    ScheduledExecutorService pinger = getOrDefault(this.pingScheduler, Executors::newSingleThreadScheduledExecutor);
    Supplier<BlockingDeque<MessageSender.Message>> messageQueueFactory = getOrDefault(
            this.messageQueueFactory, Builder::defaultMessageQueue);
    return new RawHttpDuplexOptions(client, pingPeriod, pinger, messageQueueFactory);
}
 
Example #17
Source Project: baleen   Author: dstl   File: SharedMemoryQueueResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a blocking consumer for the given topic
 *
 * @param topic
 * @return the consumer
 */
public Consumer<String> createBlockingConsumer(final String topic) {
  final BlockingDeque<String> queue = getQueue(topic);
  return t -> {
    boolean accepted = false;
    while (!accepted) {
      try {
        accepted = queue.offerLast(t, 1, TimeUnit.MINUTES);
      } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  };
}
 
Example #18
Source Project: baleen   Author: dstl   File: SharedMemoryQueueResource.java    License: Apache License 2.0 5 votes vote down vote up
private synchronized BlockingDeque<String> getOrCreateQueue(final String topic) {
  BlockingDeque<String> queue = queues.get(topic);
  if (queue == null) {
    queue = new LinkedBlockingDeque<>(queueCapacity);
    queues.put(topic, queue);
  }
  return queue;
}
 
Example #19
Source Project: j2objc   Author: google   File: LinkedBlockingDequeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #20
Source Project: j2objc   Author: google   File: LinkedBlockingDequeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #21
Source Project: flink   Author: apache   File: ChannelStateWriteRequestExecutorImpl.java    License: Apache License 2.0 5 votes vote down vote up
ChannelStateWriteRequestExecutorImpl(
		String taskName,
		ChannelStateWriteRequestDispatcher dispatcher,
		BlockingDeque<ChannelStateWriteRequest> deque) {
	this.taskName = taskName;
	this.dispatcher = dispatcher;
	this.deque = deque;
	this.thread = new Thread(this::run, "Channel state writer " + taskName);
	this.thread.setDaemon(true);
}
 
Example #22
Source Project: reef   Author: apache   File: AggregateContainer.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #23
Source Project: linstor-server   Author: LINBIT   File: DaemonHandler.java    License: GNU General Public License v3.0 4 votes vote down vote up
public DaemonHandler(final BlockingDeque<Event> dequeRef, final String... command)
{
    deque = dequeRef;
    processBuilder = new ProcessBuilder(command);
    processBuilder.redirectError(Redirect.PIPE);
}
 
Example #24
Source Project: nuls-v2   Author: nuls-io   File: Chain.java    License: MIT License 4 votes vote down vote up
public BlockingDeque<ByteArrayWrapper> getPackableHashQueue() {
    return packableHashQueue;
}
 
Example #25
Source Project: nuls-v2   Author: nuls-io   File: Chain.java    License: MIT License 4 votes vote down vote up
public void setPackableHashQueue(BlockingDeque<ByteArrayWrapper> packableHashQueue) {
    this.packableHashQueue = packableHashQueue;
}
 
Example #26
Source Project: nuls-v2   Author: nuls-io   File: Chain.java    License: MIT License 4 votes vote down vote up
public BlockingDeque<TransactionNetPO> getUnverifiedQueue() {
    return unverifiedQueue;
}
 
Example #27
Source Project: nuls-v2   Author: nuls-io   File: Chain.java    License: MIT License 4 votes vote down vote up
public void setUnverifiedQueue(BlockingDeque<TransactionNetPO> unverifiedQueue) {
    this.unverifiedQueue = unverifiedQueue;
}
 
Example #28
Source Project: nuls-v2   Author: nuls-io   File: NodeGroup.java    License: MIT License 4 votes vote down vote up
public BlockingDeque<RpcCacheMessage> getCacheMsgQueue() {
    return cacheMsgQueue;
}
 
Example #29
Source Project: nuls-v2   Author: nuls-io   File: NodeGroup.java    License: MIT License 4 votes vote down vote up
public void setCacheMsgQueue(BlockingDeque<RpcCacheMessage> cacheMsgQueue) {
    this.cacheMsgQueue = cacheMsgQueue;
}
 
Example #30
Source Project: nuls-v2   Author: nuls-io   File: Node.java    License: MIT License 4 votes vote down vote up
public BlockingDeque<PeerCacheMessage> getCacheSendMsgQueue() {
    return cacheSendMsgQueue;
}