001package org.apache.commons.jcs3.engine;
002
003import java.util.concurrent.ExecutorService;
004
005/*
006 * Licensed to the Apache Software Foundation (ASF) under one
007 * or more contributor license agreements.  See the NOTICE file
008 * distributed with this work for additional information
009 * regarding copyright ownership.  The ASF licenses this file
010 * to you under the Apache License, Version 2.0 (the
011 * "License"); you may not use this file except in compliance
012 * with the License.  You may obtain a copy of the License at
013 *
014 *   http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing,
017 * software distributed under the License is distributed on an
018 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019 * KIND, either express or implied.  See the License for the
020 * specific language governing permissions and limitations
021 * under the License.
022 */
023
024import org.apache.commons.jcs3.engine.behavior.ICacheListener;
025import org.apache.commons.jcs3.utils.threadpool.PoolConfiguration;
026import org.apache.commons.jcs3.utils.threadpool.PoolConfiguration.WhenBlockedPolicy;
027import org.apache.commons.jcs3.utils.threadpool.ThreadPoolManager;
028
029/**
030 * An event queue is used to propagate ordered cache events to one and only one target listener.
031 */
032public class CacheEventQueue<K, V>
033    extends PooledCacheEventQueue<K, V>
034{
035    /**
036     * Constructs with the specified listener and the cache name.
037     * <p>
038     * @param listener
039     * @param listenerId
040     * @param cacheName
041     */
042    public CacheEventQueue( final ICacheListener<K, V> listener, final long listenerId, final String cacheName )
043    {
044        this( listener, listenerId, cacheName, 10, 500 );
045    }
046
047    /**
048     * Constructor for the CacheEventQueue object
049     * <p>
050     * @param listener
051     * @param listenerId
052     * @param cacheName
053     * @param maxFailure
054     * @param waitBeforeRetry
055     */
056    public CacheEventQueue( final ICacheListener<K, V> listener, final long listenerId, final String cacheName, final int maxFailure,
057                            final int waitBeforeRetry )
058    {
059        super( listener, listenerId, cacheName, maxFailure, waitBeforeRetry, null );
060    }
061
062    /**
063     * Create the thread pool.
064     * <p>
065     * @param threadPoolName
066     * @since 3.1
067     */
068    @Override
069    protected ExecutorService createPool(final String threadPoolName)
070    {
071        // create a default pool with one worker thread to mimic the SINGLE queue behavior
072        return ThreadPoolManager.getInstance().createPool(
073                new PoolConfiguration(false, 0, 1, 1, getWaitToDieMillis(), WhenBlockedPolicy.BLOCK, 1),
074                "CacheEventQueue.QProcessor-" + getCacheName());
075    }
076
077    /**
078     * What type of queue is this.
079     * <p>
080     * @return queueType
081     */
082    @Override
083    public QueueType getQueueType()
084    {
085        /** The type of queue -- there are pooled and single */
086        return QueueType.SINGLE;
087    }
088}