001package org.apache.commons.jcs.engine;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.commons.jcs.engine.behavior.ICacheElement;
023import org.apache.commons.jcs.engine.behavior.ICacheService;
024import org.apache.commons.jcs.engine.behavior.IZombie;
025import org.apache.commons.logging.Log;
026import org.apache.commons.logging.LogFactory;
027
028import java.io.Serializable;
029import java.util.Collections;
030import java.util.Map;
031import java.util.Set;
032
033/**
034 * Zombie adapter for any cache service. Balks at every call.
035 */
036public class ZombieCacheService<K, V>
037    implements ICacheService<K, V>, IZombie
038{
039    /** The logger. */
040    private static final Log log = LogFactory.getLog( ZombieCacheService.class );
041
042    /**
043     * @param item
044     */
045    public void put( ICacheElement<K, V> item )
046    {
047        if ( log.isDebugEnabled() )
048        {
049            log.debug( "Zombie put for item " + item );
050        }
051        // zombies have no inner life
052    }
053
054    /**
055     * Does nothing.
056     * <p>
057     * @param item
058     */
059    @Override
060    public void update( ICacheElement<K, V> item )
061    {
062        // zombies have no inner life
063    }
064
065    /**
066     * @param cacheName
067     * @param key
068     * @return null. zombies have no internal data
069     */
070    @Override
071    public ICacheElement<K, V> get( String cacheName, K key )
072    {
073        return null;
074    }
075
076    /**
077     * Returns an empty map. Zombies have no internal data.
078     * <p>
079     * @param cacheName
080     * @param keys
081     * @return Collections.EMPTY_MAP
082     */
083    @Override
084    public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys )
085    {
086        return Collections.emptyMap();
087    }
088
089    /**
090     * Returns an empty map. Zombies have no internal data.
091     * <p>
092     * @param cacheName
093     * @param pattern
094     * @return Collections.EMPTY_MAP
095     */
096    @Override
097    public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern )
098    {
099        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}