View Javadoc
1   package org.apache.commons.jcs.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.jcs.engine.behavior.ICacheEventQueue;
23  import org.apache.commons.jcs.engine.behavior.ICacheListener;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  /**
28   * This class hands out event Queues. This allows us to change the implementation more easily. You
29   * can confugure the cache to use a custom type.
30   * <p>
31   * @author aaronsm
32   */
33  public class CacheEventQueueFactory<K, V>
34  {
35      /** The logger. */
36      private static final Log log = LogFactory.getLog( CacheEventQueueFactory.class );
37  
38      /**
39       * The most commonly used factory method.
40       * <p>
41       * @param listener
42       * @param listenerId
43       * @param cacheName
44       * @param threadPoolName
45       * @param poolType - SINGLE, POOLED
46       * @return ICacheEventQueue
47       */
48      public ICacheEventQueue<K, V> createCacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName,
49                                                     String threadPoolName, ICacheEventQueue.QueueType poolType )
50      {
51          return createCacheEventQueue( listener, listenerId, cacheName, 10, 500, threadPoolName, poolType );
52      }
53  
54      /**
55       * Fully configured event queue.
56       * <p>
57       * @param listener
58       * @param listenerId
59       * @param cacheName
60       * @param maxFailure
61       * @param waitBeforeRetry
62       * @param threadPoolName null is OK, if not a pooled event queue this is ignored
63       * @param poolType single or pooled
64       * @return ICacheEventQueue
65       */
66      public ICacheEventQueue<K, V> createCacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName,
67                                                     int maxFailure, int waitBeforeRetry, String threadPoolName,
68                                                     ICacheEventQueue.QueueType poolType )
69      {
70          if ( log.isDebugEnabled() )
71          {
72              log.debug( "threadPoolName = [" + threadPoolName + "] poolType = " + poolType + " " );
73          }
74  
75          ICacheEventQueue<K, V> eventQueue = null;
76          if ( poolType == null || ICacheEventQueue.QueueType.SINGLE == poolType )
77          {
78              eventQueue = new CacheEventQueue<K, V>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry );
79          }
80          else if ( ICacheEventQueue.QueueType.POOLED == poolType )
81          {
82              eventQueue = new PooledCacheEventQueue<K, V>( listener, listenerId, cacheName, maxFailure, waitBeforeRetry,
83                                                      threadPoolName );
84          }
85  
86          return eventQueue;
87      }
88  }