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 017package com.google.common.util.concurrent; 018 019import com.google.common.collect.ForwardingQueue; 020 021import java.util.Collection; 022import java.util.concurrent.BlockingQueue; 023import 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 */ 036public abstract class ForwardingBlockingQueue<E> extends ForwardingQueue<E> 037 implements BlockingQueue<E> { 038 039 /** Constructor for use by subclasses. */ 040 protected ForwardingBlockingQueue() {} 041 042 @Override protected abstract BlockingQueue<E> delegate(); 043 044 @Override public int drainTo( 045 Collection<? super E> c, int maxElements) { 046 return delegate().drainTo(c, maxElements); 047 } 048 049 @Override public int drainTo(Collection<? super E> c) { 050 return delegate().drainTo(c); 051 } 052 053 @Override public boolean offer(E e, long timeout, TimeUnit unit) 054 throws InterruptedException { 055 return delegate().offer(e, timeout, unit); 056 } 057 058 @Override public E poll(long timeout, TimeUnit unit) 059 throws InterruptedException { 060 return delegate().poll(timeout, unit); 061 } 062 063 @Override public void put(E e) throws InterruptedException { 064 delegate().put(e); 065 } 066 067 @Override public int remainingCapacity() { 068 return delegate().remainingCapacity(); 069 } 070 071 @Override public E take() throws InterruptedException { 072 return delegate().take(); 073 } 074}