001 /*
002 * Copyright (C) 2010 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package com.google.common.util.concurrent;
018
019 import com.google.common.collect.ForwardingQueue;
020
021 import java.util.Collection;
022 import java.util.concurrent.BlockingQueue;
023 import java.util.concurrent.TimeUnit;
024
025 /**
026 * A {@link BlockingQueue} which forwards all its method calls to another
027 * {@link BlockingQueue}. Subclasses should override one or more methods to
028 * modify the behavior of the backing collection as desired per the <a
029 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
030 *
031 * @author Raimundo Mirisola
032 *
033 * @param <E> the type of elements held in this collection
034 * @since 4.0
035 */
036 public abstract class ForwardingBlockingQueue<E> extends ForwardingQueue<E>
037 implements BlockingQueue<E> {
038
039 /** Constructor for use by subclasses. */
040 protected ForwardingBlockingQueue() {}
041
042
043 @Override
044 protected abstract BlockingQueue<E> delegate();
045
046 public int drainTo(
047 Collection<? super E> c, int maxElements) {
048 return delegate().drainTo(c, maxElements);
049 }
050
051 public int drainTo(Collection<? super E> c) {
052 return delegate().drainTo(c);
053 }
054
055 public boolean offer(E e, long timeout, TimeUnit unit)
056 throws InterruptedException {
057 return delegate().offer(e, timeout, unit);
058 }
059
060 public E poll(long timeout, TimeUnit unit)
061 throws InterruptedException {
062 return delegate().poll(timeout, unit);
063 }
064
065 public void put(E e) throws InterruptedException {
066 delegate().put(e);
067 }
068
069 public int remainingCapacity() {
070 return delegate().remainingCapacity();
071 }
072
073 public E take() throws InterruptedException {
074 return delegate().take();
075 }
076 }