public void put(Object x) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); putGuard_.acquire(); try { insert(x); takeGuard_.release(); } catch (ClassCastException ex) { putGuard_.release(); throw ex; } }
public Object take() throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); takeGuard_.acquire(); try { Object x = extract(); putGuard_.release(); return x; } catch (ClassCastException ex) { takeGuard_.release(); throw ex; } }
public Object poll(long msecs) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); if (!takeGuard_.attempt(msecs)) return null; else { try { Object x = extract(); putGuard_.release(); return x; } catch (ClassCastException ex) { takeGuard_.release(); throw ex; } } }
public boolean offer(Object x, long msecs) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); if (!putGuard_.attempt(msecs)) return false; else { try { insert(x); takeGuard_.release(); return true; } catch (ClassCastException ex) { putGuard_.release(); throw ex; } } }
/** * Return the number of elements in the buffer. This is only a snapshot value, that may change * immediately after returning. */ public int size() { return (int) (takeGuard_.permits()); }