/** Waits for an OAuth session for this client to be set. */ public synchronized void awaitAccessToken(Timeout timeout) throws InterruptedIOException { while (session == null) { timeout.waitUntilNotified(this); } }
@Override public long read(Buffer sink, long byteCount) throws IOException { synchronized (buffer) { if (sourceClosed) { throw new IllegalStateException("closed"); } while (buffer.size() == 0) { if (sinkClosed) { if (sinkClosedException == null) { return -1L; } throw new IOException(sinkClosedException); } timeout.waitUntilNotified(buffer); } final long result = buffer.read(sink, byteCount); buffer.notifyAll(); return result; } }
timeout.waitUntilNotified(Relay.this); continue;
@Test public synchronized void notified() throws InterruptedIOException { Timeout timeout = new Timeout(); timeout.timeout(5000, TimeUnit.MILLISECONDS); double start = now(); executorService.schedule(new Runnable() { @Override public void run() { synchronized (WaitUntilNotifiedTest.this) { WaitUntilNotifiedTest.this.notify(); } } }, 1000, TimeUnit.MILLISECONDS); timeout.waitUntilNotified(this); assertElapsed(1000.0, start); }
@Test public synchronized void threadInterrupted() { Timeout timeout = new Timeout(); double start = now(); Thread.currentThread().interrupt(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("interrupted", expected.getMessage()); assertTrue(Thread.interrupted()); } assertElapsed(0.0, start); }
timeout.waitUntilNotified(Relay.this); continue;
@Test public synchronized void deadlineAlreadyReached() { Timeout timeout = new Timeout(); timeout.deadlineNanoTime(System.nanoTime()); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(0.0, start); }
@Test public synchronized void timeout() { Timeout timeout = new Timeout(); timeout.timeout(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void deadline() { Timeout timeout = new Timeout(); timeout.deadline(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void deadlineBeforeTimeout() { Timeout timeout = new Timeout(); timeout.timeout(5000, TimeUnit.MILLISECONDS); timeout.deadline(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void timeoutBeforeDeadline() { Timeout timeout = new Timeout(); timeout.timeout(1000, TimeUnit.MILLISECONDS); timeout.deadline(5000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
timeout.waitUntilNotified(Relay.this); continue;
timeout.waitUntilNotified(Relay.this); continue;