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.ICacheElement;
23  import org.apache.commons.jcs.engine.behavior.ICacheService;
24  import org.apache.commons.jcs.engine.behavior.IZombie;
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  
28  import java.io.Serializable;
29  import java.util.Collections;
30  import java.util.Map;
31  import java.util.Set;
32  
33  /**
34   * Zombie adapter for any cache service. Balks at every call.
35   */
36  public class ZombieCacheService<K, V>
37      implements ICacheService<K, V>, IZombie
38  {
39      /** The logger. */
40      private static final Log log = LogFactory.getLog( ZombieCacheService.class );
41  
42      /**
43       * @param item
44       */
45      public void put( ICacheElement<K, V> item )
46      {
47          if ( log.isDebugEnabled() )
48          {
49              log.debug( "Zombie put for item " + item );
50          }
51          // zombies have no inner life
52      }
53  
54      /**
55       * Does nothing.
56       * <p>
57       * @param item
58       */
59      @Override
60      public void update( ICacheElement<K, V> item )
61      {
62          // zombies have no inner life
63      }
64  
65      /**
66       * @param cacheName
67       * @param key
68       * @return null. zombies have no internal data
69       */
70      @Override
71      public ICacheElement<K, V> get( String cacheName, K key )
72      {
73          return null;
74      }
75  
76      /**
77       * Returns an empty map. Zombies have no internal data.
78       * <p>
79       * @param cacheName
80       * @param keys
81       * @return Collections.EMPTY_MAP
82       */
83      @Override
84      public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys )
85      {
86          return Collections.emptyMap();
87      }
88  
89      /**
90       * Returns an empty map. Zombies have no internal data.
91       * <p>
92       * @param cacheName
93       * @param pattern
94       * @return Collections.EMPTY_MAP
95       */
96      @Override
97      public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern )
98      {
99          return Collections.emptyMap();
100     }
101 
102     /**
103      * Logs the get to debug, but always balks.
104      * <p>
105      * @param cacheName
106      * @param key
107      * @param container
108      * @return null always
109      */
110     public Serializable get( String cacheName, K key, boolean container )
111     {
112         if ( log.isDebugEnabled() )
113         {
114             log.debug( "Zombie get for key [" + key + "] cacheName [" + cacheName + "] container [" + container + "]" );
115         }
116         // zombies have no inner life
117         return null;
118     }
119 
120     /**
121      * @param cacheName
122      * @param key
123      */
124     @Override
125     public void remove( String cacheName, K key )
126     {
127         // zombies have no inner life
128     }
129 
130     /**
131      * @param cacheName
132      */
133     @Override
134     public void removeAll( String cacheName )
135     {
136         // zombies have no inner life
137     }
138 
139     /**
140      * @param cacheName
141      */
142     @Override
143     public void dispose( String cacheName )
144     {
145         // zombies have no inner life
146     }
147 
148     /**
149      * Frees all caches.
150      */
151     @Override
152     public void release()
153     {
154         // zombies have no inner life
155     }
156 }