void doRespond(SimpleServerRpcConnection conn, RpcResponse resp) throws IOException { boolean added = false; // If there is already a write in progress, we don't wait. This allows to free the handlers // immediately for other tasks. if (conn.responseQueue.isEmpty() && conn.responseWriteLock.tryLock()) { try { if (conn.responseQueue.isEmpty()) { // If we're alone, we can try to do a direct call to the socket. It's // an optimization to save on context switches and data transfer between cores.. if (processResponse(conn, resp)) { return; // we're done. } // Too big to fit, putting ahead. conn.responseQueue.addFirst(resp); added = true; // We will register to the selector later, outside of the lock. } } finally { conn.responseWriteLock.unlock(); } } if (!added) { conn.responseQueue.addLast(resp); } registerForWrite(conn); } }
if (nextRound.isEmpty()) { break;
/** * Process all the responses for this connection * @return true if all the calls were processed or that someone else is doing it. false if there * * is still some work to do. In this case, we expect the caller to delay us. * @throws IOException */ private boolean processAllResponses(final SimpleServerRpcConnection connection) throws IOException { // We want only one writer on the channel for a connection at a time. connection.responseWriteLock.lock(); try { for (int i = 0; i < 20; i++) { // protection if some handlers manage to need all the responder RpcResponse resp = connection.responseQueue.pollFirst(); if (resp == null) { return true; } if (!processResponse(connection, resp)) { connection.responseQueue.addFirst(resp); return false; } } } finally { connection.responseWriteLock.unlock(); } return connection.responseQueue.isEmpty(); }
if (retries.isEmpty()) { break; //game over
private void endBlock() throws IOException { Preconditions.checkState(waitingAckQueue.isEmpty(), "should call flush first before calling close"); if (state != State.STREAMING) { throw new IOException("stream already broken"); } state = State.CLOSING; long finalizedLength = ackedBlockLength; PacketHeader header = new PacketHeader(4, finalizedLength, nextPacketSeqno, true, 0, false); buf.release(); buf = null; int headerLen = header.getSerializedSize(); ByteBuf headerBuf = alloc.directBuffer(headerLen); header.putInBuffer(headerBuf.nioBuffer(0, headerLen)); headerBuf.writerIndex(headerLen); CompletableFuture<Long> future = new CompletableFuture<>(); waitingAckQueue.add(new Callback(future, finalizedLength, datanodeList)); datanodeList.forEach(ch -> ch.writeAndFlush(headerBuf.retainedDuplicate())); headerBuf.release(); try { future.get(); } catch (InterruptedException e) { throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); throw new IOException(cause); } }
/** * Returns true if this buffer doesn't have lines. * * @return {@code true} if this buffer doesn't have lines, otherwise {@code false} */ public boolean isEmpty() { return this.lines.isEmpty(); }
public synchronized long getElapsedTime(String unit) { if (messages.isEmpty()) { return -1L; } else { return stopwatch.elapsed(TimeUnit.valueOf(unit)); } }
public synchronized boolean tasks() { if (this.runnables.isEmpty()) { return false; } final ArrayList<Runnable> tmp = new ArrayList<>(this.runnables); this.runnables.clear(); for (final Runnable runnable : tmp) { runnable.run(); } return true; } }
UploadBlockListCommand() { super(blobLength); if (!uncommittedBlockEntries.isEmpty()) { lastBlock = uncommittedBlockEntries.getLast(); } }
public synchronized String getStatus() { if (messages.isEmpty()) { return "No current import"; } else { return messages.getLast(); } }
@Override public AuditService getAuditService() { return services.isEmpty() ? defaultAuditService : services.getLast(); }
private boolean isQueueEmpty(Stream stream) { ConcurrentLinkedDeque<PendingData> queue = outgoingDataQueue.get(stream.getStreamId()); return (queue == null || queue.isEmpty()); }
@Override public void run() { // nothing added since submission, quiet period is over if (compileQueue.getLast() == source) { Collection<Path> sources = new HashSet<>(); while (!compileQueue.isEmpty()) { sources.add(compileQueue.removeFirst()); } compile(sources); } } }, autoCompileQuietPeriod, TimeUnit.MILLISECONDS);
@Override public void run() { // nothing added since submission, quiet period is over if (compileQueue.getLast() == source) { Collection<Path> sources = new HashSet<>(); while (!compileQueue.isEmpty()) { sources.add(compileQueue.removeFirst()); } compile(sources); } } }, autoCompileQuietPeriod, TimeUnit.MILLISECONDS);
void clearQueue(int streamId) { ConcurrentLinkedDeque<PendingData> queue = outgoingDataQueue.get(streamId); while (queue != null && !queue.isEmpty() && outgoingFlowControl.get(streamId).get() > 0) { PendingData pendingData = queue.poll(); log.info("sending data from the queue: " + pendingData.data); sendDataFrames(pendingData.data, pendingData.isComplete, pendingData.stream, true) .thenAccept(v -> pendingData.future.complete(null)); } }
/** * Redraw all pending updates. */ protected void redraw() { while(!updateQueue.isEmpty()) { Visualization vis = updateQueue.pop(); vis.incrementalRedraw(); } }
private void fireToListeners() { // //ChannelRegistrationListener[] listeners = listenerList.getListeners(ChannelRegistrationListener.class); // for(int i = 0; i < listeners.length; i++) { // listenerList.remove(ChannelRegistrationListener.class, listeners[i]); // listeners[i].processRegistrations(); // } while(!listenerList.isEmpty()) { ChannelRegistrationListener l = listenerList.poll(); l.processRegistrations(); } }
/** * Redraw all pending updates. */ protected void redraw() { while(!updateQueue.isEmpty()) { Visualization vis = updateQueue.pop(); vis.incrementalRedraw(); } }
protected void shutdown() { worker.unsubscribe(); while (!taskQueue.isEmpty()) { taskQueue.poll().cancel(); } metrics.setQueueSize(0); }