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