/** * all elements successfully put are contained */ public void testPut() throws InterruptedException { LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); for (int i = 0; i < SIZE; ++i) { Integer x = new Integer(i); q.put(x); assertTrue(q.contains(x)); } assertEquals(0, q.remainingCapacity()); }
/** * drainTo(c) empties queue into another collection c */ public void testDrainTo() { LinkedBlockingQueue q = populatedQueue(SIZE); ArrayList l = new ArrayList(); q.drainTo(l); assertEquals(0, q.size()); assertEquals(SIZE, l.size()); for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i)); q.add(zero); q.add(one); assertFalse(q.isEmpty()); assertTrue(q.contains(zero)); assertTrue(q.contains(one)); l.clear(); q.drainTo(l); assertEquals(0, q.size()); assertEquals(2, l.size()); for (int i = 0; i < 2; ++i) assertEquals(l.get(i), new Integer(i)); }
/** * iterator iterates through all elements */ public void testIterator() throws InterruptedException { LinkedBlockingQueue q = populatedQueue(SIZE); Iterator it = q.iterator(); int i; for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next())); assertEquals(i, SIZE); assertIteratorExhausted(it); it = q.iterator(); for (i = 0; it.hasNext(); i++) assertEquals(it.next(), q.take()); assertEquals(i, SIZE); assertIteratorExhausted(it); }
/** * removeAll(c) removes only those elements of c and reports true if changed */ public void testRemoveAll() { for (int i = 1; i < SIZE; ++i) { LinkedBlockingQueue q = populatedQueue(SIZE); LinkedBlockingQueue p = populatedQueue(i); assertTrue(q.removeAll(p)); assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.remove()); assertFalse(q.contains(x)); } } }
public boolean contains(CassandraHost cassandraHost) { return downedHostQueue.contains(cassandraHost); }
/** * clear removes all elements */ public void testClear() { LinkedBlockingQueue q = populatedQueue(SIZE); q.clear(); assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertEquals(SIZE, q.remainingCapacity()); q.add(one); assertFalse(q.isEmpty()); assertTrue(q.contains(one)); q.clear(); assertTrue(q.isEmpty()); }
@Override public void run() { if(downedHostQueue.contains(cassandraHost) && verifyConnection(cassandraHost)) { if (connectionManager.addCassandraHost(cassandraHost)) { listenerHandler.fireOnHostRestored(cassandraHost); downedHostQueue.remove(cassandraHost); } return; } } });
@Override public void run() { synchronized (getSendingPacketQueue()) { if (self.getSendingPacketQueue().contains(packet)) { self.getSendingPacketQueue().remove(packet); self.__i__onSendPacketCancel(packet); } } } }).start();
class NoDupBlockingQueue<T> extends LinkedBlockingQueue<T> { @Override public void put(T e) throws InterruptedException { if (!contains(e)) super.put(e); } }
public boolean contains(Runnable runnable) { return command_queue.contains(runnable); }
/** * Adds a jid to lookup vCard. * * @param jid the jid to lookup. */ public void addToQueue(BareJid jid) { if (!queue.contains(jid)) { queue.add(jid); } }
@Override public void add(@NonNull Transaction runnable) { synchronized (queue) { if (!queue.contains(runnable)) { queue.add(runnable); } } }
public void execute(Runnable command, boolean checkOnly) { try { if (checkOnly && command_queue.contains(command)) { return; } command_queue.add(command); synchronized (this) { notify(); } } catch (Exception e) { log.error("Main Thread " + threadName + " Notify Exception:" + e.getMessage()); } }
protected void queueEvent(JWatchKey event) { synchronized (this) { if (_eventQueue.contains(event)) { throw new IllegalStateException(L.l("watch key already signaled: {0}", event)); } _eventQueue.add(event); } }
public boolean enqueueTcpMsg(final TcpMsg tcpMsg) { if (tcpMsg == null || getMsgQueue().contains(tcpMsg)) { return false; } try { getMsgQueue().put(tcpMsg); return true; } catch (InterruptedException e) { // e.printStackTrace(); } return false; }
public boolean enqueueUdpMsg(final UdpMsg tcpMsg) { if (tcpMsg == null || getSendingMsg() == tcpMsg || getMsgQueue().contains(tcpMsg)) { return false; } try { getMsgQueue().put(tcpMsg); return true; } catch (InterruptedException e) { // e.printStackTrace(); } return false; }
@Override public void run() { if(downedHostQueue.contains(cassandraHost) && verifyConnection(cassandraHost)) { if (connectionManager.addCassandraHost(cassandraHost)) { listenerHandler.fireOnHostRestored(cassandraHost); downedHostQueue.remove(cassandraHost); } return; } } });
@Override public void run() { if(downedHostQueue.contains(cassandraHost) && verifyConnection(cassandraHost)) { if (connectionManager.addCassandraHost(cassandraHost)) { listenerHandler.fireOnHostRestored(cassandraHost); downedHostQueue.remove(cassandraHost); } return; } } });