1 package org.apache.commons.jcs3.engine;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.jcs3.engine.behavior.ICacheEventQueue;
23 import org.apache.commons.jcs3.engine.behavior.ICacheListener;
24 import org.apache.commons.jcs3.log.Log;
25 import org.apache.commons.jcs3.log.LogManager;
26
27 /**
28 * This class hands out event Queues. This allows us to change the implementation more easily. You
29 * can configure the cache to use a custom type.
30 */
31 public class CacheEventQueueFactory<K, V>
32 {
33 /** The logger. */
34 private static final Log log = LogManager.getLog( CacheEventQueueFactory.class );
35
36 /**
37 * The most commonly used factory method.
38 * <p>
39 * @param listener
40 * @param listenerId
41 * @param cacheName
42 * @param threadPoolName
43 * @param poolType - SINGLE, POOLED
44 * @return ICacheEventQueue
45 */
46 public ICacheEventQueue<K, V> createCacheEventQueue( final ICacheListener<K, V> listener, final long listenerId, final String cacheName,
47 final String threadPoolName, final ICacheEventQueue.QueueType poolType )
48 {
49 return createCacheEventQueue( listener, listenerId, cacheName, 10, 500, threadPoolName, poolType );
50 }
51
52 /**
53 * Fully configured event queue.
54 * <p>
55 * @param listener
56 * @param listenerId
57 * @param cacheName
58 * @param maxFailure
59 * @param waitBeforeRetry
60 * @param threadPoolName null is OK, if not a pooled event queue this is ignored
61 * @param poolType single or pooled
62 * @return ICacheEventQueue
63 */
64 public ICacheEventQueue<K, V> createCacheEventQueue( final ICacheListener<K, V> listener, final long listenerId, final String cacheName,
65 final int maxFailure, final int waitBeforeRetry, final String threadPoolName,
66 final ICacheEventQueue.QueueType poolType )
67 {
68 log.debug( "threadPoolName = [{0}] poolType = {1}", threadPoolName, poolType );
69
70 ICacheEventQueue<K, V> eventQueue = null;
71 if ( poolType == null || ICacheEventQueue.QueueType.SINGLE == poolType )
72 {
73 eventQueue = new CacheEventQueue<>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry );
74 }
75 else if ( ICacheEventQueue.QueueType.POOLED == poolType )
76 {
77 eventQueue = new PooledCacheEventQueue<>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry,
78 threadPoolName );
79 }
80
81 return eventQueue;
82 }
83 }