1 package org.apache.commons.jcs3.engine;
2
3 import java.util.concurrent.ExecutorService;
4
5 /*
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 */
23
24 import org.apache.commons.jcs3.engine.behavior.ICacheListener;
25 import org.apache.commons.jcs3.utils.threadpool.PoolConfiguration;
26 import org.apache.commons.jcs3.utils.threadpool.PoolConfiguration.WhenBlockedPolicy;
27 import org.apache.commons.jcs3.utils.threadpool.ThreadPoolManager;
28
29 /**
30 * An event queue is used to propagate ordered cache events to one and only one target listener.
31 */
32 public class CacheEventQueue<K, V>
33 extends PooledCacheEventQueue<K, V>
34 {
35 /**
36 * Constructs with the specified listener and the cache name.
37 * <p>
38 * @param listener
39 * @param listenerId
40 * @param cacheName
41 */
42 public CacheEventQueue( final ICacheListener<K, V> listener, final long listenerId, final String cacheName )
43 {
44 this( listener, listenerId, cacheName, 10, 500 );
45 }
46
47 /**
48 * Constructor for the CacheEventQueue object
49 * <p>
50 * @param listener
51 * @param listenerId
52 * @param cacheName
53 * @param maxFailure
54 * @param waitBeforeRetry
55 */
56 public CacheEventQueue( final ICacheListener<K, V> listener, final long listenerId, final String cacheName, final int maxFailure,
57 final int waitBeforeRetry )
58 {
59 super( listener, listenerId, cacheName, maxFailure, waitBeforeRetry, null );
60 }
61
62 /**
63 * Create the thread pool.
64 * <p>
65 * @param threadPoolName
66 * @since 3.1
67 */
68 @Override
69 protected ExecutorService createPool(final String threadPoolName)
70 {
71 // create a default pool with one worker thread to mimic the SINGLE queue behavior
72 return ThreadPoolManager.getInstance().createPool(
73 new PoolConfiguration(false, 0, 1, 1, getWaitToDieMillis(), WhenBlockedPolicy.BLOCK, 1),
74 "CacheEventQueue.QProcessor-" + getCacheName());
75 }
76
77 /**
78 * What type of queue is this.
79 * <p>
80 * @return queueType
81 */
82 @Override
83 public QueueType getQueueType()
84 {
85 /** The type of queue -- there are pooled and single */
86 return QueueType.SINGLE;
87 }
88 }