@Override public Object[] toArray() { return underlyingQueue.toArray(); }
@Override public <T> T[] toArray(T[] array) { return underlyingQueue.toArray(array); }
public void retainConsumers() { Arrays.stream(pooledLeases.toArray(new ConsumerLease[]{})) .forEach(ConsumerLease::retainConnection); }
/** * Drains the task queue into a new list, normally using * drainTo. But if the queue is a DelayQueue or any other kind of * queue for which poll or drainTo may fail to remove some * elements, it deletes them one by one. */ private List<Runnable> drainQueue() { BlockingQueue<Runnable> q = workQueue; ArrayList<Runnable> taskList = new ArrayList<Runnable>(); q.drainTo(taskList); if (!q.isEmpty()) { for (Runnable r : q.toArray(new Runnable[0])) { if (q.remove(r)) taskList.add(r); } } return taskList; }
/** * Tries to remove from the work queue all {@link Future} * tasks that have been cancelled. This method can be useful as a * storage reclamation operation, that has no other impact on * functionality. Cancelled tasks are never executed, but may * accumulate in work queues until worker threads can actively * remove them. Invoking this method instead tries to remove them now. * However, this method may fail to remove tasks in * the presence of interference by other threads. */ public void purge() { final BlockingQueue<Runnable> q = workQueue; try { Iterator<Runnable> it = q.iterator(); while (it.hasNext()) { Runnable r = it.next(); if (r instanceof Future<?> && ((Future<?>)r).isCancelled()) it.remove(); } } catch (ConcurrentModificationException fallThrough) { // Take slow path if we encounter interference during traversal. // Make copy for traversal and call remove for cancelled entries. // The slow path is more likely to be O(N*N). for (Object r : q.toArray()) if (r instanceof Future<?> && ((Future<?>)r).isCancelled()) q.remove(r); } tryTerminate(); // In case SHUTDOWN and now empty }
getContinueExistingPeriodicTasksAfterShutdownPolicy(); if (!keepDelayed && !keepPeriodic) { for (Object e : q.toArray()) if (e instanceof RunnableScheduledFuture<?>) ((RunnableScheduledFuture<?>) e).cancel(false); for (Object e : q.toArray()) { if (e instanceof RunnableScheduledFuture) { RunnableScheduledFuture<?> t =
void checkEmpty(BlockingQueue q) { try { assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertNull(q.peek()); assertNull(q.poll()); assertNull(q.poll(0, MILLISECONDS)); assertEquals("[]", q.toString()); assertTrue(Arrays.equals(q.toArray(), new Object[0])); assertFalse(q.iterator().hasNext()); try { q.element(); shouldThrow(); } catch (NoSuchElementException success) { } try { q.iterator().next(); shouldThrow(); } catch (NoSuchElementException success) { } try { q.remove(); shouldThrow(); } catch (NoSuchElementException success) { } } catch (InterruptedException ie) { threadUnexpectedException(ie); } }
void checkEmpty(BlockingQueue q) { try { assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertNull(q.peek()); assertNull(q.poll()); assertNull(q.poll(0, MILLISECONDS)); assertEquals(q.toString(), "[]"); assertTrue(Arrays.equals(q.toArray(), new Object[0])); assertFalse(q.iterator().hasNext()); try { q.element(); shouldThrow(); } catch (NoSuchElementException success) {} try { q.iterator().next(); shouldThrow(); } catch (NoSuchElementException success) {} try { q.remove(); shouldThrow(); } catch (NoSuchElementException success) {} } catch (InterruptedException fail) { threadUnexpectedException(fail); } }
void checkEmpty(BlockingQueue q) { try { assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertNull(q.peek()); assertNull(q.poll()); assertNull(q.poll(randomExpiredTimeout(), randomTimeUnit())); assertEquals(q.toString(), "[]"); assertTrue(Arrays.equals(q.toArray(), new Object[0])); assertFalse(q.iterator().hasNext()); try { q.element(); shouldThrow(); } catch (NoSuchElementException success) {} try { q.iterator().next(); shouldThrow(); } catch (NoSuchElementException success) {} try { q.remove(); shouldThrow(); } catch (NoSuchElementException success) {} } catch (InterruptedException fail) { threadUnexpectedException(fail); } }
@Override public Object[] toArray() { return queue.toArray(); }
@Override public <T> T[] toArray(T[] a) { return (T[]) queue.toArray(a); }
@Override public <TargetType> TargetType[] toArray( @SuppressWarnings("PMD.ShortVariable") final TargetType[] a) { synchronized (this) { return this.queue.toArray(a); } }
public <T> T[] toArray(T[] array) { synchronized (list) { return list.toArray(array); } }
@Override public Object[] toArray() { synchronized (this) { return this.queue.toArray(); } }
public Object[] toArray() { synchronized (list) { return list.toArray(); } }
public Object[] toArray() { if (isRunning()) { return q.toArray(); } else { return new Object[0]; } }
public <T> T[] toArray(T[] a) { Lock l = lock.readLock(); l.lock(); try { return backing.toArray(a); } finally { l.unlock(); } }
public ReceivedEvent assertMessagePublished(String message, Predicate<ReceivedEvent> predicate) { return eventuallyReturning(eventTrackerIterations, eventTrackerInterval, TimeUnit.SECONDS, () -> { ReceivedEvent[] currentEvents = events.toArray(new ReceivedEvent[events.size()]); for (ReceivedEvent event : currentEvents) { if (predicate.test(event)) { return event; } } throw new RuntimeException(message); }); } }
public <T extends Event> DispatchedEvent<T> assertMessagePublished(String entityId, Class<T> eventClass) { return eventuallyReturning(30, 1, TimeUnit.SECONDS, () -> { DispatchedEvent<Event>[] currentEvents = events.toArray(new DispatchedEvent[events.size()]); for (DispatchedEvent<Event> event : currentEvents) { if (event.getEntityId().equals(entityId) && event.getEventType().equals(eventClass)) return (DispatchedEvent<T>)event; } throw new RuntimeException(String.format("Haven't found event from %s of type %s", entityId, eventClass)); }); } }
public <T> T[] toArray(T[] a) { if (isRunning()) { return q.toArray(a); } else { return new LinkedBlockingQueue<T>(0).toArray(a); } }