001package org.apache.commons.jcs3.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 java.io.Serializable; 023import java.util.Collections; 024import java.util.Map; 025import java.util.Set; 026 027import org.apache.commons.jcs3.engine.behavior.ICacheElement; 028import org.apache.commons.jcs3.engine.behavior.ICacheService; 029import org.apache.commons.jcs3.engine.behavior.IZombie; 030import org.apache.commons.jcs3.log.Log; 031import org.apache.commons.jcs3.log.LogManager; 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 = LogManager.getLog( ZombieCacheService.class ); 041 042 /** 043 * @param item 044 */ 045 public void put( final ICacheElement<K, V> item ) 046 { 047 log.debug( "Zombie put for item {0}", item ); 048 // zombies have no inner life 049 } 050 051 /** 052 * Does nothing. 053 * <p> 054 * @param item 055 */ 056 @Override 057 public void update( final ICacheElement<K, V> item ) 058 { 059 // zombies have no inner life 060 } 061 062 /** 063 * @param cacheName 064 * @param key 065 * @return null. zombies have no internal data 066 */ 067 @Override 068 public ICacheElement<K, V> get( final String cacheName, final K key ) 069 { 070 return null; 071 } 072 073 /** 074 * Returns an empty map. Zombies have no internal data. 075 * <p> 076 * @param cacheName 077 * @param keys 078 * @return Collections.EMPTY_MAP 079 */ 080 @Override 081 public Map<K, ICacheElement<K, V>> getMultiple( final String cacheName, final Set<K> keys ) 082 { 083 return Collections.emptyMap(); 084 } 085 086 /** 087 * Returns an empty map. Zombies have no internal data. 088 * <p> 089 * @param cacheName 090 * @param pattern 091 * @return Collections.EMPTY_MAP 092 */ 093 @Override 094 public Map<K, ICacheElement<K, V>> getMatching( final String cacheName, final String pattern ) 095 { 096 return Collections.emptyMap(); 097 } 098 099 /** 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}