Refine search
private boolean fetchChunk(final boolean block) throws InterruptedException { if (eof) { return false; } // Read until no buffers available (poll returned null) // or until a non-empty buffer or EOF is reached. do { if (closed.get()) { current = EOF; break; } current = (block) ? buffers.take() : buffers.poll(); } while (current != null && current != EOF && !current.hasRemaining()); eof = current == EOF; return !eof; }
private List<RedisCommand<Object, Object, Object>> prepareForceFlush() { List<RedisCommand<Object, Object, Object>> batch = new ArrayList<>(Math.max(batchSize, 10)); do { RedisCommand<Object, Object, Object> poll = queue.poll(); assert poll != null; batch.add(poll); } while (!queue.isEmpty()); return batch; }
private boolean fetchChunk(final boolean block) throws InterruptedException { if (eof) { return false; } // Read until no buffers available (poll returned null) // or until a non-empty buffer or EOF is reached. do { if (closed.get()) { current = EOF; break; } current = (block) ? buffers.take() : buffers.poll(); } while (current != null && current != EOF && !current.hasRemaining()); eof = current == EOF; return !eof; }
private ReaderElement getNextPBF() { ReaderElement next = null; while (next == null) { if (!hasIncomingData && itemQueue.isEmpty()) { // we are done, stop polling eof = true; break; } try { // we cannot use "itemQueue.take()" as it blocks and hasIncomingData can change next = itemQueue.poll(10, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { eof = true; break; } } return next; } }
@Override public void run() { WebSocketImpl ws = null; try { while ( true ) { ByteBuffer buf; ws = iqueue.take(); buf = ws.inQueue.poll(); assert ( buf != null ); doDecode(ws, buf); ws = null; } } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); } catch ( RuntimeException e ) { handleFatal( ws, e ); } }
private List<RedisCommand<Object, Object, Object>> prepareDefaultFlush(int consume) { List<RedisCommand<Object, Object, Object>> batch = new ArrayList<>(Math.max(consume, 10)); while ((batch.size() < consume || consume == -1) && !queue.isEmpty()) { RedisCommand<Object, Object, Object> poll = queue.poll(); assert poll != null; batch.add(poll); } return batch; } }
private RandomAccessFile checkOut() throws IOException, InterruptedException { RandomAccessFile fileHandle = readFileHandles.poll(); if (fileHandle != null) { return fileHandle; } int remaining = readFileHandles.remainingCapacity(); if (remaining > 0) { LOG.info("Opening " + file + " for read, remaining number of file " + "handles available for reads of this file is " + remaining); return open(); } return readFileHandles.take(); }
@Override public void run() { while (true) { if (messageStrings.size() > 0) { StringBuilder builder = new StringBuilder(); while (!messageStrings.isEmpty()) { builder.append(messageStrings.poll()).append(BATCH_LOG_SPLIT); } if (LOGGER.isInfoEnabled()) { LOGGER.info(builder.toString()); } } try { Thread.sleep(IDLE_CHECK_MILLS); } catch (InterruptedException exx) { LOGGER.error(exx.getMessage()); } } } }
@Override public void removeSupervisors(int number) throws TException { if (jstormMaster.jstormMasterContext.supervisorContainers.isEmpty()) return; for (int i = 0; i < number; i++) { Container container = jstormMaster.jstormMasterContext.supervisorContainers.poll(); if (container != null) { amRMClient.releaseAssignedContainer(container.getId()); LOG.info("release supervisor's " + String.valueOf(number) + " container, id: " + container.getId().toString()); } } }
/** * This method returns job specs receive from Kafka. It will block if there are no job specs. * @return list of (verb, jobspecs) pairs. */ @Override public Future<? extends List<Pair<SpecExecutor.Verb, Spec>>> changedSpecs() { List<Pair<SpecExecutor.Verb, Spec>> changesSpecs = new ArrayList<>(); try { Pair<SpecExecutor.Verb, Spec> specPair = _jobSpecQueue.take(); _metrics.jobSpecDeqCount.incrementAndGet(); do { changesSpecs.add(specPair); // if there are more elements then pass them along in this call specPair = _jobSpecQueue.poll(); } while (specPair != null); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return new CompletedFuture(changesSpecs, null); }
@Override public void stopSupervisors() throws TException { if (jstormMaster.jstormMasterContext.supervisorContainers.isEmpty()) return; int supervisorCount = jstormMaster.jstormMasterContext.supervisorContainers.size(); for (int i = 0; i < supervisorCount; i++) { Container container = jstormMaster.jstormMasterContext.supervisorContainers.poll(); if (container != null) { amRMClient.releaseAssignedContainer(container.getId()); LOG.info("release all supervisor container, id: " + container.getId().toString()); } } }
/** * May block the current thread and wait until {@link BluetoothDevice} is offered via * {@link #deviceConnected(BluetoothDevice)} method or timeout occurred. * * @return socket of the connected bluetooth device * @throws IOException if socket has been closed, thread interrupted while waiting or timeout has * occurred. */ @Implementation protected BluetoothSocket accept(int timeout) throws IOException { if (closed) { throw new IOException("Socket closed"); } BluetoothSocket socket; try { socket = timeout == -1 ? sockets.take() : sockets.poll(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new IOException(e); } if (socket == null) { throw new IOException("Timeout occurred"); } socket.connect(); return socket; }