com.phloc.commons.concurrent.collector.AbstractConcurrentCollector Maven / Gradle / Ivy
/**
* Copyright (C) 2006-2015 phloc systems
* http://www.phloc.com
* office[at]phloc[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.phloc.commons.concurrent.collector;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.phloc.commons.ValueEnforcer;
import com.phloc.commons.callback.INonThrowingRunnable;
import com.phloc.commons.state.ESuccess;
/**
* Abstract concurrent collector.
*
* @author Philip Helger
* @param
* The type of the objects in the queue.
*/
public abstract class AbstractConcurrentCollector implements INonThrowingRunnable, IConcurrentCollector
{
/**
* Default maximum queue size
*/
public static final int DEFAULT_MAX_QUEUE_SIZE = 100;
protected static final Object STOP_QUEUE_OBJECT = new Object ();
private static final Logger s_aLogger = LoggerFactory.getLogger (AbstractConcurrentCollector.class);
private final ReadWriteLock m_aRWLock = new ReentrantReadWriteLock ();
// It's a list of Object because otherwise we could not use a static
// STOP_OBJECT that works for every type. But it is ensured that the queue
// contains only objects of type T
protected final BlockingQueue