View Javadoc
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 java.util.concurrent.ConcurrentHashMap;
23  import java.util.concurrent.ConcurrentMap;
24  
25  import org.apache.commons.jcs3.engine.behavior.ICache;
26  import org.apache.commons.jcs3.engine.behavior.ICacheEventQueue;
27  
28  /**
29   * Used to associates a set of [cache listener to cache event queue] for a
30   * cache.
31   */
32  public class CacheListeners<K, V>
33  {
34      /** The cache using the queue. */
35      public final ICache<K, V> cache;
36  
37      /** Map ICacheListener to ICacheEventQueue */
38      public final ConcurrentMap<Long, ICacheEventQueue<K, V>> eventQMap =
39          new ConcurrentHashMap<>();
40  
41      /**
42       * Constructs with the given cache.
43       * <p>
44       * @param cache
45       */
46      public CacheListeners( final ICache<K, V> cache )
47      {
48          if ( cache == null )
49          {
50              throw new IllegalArgumentException( "cache must not be null" );
51          }
52          this.cache = cache;
53      }
54  
55      /** @return info on the listeners */
56      @Override
57      public String toString()
58      {
59          final StringBuilder buffer = new StringBuilder();
60          buffer.append( "\n CacheListeners" );
61          buffer.append( "\n Region = " + cache.getCacheName() );
62          buffer.append( "\n Event Queue Map " );
63          buffer.append( "\n size = " + eventQMap.size() );
64          eventQMap.forEach((key, value)
65                  -> buffer.append( "\n Entry: key: ").append(key)
66                      .append(", value: ").append(value));
67          return buffer.toString();
68      }
69  }