if (!isExpecting()) { throw new NoSuchElementException("Not expecting a result. Call expect() before take()."); synchronized (lock) { value = results.take(); if (isContinuable(value)) {
/** * @param throttleLimit the throttle limit for the result queue */ public ResultQueueInternalState(int throttleLimit) { super(); this.results = new ResultHolderResultQueue(throttleLimit); }
@Test public void testPutTake() throws Exception { queue.expect(); assertTrue(queue.isExpecting()); assertTrue(queue.isEmpty()); queue.put(new TestResultHolder(RepeatStatus.CONTINUABLE)); assertFalse(queue.isEmpty()); assertTrue(queue.take().getResult().isContinuable()); assertFalse(queue.isExpecting()); }
@Override public void put(ResultHolder holder) throws IllegalArgumentException { if (!isExpecting()) { throw new IllegalArgumentException("Not expecting a result. Call expect() before put()."); } results.add(holder); // Take from the waits queue now to allow another result to // accumulate. But don't decrement the counter. waits.release(); synchronized (lock) { lock.notifyAll(); } }
@Test public void testOrdering() throws Exception { queue.expect(); queue.expect(); queue.put(new TestResultHolder(RepeatStatus.FINISHED)); queue.put(new TestResultHolder(RepeatStatus.CONTINUABLE)); assertFalse(queue.isEmpty()); assertTrue(queue.take().getResult().isContinuable()); assertFalse(queue.take().getResult().isContinuable()); }
@Override public void put(ResultHolder holder) throws IllegalArgumentException { if (!isExpecting()) { throw new IllegalArgumentException("Not expecting a result. Call expect() before put()."); } results.add(holder); // Take from the waits queue now to allow another result to // accumulate. But don't decrement the counter. waits.release(); synchronized (lock) { lock.notifyAll(); } }
if (!isExpecting()) { throw new NoSuchElementException("Not expecting a result. Call expect() before take()."); synchronized (lock) { value = results.take(); if (isContinuable(value)) {
/** * @param throttleLimit the throttle limit for the result queue */ public ResultQueueInternalState(int throttleLimit) { super(); this.results = new ResultHolderResultQueue(throttleLimit); }