@Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { // To permit interactive/browser testing, ignore requests for favicons. final String requestLine = request.getRequestLine(); if (requestLine != null && requestLine.equals("GET /favicon.ico HTTP/1.1")) { logger.info("served " + requestLine); return new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND); } if (failFastResponse != null && responseQueue.peek() == null) { // Fail fast if there's no response queued up. return failFastResponse; } MockResponse result = responseQueue.take(); // If take() returned because we're shutting down, then enqueue another dead letter so that any // other threads waiting on take() will also return. if (result == DEAD_LETTER) responseQueue.add(DEAD_LETTER); return result; }
@Override public synchronized Request poll(Task task) { if (!inited.get()) { init(task); } fileCursorWriter.println(cursor.incrementAndGet()); return queue.poll(); }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { executor.getQueue().put(r); } catch (InterruptedException e) { throw new RejectedExecutionException("Got Interrupted while adding to the Queue", e); } } }
@Override public void onNext(Notification<T> args) { if (waiting.getAndSet(0) == 1 || !args.isOnNext()) { Notification<T> toOffer = args; while (!buf.offer(toOffer)) { Notification<T> concurrentItem = buf.poll(); // in case if we won race condition with onComplete/onError method if (concurrentItem != null && !concurrentItem.isOnNext()) { toOffer = concurrentItem; } } } }
if (this.closed.get()) { logger.info("Provenance Repository has been closed; will not merge journal files to {}", suggestedMergeFile); return null; final AtomicBoolean finishedAdding = new AtomicBoolean(false); final List<Future<?>> futures = new ArrayList<>(); final AtomicInteger indexingFailureCount = new AtomicInteger(0); try { for (int i = 0; i < configuration.getIndexThreadPoolSize(); i++) { final Future<?> future = exec.submit(callable); futures.add(future); while (!accepted && indexEvents) { try { accepted = eventQueue.offer(new Tuple<>(record, blockIndex), 10, TimeUnit.MILLISECONDS); } catch (final InterruptedException ie) { Thread.currentThread().interrupt(); if (!accepted && indexingFailureCount.get() >= MAX_INDEXING_FAILURE_COUNT) { indexEvents = false; // don't add anything else to the queue. eventQueue.clear(); finishedAdding.set(true); exec.shutdown();
public void setup() { // Create a single script engine, the Processor object is reused by each task if(scriptEngine == null) { scriptingComponentHelper.setup(1, getLogger()); scriptEngine = scriptingComponentHelper.engineQ.poll(); } if (scriptEngine == null) { throw new ProcessException("No script engine available!"); } if (scriptNeedsReload.get() || processor.get() == null) { if (ScriptingComponentHelper.isFile(scriptingComponentHelper.getScriptPath())) { reloadScriptFile(scriptingComponentHelper.getScriptPath()); } else { reloadScriptBody(scriptingComponentHelper.getScriptBody()); } scriptNeedsReload.set(false); } }
protected void dispatchMessages(Deliver e) { messages.offer(e); if (dispatchThread.get() == 0) { dispatchThread.incrementAndGet(); getBroadcasterConfig().getExecutorService().submit(getBroadcastHandler()); } }
@Override public List<SourceRecord> poll() throws InterruptedException { failureException = this.failure.get(); if (failureException != null) { if (!running.get()) { cleanupResources(); throw new InterruptedException( "Reader was stopped while polling" ); List<SourceRecord> batch = new ArrayList<>(maxBatchSize); final Timer timeout = Threads.timer(Clock.SYSTEM, Temporals.max(pollInterval, ConfigurationDefaults.RETURN_CONTROL_INTERVAL)); while (running.get() && (records.drainTo(batch, maxBatchSize) == 0) && !success.get()) { failureException = this.failure.get(); if (failureException != null) throw failureException; if (timeout.expired()) { if (batch.isEmpty() && success.get() && records.isEmpty()) { this.running.set(false);
Deliver msg = null; try { msg = messages.poll(waitTime, TimeUnit.MILLISECONDS); if (msg == null) { dispatchThread.decrementAndGet(); return; return; } finally { if (outOfOrderBroadcastSupported.get()) { bc.getExecutorService().submit(this); push(msg); } catch (Throwable ex) { if (!started.get() || destroyed.get()) { logger.trace("Failed to submit broadcast handler runnable on shutdown for Broadcaster {}", getID(), ex); return;
getDeltaCount.getAndIncrement(); if (sentDelta.compareAndSet(false, true)) { addDeltaApps(includeRemote, apps); } else { handled = true; } else if (pathInfo.equals("apps/")) { getFullRegistryCount.getAndIncrement(); if (sentDelta.get()) { addDeltaApps(includeRemote, apps); } else { sentRegistry.set(true); handled = true; } else if (pathInfo.startsWith("vips/")) { getSingleVipCount.getAndIncrement(); registrationStatusesQueue.add(statusStr); registrationStatuses.add(statusStr);
public void pushToStream(String message) { int streamNo = (int) this.nextStream.incrementAndGet() % this.queues.size(); AtomicLong offset = this.offsets.get(streamNo); BlockingQueue<FetchedDataChunk> queue = this.queues.get(streamNo); AtomicLong thisOffset = new AtomicLong(offset.incrementAndGet()); List<Message> seq = Lists.newArrayList(); seq.add(new Message(message.getBytes(Charsets.UTF_8))); ByteBufferMessageSet messageSet = new ByteBufferMessageSet(NoCompressionCodec$.MODULE$, offset, JavaConversions.asScalaBuffer(seq)); FetchedDataChunk chunk = new FetchedDataChunk(messageSet, new PartitionTopicInfo("topic", streamNo, queue, thisOffset, thisOffset, new AtomicInteger(1), "clientId"), thisOffset.get()); queue.add(chunk); }
@Override public Object call() throws IOException { while (!eventQueue.isEmpty() || !finishedAdding.get()) { try { final Tuple<StandardProvenanceEventRecord, Integer> tuple; try { tuple = eventQueue.poll(10, TimeUnit.MILLISECONDS); } catch (final InterruptedException ie) { Thread.currentThread().interrupt(); continue; } if (tuple == null) { continue; } indexingAction.index(tuple.getKey(), indexWriter.getIndexWriter(), tuple.getValue()); } catch (final Throwable t) { logger.error("Failed to index Provenance Event for " + writerFile + " to " + indexingDirectory, t); if (indexingFailureCount.incrementAndGet() >= MAX_INDEXING_FAILURE_COUNT) { return null; } } } return null; } };
int c = ctl.get(); if (isRunning(c) || runStateAtLeast(c, TIDYING) || (runStateOf(c) == SHUTDOWN && ! workQueue.isEmpty())) return; if (workerCountOf(c) != 0) { // Eligible to terminate mainLock.lock(); try { if (ctl.compareAndSet(c, ctlOf(TIDYING, 0))) { try { terminated(); } finally { ctl.set(ctlOf(TERMINATED, 0)); termination.signalAll(); mainLock.unlock();
final SocketChannel socketChannel = channel.accept(); if (currentConnections.incrementAndGet() > maxConnections){ currentConnections.decrementAndGet(); logger.warn("Rejecting connection from {} because max connections has been met", new Object[]{ socketChannel.getRemoteAddress().toString() }); ByteBuffer buffer = bufferPool.poll(); buffer.clear(); buffer.mark(); executor.execute(handler); while((key = keyQueue.poll()) != null){ key.interestOps(SelectionKey.OP_READ);
public BufferResult getPages(long sequenceId, DataSize maxSize) if (completed.get() && serializedPages.isEmpty()) { return BufferResult.emptyResults(TASK_INSTANCE_ID, token.get(), true); assertEquals(sequenceId, token.get(), "token"); serializedPage = serializedPages.poll(10, TimeUnit.MILLISECONDS); return BufferResult.emptyResults(TASK_INSTANCE_ID, token.get(), false); long responseSize = serializedPage.getSizeInBytes(); while (responseSize < maxSize.toBytes()) { serializedPage = serializedPages.poll(); if (serializedPage == null) { break;
@Override public ClientResponse<InputStream> done(ClientResponse<InputStream> clientResponse) { synchronized (done) { try { // An empty byte array is put at the end to give the SequenceInputStream.close() as something to close out // after done is set to true, regardless of the rest of the stream's state. queue.put(ByteSource.empty().openStream()); log.debug("Added terminal empty stream"); } catch (InterruptedException e) { log.warn(e, "Thread interrupted while adding to queue"); Thread.currentThread().interrupt(); throw Throwables.propagate(e); } catch (IOException e) { // This should never happen log.wtf(e, "The empty stream threw an IOException"); throw Throwables.propagate(e); } finally { log.debug("Done after adding %d bytes of streams", byteCount.get()); done.set(true); } } return ClientResponse.finished(clientResponse.getObj()); }
final AtomicInteger count = new AtomicInteger(); final BlockingQueue<Object> ref = new LinkedBlockingQueue<>(); for (final Invoker<T> invoker : selected) { executor.execute(new Runnable() { @Override public void run() { Object ret = ref.poll(timeout, TimeUnit.MILLISECONDS); if (ret instanceof Throwable) { Throwable e = (Throwable) ret;
public boolean offer(ServerConnection con, String nextStep, RouteResultset rrs) { PauseTask task = new PauseTask(rrs, nextStep, con); queueLock.lock(); try { if (!teminateFlag) { if (queueNumber.incrementAndGet() <= queueLimit) { handlerQueue.offer(task); return true; } else { con.writeErrMessage(ER_YES, "The node is pausing, wait list is full"); queueNumber.decrementAndGet(); } return true; } else { return false; } } finally { queueLock.unlock(); } }
@Override public void exceptionCaught(final ClientResponse<InputStream> clientResponse, final Throwable e) { // Don't wait for lock in case the lock had something to do with the error synchronized (done) { done.set(true); // Make a best effort to put a zero length buffer into the queue in case something is waiting on the take() // If nothing is waiting on take(), this will be closed out anyways. final boolean accepted = queue.offer( new InputStream() { @Override public int read() throws IOException { throw new IOException(e); } } ); if (!accepted) { log.warn("Unable to place final IOException offer in queue"); } else { log.debug("Placed IOException in queue"); } log.debug(e, "Exception with queue length of %d and %d bytes available", queue.size(), byteCount.get()); } }
Long lastKillTimeMs = null; SanityChecker sc = null; while (!isShutdown.get()) { RejectedExecutionException rejectedException = null; if (nextSanityCheck != null && ((nextSanityCheck - System.nanoTime()) <= 0)) { boolean shouldWait = numSlotsAvailable.get() <= 0 && lastKillTimeMs == null; boolean canKill = false; if (task.canFinishForPriority() || task.isGuaranteed()) { + "preemptionQueueSize={}, numSlotsAvailable={}, waitQueueSize={}", task.getRequestId(), task.getTaskRunnerCallable().canFinish(), preemptionQueue.size(), numSlotsAvailable.get(), waitQueue.size()); canKill = enablePreemption && canPreempt(task, preemptionQueue.peek()); shouldWait = shouldWait && !canKill; if (isShutdown.get()) { LOG.info(WAIT_QUEUE_SCHEDULER_THREAD_NAME_FORMAT + " thread has been interrupted after shutdown.");