本文整理了Java中java.util.concurrent.LinkedBlockingDeque.isEmpty()
方法的一些代码示例,展示了LinkedBlockingDeque.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedBlockingDeque.isEmpty()
方法的具体详情如下:
包路径:java.util.concurrent.LinkedBlockingDeque
类名称:LinkedBlockingDeque
方法名:isEmpty
暂无
代码示例来源:origin: google/ExoPlayer
/**
* Asserts that the source has not notified its listener of a timeline change since the last call
* to {@link #assertTimelineChangeBlocking()} or {@link #assertTimelineChange()} (or since the
* runner was created if neither method has been called).
*/
public void assertNoTimelineChange() {
assertThat(timelines.isEmpty()).isTrue();
}
代码示例来源:origin: wildfly/wildfly
@Override
public void run() {
while (!taskRunQueue.isEmpty()) {
taskRunQueue.poll().run();
}
}
};
代码示例来源:origin: testcontainers/testcontainers-java
private void waitUntilEnd(Long expiry) throws TimeoutException {
while (System.currentTimeMillis() < expiry) {
try {
OutputFrame frame = frames.pollLast(100, TimeUnit.MILLISECONDS);
if (frame == OutputFrame.END) {
return;
}
if (frames.isEmpty()) {
// sleep for a moment to avoid excessive CPU spinning
Thread.sleep(10L);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
throw new TimeoutException("Expiry time reached before end of output");
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Check if any {@link WorkUnit} is available. The producer is {@link SingleWorkUnitGeneratorService}
* @return true when a new {@link WorkUnit} is available
* false when {@link CompactionWorkUnitIterator#isDone} is invoked
*/
public boolean hasNext () {
try {
while (true) {
if (last != null) return true;
if (this.isDone.get() && this.workUnits.isEmpty()) return false;
this.last = this.workUnits.poll(1, TimeUnit.SECONDS);
}
} catch (InterruptedException e) {
log.error(e.toString());
return false;
}
}
代码示例来源:origin: google/ExoPlayer
/**
* Asserts that the source has not notified its listener of a timeline change since the last call
* to {@link #assertTimelineChangeBlocking()} or {@link #assertTimelineChange()} (or since the
* runner was created if neither method has been called).
*/
public void assertNoTimelineChange() {
assertThat(timelines.isEmpty()).isTrue();
}
代码示例来源:origin: testcontainers/testcontainers-java
private void waitUntil(Predicate<OutputFrame> predicate, long expiry, int times) throws TimeoutException {
int numberOfMatches = 0;
while (System.currentTimeMillis() < expiry) {
try {
OutputFrame frame = frames.pollLast(100, TimeUnit.MILLISECONDS);
if (frame != null) {
final String trimmedFrameText = frame.getUtf8String().replaceFirst("\n$", "");
LOGGER.debug("{}: {}", frame.getType(), trimmedFrameText);
if (predicate.test(frame)) {
numberOfMatches++;
if (numberOfMatches == times) {
return;
}
}
}
if (frames.isEmpty()) {
// sleep for a moment to avoid excessive CPU spinning
Thread.sleep(10L);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
// did not return before expiry was reached
throw new TimeoutException();
}
代码示例来源:origin: apache/usergrid
@Override
public void run() {
synchronized ( isOpen ) {
// Keep writing after closed until buffer is flushed (empty)
while ( isOpen.get() || !buffer.isEmpty() ) {
try {
Result result = buffer.pollLast( waitTime.get(), TimeUnit.MILLISECONDS );
if ( result != null ) {
resultCount.incrementAndGet();
jgen.writeObject( result );
}
}
catch ( InterruptedException e ) {
LOG.error( "ResultLog thread interrupted.", e );
}
catch ( JsonProcessingException e ) {
LOG.error( "Failed to generate the JSON for a result.", e );
}
catch ( IOException e ) {
LOG.error( "Failed to write JSON to output stream for a result", e );
}
}
isOpen.notifyAll();
}
}
}
代码示例来源:origin: apache/zookeeper
private Packet findSendablePacket(LinkedBlockingDeque<Packet> outgoingQueue,
boolean tunneledAuthInProgres) {
if (outgoingQueue.isEmpty()) {
return null;
}
// If we've already starting sending the first packet, we better finish
if (outgoingQueue.getFirst().bb != null || !tunneledAuthInProgres) {
return outgoingQueue.getFirst();
}
// Since client's authentication with server is in progress,
// send only the null-header packet queued by primeConnection().
// This packet must be sent so that the SASL authentication process
// can proceed, but all other packets should wait until
// SASL authentication completes.
Iterator<Packet> iter = outgoingQueue.iterator();
while (iter.hasNext()) {
Packet p = iter.next();
if (p.requestHeader == null) {
// We've found the priming-packet. Move it to the beginning of the queue.
iter.remove();
outgoingQueue.addFirst(p);
return p;
} else {
// Non-priming packet: defer it until later, leaving it in the queue
// until authentication completes.
LOG.debug("deferring non-priming packet {} until SASL authentation completes.", p);
}
}
return null;
}
代码示例来源:origin: apache/drill
void close() {
logger.debug( "[#{}] Query listener closing.", instanceId );
closed = true;
if ( stopThrottlingIfSo() ) {
logger.debug( "[#{}] Throttling stopped at close() (at queue size {}).",
instanceId, batchQueue.size() );
}
while (!batchQueue.isEmpty()) {
// Don't bother with query timeout, we're closing the cursor
QueryDataBatch qdb = batchQueue.poll();
if (qdb != null && qdb.getData() != null) {
qdb.getData().release();
}
}
// Close may be called before the first result is received and therefore
// when the main thread is blocked waiting for the result. In that case
// we want to unblock the main thread.
firstMessageReceived.countDown(); // TODO: Why not call releaseIfFirst as used elsewhere?
completed = true;
}
代码示例来源:origin: loklak/loklak_server
@Override
public void run() {
// work loop
while (!DAO.wait_ready(1000)) {
try {Thread.sleep(10000);} catch (InterruptedException e) {}
}
loop: while (this.shallRun) try {
this.isBusy = false;
if (messageQueue.isEmpty() && postQueue.isEmpty()) {
// in case that the queue is empty, try to fill it with previously pushed content
//List<Map<String, Object>> shard = this.jsonBufferHandler.getBufferShard();
// if the shard has content, turn this into messages again
// if such content does not exist, simply sleep a while
try {Thread.sleep(2000);} catch (InterruptedException e) {}
continue loop;
}
this.isBusy = true;
if (messageQueue.size() > 0) indexTweets();
if (postQueue.size() > 0) indexPosts();
this.isBusy = false;
} catch (Throwable e) {
DAO.severe("QueuedIndexing THREAD", e);
}
DAO.log("QueuedIndexing terminated");
}
代码示例来源:origin: apache/flume
@Override
protected void doRollback() {
int takes = takeList.size();
synchronized (queueLock) {
Preconditions.checkState(queue.remainingCapacity() >= takeList.size(),
"Not enough space in memory channel " +
"queue to rollback takes. This should never happen, please report");
while (!takeList.isEmpty()) {
queue.addFirst(takeList.removeLast());
}
putList.clear();
}
putByteCounter = 0;
takeByteCounter = 0;
queueStored.release(takes);
channelCounter.setChannelSize(queue.size());
}
代码示例来源:origin: apache/drill
throw executionFailureException;
if (completed && batchQueue.isEmpty()) {
return null;
} else {
代码示例来源:origin: apache/zookeeper
if (outgoingQueue.isEmpty()) {
代码示例来源:origin: apache/flume
channelCounter.addToEventPutSuccessCount(puts);
synchronized (queue) {
while (!putList.isEmpty()) {
if (!queue.addTail(putList.removeFirst())) {
StringBuilder msg = new StringBuilder();
代码示例来源:origin: apache/flume
synchronized (queueLock) {
if (puts > 0) {
while (!putList.isEmpty()) {
if (!queue.offer(putList.removeFirst())) {
throw new RuntimeException("Queue add failed, this shouldn't be able to happen");
代码示例来源:origin: apache/zookeeper
/**
* doWrite handles writing the packets from outgoingQueue via network to server.
*/
private void doWrite(List<Packet> pendingQueue, Packet p, ClientCnxn cnxn) {
updateNow();
while (true) {
if (p != WakeupPacket.getInstance()) {
if ((p.requestHeader != null) &&
(p.requestHeader.getType() != ZooDefs.OpCode.ping) &&
(p.requestHeader.getType() != ZooDefs.OpCode.auth)) {
p.requestHeader.setXid(cnxn.getXid());
synchronized (pendingQueue) {
pendingQueue.add(p);
}
}
sendPktOnly(p);
}
if (outgoingQueue.isEmpty()) {
break;
}
p = outgoingQueue.remove();
}
// TODO: maybe we should flush in the loop above every N packets/bytes?
// But, how do we determine the right value for N ...
channel.flush();
}
代码示例来源:origin: apache/flume
+ channelNameDescriptor);
synchronized (queue) {
while (!takeList.isEmpty()) {
Preconditions.checkState(queue.addHead(takeList.removeLast()),
"Queue add failed, this shouldn't be able to happen "
代码示例来源:origin: jankotek/mapdb
/**
* Returns a new deque of given size containing consecutive
* Integers 0 ... n - 1.
*/
private static LinkedBlockingDeque<Integer> populatedDeque(int n) {
LinkedBlockingDeque<Integer> q =
new LinkedBlockingDeque<Integer>(n);
assertTrue(q.isEmpty());
for (int i = 0; i < n; i++)
assertTrue(q.offer(new Integer(i)));
assertFalse(q.isEmpty());
assertEquals(0, q.remainingCapacity());
assertEquals(n, q.size());
assertEquals((Integer) 0, q.peekFirst());
assertEquals((Integer) (n - 1), q.peekLast());
return q;
}
代码示例来源:origin: linkedin/cruise-control
anomalies.add(new GoalViolations(mockKafkaCruiseControl, true,
true, true));
while (!anomalies.isEmpty()) {
代码示例来源:origin: linkedin/cruise-control
anomalies.add(new BrokerFailures(mockKafkaCruiseControl, Collections.singletonMap(0, 100L),
false, true, true));
while (!anomalies.isEmpty()) {
内容来源于网络,如有侵权,请联系作者删除!