Home | History | Annotate | Download | only in concurrent
      1 /*
      2  * Copyright (C) 2010 The Guava Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.util.concurrent;
     18 
     19 import com.google.common.collect.ForwardingQueue;
     20 
     21 import java.util.Collection;
     22 import java.util.concurrent.BlockingQueue;
     23 import java.util.concurrent.TimeUnit;
     24 
     25 /**
     26  * A {@link BlockingQueue} which forwards all its method calls to another
     27  * {@link BlockingQueue}. Subclasses should override one or more methods to
     28  * modify the behavior of the backing collection as desired per the <a
     29  * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
     30  *
     31  * @author Raimundo Mirisola
     32  *
     33  * @param <E> the type of elements held in this collection
     34  * @since 4.0
     35  */
     36 public abstract class ForwardingBlockingQueue<E> extends ForwardingQueue<E>
     37     implements BlockingQueue<E> {
     38 
     39   /** Constructor for use by subclasses. */
     40   protected ForwardingBlockingQueue() {}
     41 
     42   @Override protected abstract BlockingQueue<E> delegate();
     43 
     44   @Override public int drainTo(
     45       Collection<? super E> c, int maxElements) {
     46     return delegate().drainTo(c, maxElements);
     47   }
     48 
     49   @Override public int drainTo(Collection<? super E> c) {
     50     return delegate().drainTo(c);
     51   }
     52 
     53   @Override public boolean offer(E e, long timeout, TimeUnit unit)
     54       throws InterruptedException {
     55     return delegate().offer(e, timeout, unit);
     56   }
     57 
     58   @Override public E poll(long timeout, TimeUnit unit)
     59       throws InterruptedException {
     60     return delegate().poll(timeout, unit);
     61   }
     62 
     63   @Override public void put(E e) throws InterruptedException {
     64     delegate().put(e);
     65   }
     66 
     67   @Override public int remainingCapacity() {
     68     return delegate().remainingCapacity();
     69   }
     70 
     71   @Override public E take() throws InterruptedException {
     72     return delegate().take();
     73   }
     74 }
     75