public ScriptEngine getEngine() { availableCount.decrementAndGet(); return scriptEngines.poll(); }
public static void addReceiveMessageEntity( ReceiveMessageEntity receiveMessageEntity) { if (RECEIVE_MESSAGE_ENTITIES.offer(receiveMessageEntity)) { return; } RECEIVE_MESSAGE_ENTITIES.poll(); RECEIVE_MESSAGE_ENTITIES.offer(receiveMessageEntity); }
public static void addSendSmsRequest(SendSmsRequest sendSmsRequest) { if (SEND_SMS_REQUESTS.offer(sendSmsRequest)) { return; } try { SEND_REENTRANT_LOCK.lock(); SEND_SMS_REQUESTS.poll(); SEND_SMS_REQUESTS.offer(sendSmsRequest); } finally { SEND_REENTRANT_LOCK.unlock(); } }
public static void addSendBatchSmsRequest(SendBatchSmsRequest sendBatchSmsRequest) { if (SEND_BATCH_SMS_REQUESTS.offer(sendBatchSmsRequest)) { return; } try { SEND_BATCH_REENTRANT_LOCK.lock(); SEND_BATCH_SMS_REQUESTS.poll(); SEND_BATCH_SMS_REQUESTS.offer(sendBatchSmsRequest); } finally { SEND_BATCH_REENTRANT_LOCK.unlock(); } }
public void run() { while (!stop) { try { ToSend m = sendqueue.poll(3000, TimeUnit.MILLISECONDS); if(m == null) continue; process(m); } catch (InterruptedException e) { break; } } LOG.info("WorkerSender is down"); }
public static void main(String[] args) throws InterruptedException { CacheLoaderTest cacheLoaderTest = new CacheLoaderTest() ; cacheLoaderTest.init(); while (true) { try { Integer integer = QUEUE.poll(200, TimeUnit.MILLISECONDS); if (null == integer) { break; } //TimeUnit.SECONDS.sleep(5); cacheLoaderTest.checkAlert(integer); LOGGER.info("job running times={}", integer); } catch (InterruptedException e) { e.printStackTrace(); } } }
private WatchedEvent getEvent(int numTries) throws InterruptedException { WatchedEvent event = null; for (int i = 0; i < numTries; i++) { System.out.println("i = " + i); event = events.poll(10, TimeUnit.SECONDS); if (event != null) { break; } Thread.sleep(5000); } return event; }
public static Object pollMessage(int port) { readerArrived(port); return getQueue(port).poll(); }
/** * Get an assignments from the target queue with the specific index. * @param queueIndex index of the queue * @return an {@link NodeAssignments} * @throws InterruptedException */ public NodeAssignments nextAssignments(Integer queueIndex) throws InterruptedException { NodeAssignments target = null; while (true) { target = getQueueById(queueIndex).poll(); if (target != null) { return target; } Time.sleep(100L); } }
public synchronized void setRecordReader(LlapBaseRecordReader recordReader) { this.recordReader = recordReader; if (recordReader == null) { return; } // If any events were queued by the responder, give them to the record reader now. while (!queuedEvents.isEmpty()) { ReaderEvent readerEvent = queuedEvents.poll(); LOG.debug("Sending queued event to record reader: " + readerEvent.getEventType()); recordReader.handleEvent(readerEvent); } }
/** * Queue contains all elements of collection used to initialize */ public void testConstructor6() { Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i); LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints)); for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll()); }
public void assertEvent(long timeout, EventType eventType) { try { WatchedEvent event = dataEvents.poll(timeout, TimeUnit.MILLISECONDS); Assert.assertNotNull("do not receive a " + eventType, event); Assert.assertEquals(eventType, event.getType()); } catch (InterruptedException e) { LOG.warn("ignoring interrupt during EventsWatcher assertEvent"); } } }
public void verify(List<EventType> expected) throws InterruptedException{ WatchedEvent event; int count = 0; while (count < expected.size() && (event = events.poll(30, TimeUnit.SECONDS)) != null) { Assert.assertEquals(expected.get(count), event.getType()); count++; } Assert.assertEquals(expected.size(), count); events.clear(); } }
/** * toArray contains all elements in FIFO order */ public void testToArray() { LinkedBlockingQueue q = populatedQueue(SIZE); Object[] o = q.toArray(); for (int i = 0; i < o.length; i++) assertSame(o[i], q.poll()); }
/** * contains(x) reports true when elements added but not yet removed */ public void testContains() { LinkedBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertTrue(q.contains(new Integer(i))); q.poll(); assertFalse(q.contains(new Integer(i))); } }
/** * toArray(a) contains all elements in FIFO order */ public void testToArray2() throws InterruptedException { LinkedBlockingQueue<Integer> q = populatedQueue(SIZE); Integer[] ints = new Integer[SIZE]; Integer[] array = q.toArray(ints); assertSame(ints, array); for (int i = 0; i < ints.length; i++) assertSame(ints[i], q.poll()); }
/** * peek returns next element, or null if empty */ public void testPeek() { LinkedBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.peek()); assertEquals(i, q.poll()); assertTrue(q.peek() == null || !q.peek().equals(i)); } assertNull(q.peek()); }