Java Code Examples for java.util.concurrent.DelayQueue#toArray()
The following examples show how to use
java.util.concurrent.DelayQueue#toArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelayQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * toArray contains all elements */ public void testToArray() throws InterruptedException { DelayQueue q = populatedQueue(SIZE); Object[] o = q.toArray(); Arrays.sort(o); for (int i = 0; i < o.length; i++) assertSame(o[i], q.take()); }
Example 2
Source File: DelayQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * toArray(a) contains all elements */ public void testToArray2() { DelayQueue<PDelay> q = populatedQueue(SIZE); PDelay[] ints = new PDelay[SIZE]; PDelay[] array = q.toArray(ints); assertSame(ints, array); Arrays.sort(ints); for (int i = 0; i < ints.length; i++) assertSame(ints[i], q.remove()); }
Example 3
Source File: DelayQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { DelayQueue q = populatedQueue(SIZE); try { q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} }
Example 4
Source File: RpcConfigSourceClient.java From vespa with Apache License 2.0 | 5 votes |
/** * This method will be called when a response with changed config is received from upstream * (content or generation has changed) or the server timeout has elapsed. * * @param config new config */ public void updateSubscribers(RawConfig config) { log.log(Level.FINE, () -> "Config updated for " + config.getKey() + "," + config.getGeneration()); DelayQueue<DelayedResponse> responseDelayQueue = delayedResponses.responses(); log.log(Level.FINEST, () -> "Delayed response queue: " + responseDelayQueue); if (responseDelayQueue.size() == 0) { log.log(Level.FINE, () -> "There exists no matching element on delayed response queue for " + config.getKey()); return; } else { log.log(Level.FINE, () -> "Delayed response queue has " + responseDelayQueue.size() + " elements"); } boolean found = false; for (DelayedResponse response : responseDelayQueue.toArray(new DelayedResponse[0])) { JRTServerConfigRequest request = response.getRequest(); if (request.getConfigKey().equals(config.getKey()) // Generation 0 is special, used when returning empty sentinel config && (config.getGeneration() >= request.getRequestGeneration() || config.getGeneration() == 0)) { if (delayedResponses.remove(response)) { found = true; log.log(Level.FINE, () -> "Call returnOkResponse for " + config.getKey() + "," + config.getGeneration()); rpcServer.returnOkResponse(request, config); } else { log.log(Level.INFO, "Could not remove " + config.getKey() + " from delayedResponses queue, already removed"); } } } if (!found) { log.log(Level.FINE, () -> "Found no recipient for " + config.getKey() + " in delayed response queue"); } log.log(Level.FINE, () -> "Finished updating config for " + config.getKey() + "," + config.getGeneration()); }
Example 5
Source File: DelayQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * toArray contains all elements */ public void testToArray() throws InterruptedException { DelayQueue q = populatedQueue(SIZE); Object[] o = q.toArray(); Arrays.sort(o); for (int i = 0; i < o.length; i++) assertSame(o[i], q.take()); }
Example 6
Source File: DelayQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * toArray(a) contains all elements */ public void testToArray2() { DelayQueue<PDelay> q = populatedQueue(SIZE); PDelay[] ints = new PDelay[SIZE]; PDelay[] array = q.toArray(ints); assertSame(ints, array); Arrays.sort(ints); for (int i = 0; i < ints.length; i++) assertSame(ints[i], q.remove()); }
Example 7
Source File: DelayQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { DelayQueue q = populatedQueue(SIZE); try { q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} }