Refine search
@SuppressWarnings("ArrayEquality") private void emitLargeEvents() { if (largeEventsToEmit.isEmpty()) { return; } // Don't try to emit large events until exhaustion, to avoid starvation of "normal" batches, if large event // posting rate is too high, though it should never happen in practice. largeEventsToEmit.add(LARGE_EVENTS_STOP); for (byte[] largeEvent; (largeEvent = largeEventsToEmit.poll()) != LARGE_EVENTS_STOP; ) { emitLargeEvent(largeEvent); approximateBuffersToEmitCount.decrementAndGet(); approximateLargeEventsToEmitCount.decrementAndGet(); approximateEventsToEmitCount.decrementAndGet(); } }
private void persist() { IPersistable persistable = null; while (!queue.isEmpty()) { try { persistable = queue.poll(); if (!saveObject(persistable)) { log.warn("Object persist failed for: {}", persistable); } } catch (Throwable e) { log.error("Error while saving {} in {}. {}", new Object[] { persistable, this, e }); } } }
ThreadWorker get() { if (allWorkers.isDisposed()) { return SHUTDOWN_THREAD_WORKER; } while (!expiringWorkerQueue.isEmpty()) { ThreadWorker threadWorker = expiringWorkerQueue.poll(); if (threadWorker != null) { return threadWorker; } } // No cached worker found, so create a new one. ThreadWorker w = new ThreadWorker(threadFactory); allWorkers.add(w); return w; }
private void failPendingReceive() { lock.readLock().lock(); try { if (listenerExecutor != null && !listenerExecutor.isShutdown()) { while (!pendingReceives.isEmpty()) { CompletableFuture<Message<T>> receiveFuture = pendingReceives.poll(); if (receiveFuture != null) { receiveFuture.completeExceptionally( new PulsarClientException.AlreadyClosedException("Consumer is already closed")); } else { break; } } } } finally { lock.readLock().unlock(); } }
private void failPendingReceive() { lock.readLock().lock(); try { if (listenerExecutor != null && !listenerExecutor.isShutdown()) { while (!pendingReceives.isEmpty()) { CompletableFuture<Message<T>> receiveFuture = pendingReceives.poll(); if (receiveFuture != null) { receiveFuture.completeExceptionally( new PulsarClientException.AlreadyClosedException("Consumer is already closed")); } else { break; } } } } finally { lock.readLock().unlock(); } }
/** * Waits until all evaluate blocks have completed or the specified timeout * (in seconds) expires. If one of the evaluate blocks throws an exception, it is rethrown * from this method. * * @param seconds the timeout (in seconds) * @throws InterruptedException if the calling thread is interrupted * @throws Throwable the first exception thrown by an evaluate block */ public void await(double seconds) throws Throwable { latch.await((long) (seconds * 1000), TimeUnit.MILLISECONDS); if (!exceptions.isEmpty()) throw exceptions.poll(); long pendingEvalBlocks = latch.getCount(); if (pendingEvalBlocks > 0) { String msg = String.format("Async conditions timed out " + "after %1.2f seconds; %d out of %d evaluate blocks did not complete in time", seconds, pendingEvalBlocks, numEvalBlocks); throw new SpockTimeoutError(seconds, msg); } }
ThreadWorker get() { if (allWorkers.isDisposed()) { return SHUTDOWN_THREAD_WORKER; } while (!expiringWorkerQueue.isEmpty()) { ThreadWorker threadWorker = expiringWorkerQueue.poll(); if (threadWorker != null) { return threadWorker; } } // No cached worker found, so create a new one. ThreadWorker w = new ThreadWorker(threadFactory); allWorkers.add(w); return w; }
private void checkRequestTimeout() { while (!requestTimeoutQueue.isEmpty()) { RequestTime request = requestTimeoutQueue.peek(); if (request == null || (System.currentTimeMillis() - request.creationTimeMs) < operationTimeoutMs) { // if there is no request that is timed out then exit the loop break; } request = requestTimeoutQueue.poll(); CompletableFuture<ProducerResponse> requestFuture = pendingRequests.remove(request.requestId); if (requestFuture != null && !requestFuture.isDone() && requestFuture.completeExceptionally(new TimeoutException( request.requestId + " lookup request timedout after ms " + operationTimeoutMs))) { log.warn("{} request {} timed out after {} ms", ctx.channel(), request.requestId, operationTimeoutMs); } else { // request is already completed successfully. } } }
private void resumeReceivingFromPausedConsumersIfNeeded() { lock.readLock().lock(); try { if (incomingMessages.size() <= sharedQueueResumeThreshold && !pausedConsumers.isEmpty()) { while (true) { ConsumerImpl<T> consumer = pausedConsumers.poll(); if (consumer == null) { break; } // if messages are readily available on consumer we will attempt to writeLock on the same thread client.eventLoopGroup().execute(() -> { receiveMessageFromConsumer(consumer); }); } } } finally { lock.readLock().unlock(); } }
while (!fetchedAppSettingsCallbacks.isEmpty()) { final FetchedAppSettingsCallback callback = fetchedAppSettingsCallbacks.poll(); handler.post(new Runnable() { @Override while (!fetchedAppSettingsCallbacks.isEmpty()) { final FetchedAppSettingsCallback callback = fetchedAppSettingsCallbacks.poll(); handler.post(new Runnable() { @Override
@SuppressWarnings("unchecked") @Override public final void run() { if(on.get()) { // establishes a happens-before relationship with the end of the previous run try { final Signal s = inboundSignals.poll(); // We take a signal off the queue if (!done) { // If we're done, we shouldn't process any more signals, obeying rule 2.8 // Below we simply unpack the `Signal`s and invoke the corresponding methods if (s instanceof OnNext<?>) handleOnNext(((OnNext<T>)s).next); else if (s instanceof OnSubscribe) handleOnSubscribe(((OnSubscribe)s).subscription); else if (s instanceof OnError) // We are always able to handle OnError, obeying rule 2.10 handleOnError(((OnError)s).error); else if (s == OnComplete.Instance) // We are always able to handle OnComplete, obeying rule 2.9 handleOnComplete(); } } finally { on.set(false); // establishes a happens-before relationship with the beginning of the next run if(!inboundSignals.isEmpty()) // If we still have signals to process tryScheduleToExecute(); // Then we try to schedule ourselves to execute again } } }
/** * Tests that an exception is thrown if the resource pool is used more than its size can take. */ @Test public void resourcePoolBlocking() throws InterruptedException { mThrown.expect(RuntimeException.class); final int POOL_SIZE = 2; @SuppressWarnings("unchecked") ConcurrentLinkedQueue<Integer> queue = mock(ConcurrentLinkedQueue.class); TestResourcePool testPool = new TestResourcePool(POOL_SIZE, queue); when(queue.isEmpty()).thenReturn(true); when(queue.poll()).thenThrow(new InterruptedException()); for (int i = 0; i < POOL_SIZE + 1; i++) { testPool.acquire(); } }