/** * Returns the next available packet. The method call will block (not return) * until a stanza is available or the <tt>timeout</tt> has elapsed. If the * timeout elapses without a result, <tt>null</tt> will be returned. * * @param <P> type of the result stanza. * @param timeout the timeout in milliseconds. * @return the next available packet. * @throws InterruptedException */ @SuppressWarnings("unchecked") public <P extends Stanza> P nextResult(long timeout) throws InterruptedException { throwIfCancelled(); P res = null; long remainingWait = timeout; waitStart = System.currentTimeMillis(); do { res = (P) resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS); if (res != null) { return res; } remainingWait = timeout - (System.currentTimeMillis() - waitStart); } while (remainingWait > 0); return null; }
/** * Returns the next available packet. The method call will block (not return) until a stanza is * available. * * @param <P> type of the result stanza. * @return the next available packet. * @throws InterruptedException */ @SuppressWarnings("unchecked") public <P extends Stanza> P nextResultBlockForever() throws InterruptedException { throwIfCancelled(); P res = null; while (res == null) { res = (P) resultQueue.take(); } return res; }
/** * Returns the next available packet. The method call will block (not return) * until a stanza is available or the <tt>timeout</tt> has elapsed. If the * timeout elapses without a result, <tt>null</tt> will be returned. * * @param <P> type of the result stanza. * @param timeout the timeout in milliseconds. * @return the next available packet. * @throws InterruptedException */ @SuppressWarnings("unchecked") public <P extends Stanza> P nextResult(long timeout) throws InterruptedException { throwIfCancelled(); P res = null; long remainingWait = timeout; waitStart = System.currentTimeMillis(); do { res = (P) resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS); if (res != null) { return res; } remainingWait = timeout - (System.currentTimeMillis() - waitStart); } while (remainingWait > 0); return null; }
/** * Returns the next available packet. The method call will block (not return) until a stanza is * available. * * @param <P> type of the result stanza. * @return the next available packet. * @throws InterruptedException */ @SuppressWarnings("unchecked") public <P extends Stanza> P nextResultBlockForever() throws InterruptedException { throwIfCancelled(); P res = null; while (res == null) { res = (P) resultQueue.take(); } return res; }