001package org.apache.commons.jcs.engine; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.jcs.engine.behavior.ICacheEventQueue; 023import org.apache.commons.jcs.engine.behavior.ICacheListener; 024import org.apache.commons.logging.Log; 025import org.apache.commons.logging.LogFactory; 026 027/** 028 * This class hands out event Queues. This allows us to change the implementation more easily. You 029 * can confugure the cache to use a custom type. 030 * <p> 031 * @author aaronsm 032 */ 033public class CacheEventQueueFactory<K, V> 034{ 035 /** The logger. */ 036 private static final Log log = LogFactory.getLog( CacheEventQueueFactory.class ); 037 038 /** 039 * The most commonly used factory method. 040 * <p> 041 * @param listener 042 * @param listenerId 043 * @param cacheName 044 * @param threadPoolName 045 * @param poolType - SINGLE, POOLED 046 * @return ICacheEventQueue 047 */ 048 public ICacheEventQueue<K, V> createCacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName, 049 String threadPoolName, ICacheEventQueue.QueueType poolType ) 050 { 051 return createCacheEventQueue( listener, listenerId, cacheName, 10, 500, threadPoolName, poolType ); 052 } 053 054 /** 055 * Fully configured event queue. 056 * <p> 057 * @param listener 058 * @param listenerId 059 * @param cacheName 060 * @param maxFailure 061 * @param waitBeforeRetry 062 * @param threadPoolName null is OK, if not a pooled event queue this is ignored 063 * @param poolType single or pooled 064 * @return ICacheEventQueue 065 */ 066 public ICacheEventQueue<K, V> createCacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName, 067 int maxFailure, int waitBeforeRetry, String threadPoolName, 068 ICacheEventQueue.QueueType poolType ) 069 { 070 if ( log.isDebugEnabled() ) 071 { 072 log.debug( "threadPoolName = [" + threadPoolName + "] poolType = " + poolType + " " ); 073 } 074 075 ICacheEventQueue<K, V> eventQueue = null; 076 if ( poolType == null || ICacheEventQueue.QueueType.SINGLE == poolType ) 077 { 078 eventQueue = new CacheEventQueue<K, V>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry ); 079 } 080 else if ( ICacheEventQueue.QueueType.POOLED == poolType ) 081 { 082 eventQueue = new PooledCacheEventQueue<K, V>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry, 083 threadPoolName ); 084 } 085 086 return eventQueue; 087 } 088}