Advertisement
Guest User

Untitled

a guest
Aug 10th, 2011
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. /**
  2.  * Generic object {@link Pool}.
  3.  *
  4.  * @param <O> the type of objects <i>this</i> {@link Pool} can hold
  5.  */
  6. public interface BlockingPool<O> extends Iterable<O> {
  7.  
  8.   /**
  9.    * @return the next available {@link O} object from <i>this</i> {@link Pool}
  10.    * or {@code null} if currently there is no available objects
  11.    */
  12.   O poll();
  13.  
  14.   /**
  15.    * @return the next available {@link O} object from <i>this</i>
  16.    * {@link BlockingPool}
  17.    *
  18.    * @throws InterruptedException if the thread waiting to take the next
  19.    * available {@link O} object gets interrupted
  20.    */
  21.   O take() throws InterruptedException;
  22.  
  23.   /**
  24.    * @param timeout the maximum time to wait for being able to take the next
  25.    * available {@link O} object from <i>this</i> {@link BlockingPool}
  26.    * @param unit the unit of {@code timeout}
  27.    *
  28.    * @return the next available {@link O} object from <i>this</i>
  29.    * {@link BlockingPool}
  30.    *
  31.    * @throws InterruptedException if the thread waiting to take the next
  32.    * available {@link O} object gets interrupted
  33.    */
  34.   O take(long timeout, TimeUnit unit) throws InterruptedException;
  35.  
  36.   /**
  37.    * @param object the {@link O} object (previously taken from here) to be
  38.    * returned to <i>this</i> {@link Pool}
  39.    *
  40.    * @throws IllegalStateException if {@code element} wasn't taken from
  41.    * <i>this</i> {@link Pool}
  42.    */
  43.   void put(O object);
  44.  
  45.   /**
  46.    * @param object the {@link O} object (previously taken from here) to be
  47.    * discarded from <i>this</i> {@link Pool}
  48.    *
  49.    * @throws IllegalStateException if {@code element} wasn't taken from
  50.    * <i>this</i> {@link Pool}
  51.    */
  52.   void discard(O object);
  53.  
  54.   /**
  55.    * @return an unmodifiable {@link Iterator} over the {@link O} objects of
  56.    * <i>this</i> {@link Pool} (whether those are currently taken or not)
  57.    */
  58.   @Override
  59.   Iterator<O> iterator();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement