1 4 package com.tc.util.concurrent; 5 6 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue; 7 8 import java.util.NoSuchElementException ; 9 10 16 public class TCBlockingLinkedQueue implements BlockingQueue { 17 18 private static final long NO_WAIT = 0; 19 private final LinkedQueue queue; 20 21 26 public TCBlockingLinkedQueue() { 27 queue = new LinkedQueue(); 28 } 29 30 public boolean offer(Object o, long timeout) throws InterruptedException { 31 if (null == o) { throw new NullPointerException ("Cannot add null item to queue"); } 32 33 return queue.offer(o, timeout); 34 } 35 36 public Object poll(long timeout) throws InterruptedException { 37 return queue.poll(timeout); 38 } 39 40 public Object take() throws InterruptedException { 41 return queue.take(); 42 } 43 44 public boolean isEmpty() { 45 return queue.isEmpty(); 46 } 47 48 public Object element() { 49 throw new UnsupportedOperationException (); 50 } 51 52 public boolean offer(Object o) { 53 try { 54 return queue.offer(o, 0); 55 } catch (InterruptedException e) { 56 return false; 57 } 58 } 59 60 public Object peek() { 61 return queue.peek(); 62 } 63 64 public Object poll() { 65 try { 66 return queue.poll(NO_WAIT); 67 } catch (InterruptedException e) { 68 return null; 69 } 70 } 71 72 public Object remove() { 73 Object rv = poll(); 74 75 if (rv == null) { throw new NoSuchElementException (); } 76 77 return rv; 78 } 79 80 } | Popular Tags |