@Override public boolean hasPendingJobs() { return !queue.isEmpty(); }
/** * Returns true if there are waiting envelopes. */ public boolean hasEnvelopes() { return !envelopes.isEmpty(); }
public boolean isEmptyish() { for (Executor exe : exes) if (!exe.que.isEmpty()) return false; return true; }
@Override public synchronized boolean isFinished() { return closed && queue.isEmpty(); }
@Override public void onStopped(GridWorker w) { workers.remove(w); if (shutdown) { active.decrementAndGet(); return; } Callable<?> task = queue.poll(); if (task != null) startThread(task); else { active.decrementAndGet(); if (!queue.isEmpty()) startFromQueue(); } } };
private void flushPending() { IConnectionCallback serverCb = _server._cb; if (serverCb != null && !_pendingDueToUnregisteredServer.isEmpty()) { ArrayList<TaskMessage> ret = new ArrayList<>(); _pendingDueToUnregisteredServer.drainTo(ret); serverCb.recv(ret); } }
public synchronized void setRecordReader(LlapBaseRecordReader recordReader) { this.recordReader = recordReader; if (recordReader == null) { return; } // If any events were queued by the responder, give them to the record reader now. while (!queuedEvents.isEmpty()) { ReaderEvent readerEvent = queuedEvents.poll(); LOG.debug("Sending queued event to record reader: " + readerEvent.getEventType()); recordReader.handleEvent(readerEvent); } }
@Override @SuppressFBWarnings("JLM_JSR166_UTILCONCURRENT_MONITORENTER") public void run() { try { isRunning = true; while (true) { Object event = waitingEvents.take(); if (event == eventOfDeath) { wasKilled = true; } else { processEvent(event); } if (wasKilled) synchronized (waitingEvents) { if (waitingEvents.isEmpty()) { isRunning = false; break; } } } } catch (InterruptedException e) { LOG.error("Event thread exiting due to interruption", e); } LOG.info("EventThread shut down for session: 0x{}", Long.toHexString(getSessionId())); }
@Override public void run() { synchronized (lock) { try { if (!(finished && queue.isEmpty())) { final List<DataSegment> segments = new ArrayList<>(); queue.drainTo(segments); try { announcer.announceSegments(segments); nextAnnoucement = exec.schedule(this, intervalMillis, TimeUnit.MILLISECONDS); } catch (IOException e) { doneAnnouncing.setException( new SegmentLoadingException(e, "Failed to announce segments[%s]", segments) ); } } else { doneAnnouncing.set(true); } } catch (Exception e) { doneAnnouncing.setException(e); } } } },
@Override public boolean cleanLocalBuffer() { while (!messageBuffer.isEmpty()) { if (!push(messageBuffer.peek())) { return false; } else { messageBuffer.poll(); } } return true; }
private OpenedObject<T> openObjectFromLocal() throws IOException { final FetchedFile<T> fetchedFile; if (!fetchedFiles.isEmpty()) { // If there are already fetched files, use them fetchedFile = fetchedFiles.poll(); } else { // Otherwise, wait for fetching try { fetchIfNeeded(fetchedBytes.get()); fetchedFile = fetchedFiles.poll(prefetchConfig.getFetchTimeout(), TimeUnit.MILLISECONDS); if (fetchedFile == null) { // Check the latest fetch is failed checkFetchException(true); // Or throw a timeout exception throw new RuntimeException(new TimeoutException()); } } catch (InterruptedException e) { throw Throwables.propagate(e); } } final FetchedFile<T> maybeCached = cacheIfPossible(fetchedFile); // trigger fetch again for subsequent next() calls fetchIfNeeded(fetchedBytes.get()); return new OpenedObject<>(maybeCached); }
private synchronized List<ConnectorSplit> getBatch(int maxSize) { // take up to maxSize elements from the queue List<ConnectorSplit> elements = new ArrayList<>(maxSize); queue.drainTo(elements, maxSize); // if the queue is empty and the current future is finished, create a new one so // a new readers can be notified when the queue has elements to read if (queue.isEmpty() && !closed) { if (notEmptyFuture.isDone()) { notEmptyFuture = new CompletableFuture<>(); } } return ImmutableList.copyOf(elements); }
@Override public void run() { Random rand = new Random(Thread.currentThread().getId()); try { while(true) { // If it is a read-only test, there will be no proposals.. if (!proposals.isEmpty()){ Request request = proposals.take(); Thread.sleep(5 + rand.nextInt(95)); commitProcessor.commit(request); } } } catch (InterruptedException e) { // ignore } }
@OnStopped public void onStopped(final ProcessContext context) throws IOException { if(mqttQueue != null && !mqttQueue.isEmpty() && processSessionFactory != null) { logger.info("Finishing processing leftover messages"); ProcessSession session = processSessionFactory.createSession(); transferQueue(session); } else { if (mqttQueue!= null && !mqttQueue.isEmpty()){ throw new ProcessException("Stopping the processor but there is no ProcessSessionFactory stored and there are messages in the MQTT internal queue. Removing the processor now will " + "clear the queue but will result in DATA LOSS. This is normally due to starting the processor, receiving messages and stopping before the onTrigger happens. The messages " + "in the MQTT internal queue cannot finish processing until until the processor is triggered to run."); } } }
private void commitTransactions() { if (transactions.isEmpty()) return; ArrayList<MVCCTransaction> oldTransactions = new ArrayList<>(transactions.size()); transactions.drainTo(oldTransactions); for (MVCCTransaction t : oldTransactions) { if (t.getSession() != null) t.getSession().commit(null); else t.commit(); } }
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { final boolean isScheduled = scheduled.get(); if (!isConnected() && isScheduled){ synchronized (this) { if (!isConnected()) { initializeClient(context); } } } if (mqttQueue.isEmpty()) { return; } transferQueue(session); }
/** * Queue transitions from empty to full when elements added */ public void testEmptyFull() { LinkedBlockingQueue q = new LinkedBlockingQueue(2); assertTrue(q.isEmpty()); assertEquals("should have room for 2", 2, q.remainingCapacity()); q.add(one); assertFalse(q.isEmpty()); q.add(two); assertFalse(q.isEmpty()); assertEquals(0, q.remainingCapacity()); assertFalse(q.offer(three)); }
/** * Returns a new queue of given size containing consecutive * Integers 0 ... n - 1. */ private static LinkedBlockingQueue<Integer> populatedQueue(int n) { LinkedBlockingQueue<Integer> q = new LinkedBlockingQueue<>(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.peek()); return q; }
/** * clear removes all elements */ public void testClear() { LinkedBlockingQueue q = populatedQueue(SIZE); q.clear(); assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertEquals(SIZE, q.remainingCapacity()); q.add(one); assertFalse(q.isEmpty()); assertTrue(q.contains(one)); q.clear(); assertTrue(q.isEmpty()); }