1/* 2 * Copyright (C) 2011 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.common.cache; 18 19import com.google.common.annotations.Beta; 20 21/** 22 * An object that can receive a notification when an entry is removed from a cache. The removal 23 * resulting in notification could have occured to an entry being manually removed or replaced, or 24 * due to eviction resulting from timed expiration, exceeding a maximum size, or garbage 25 * collection. 26 * 27 * <p>An instance may be called concurrently by multiple threads to process different entries. 28 * Implementations of this interface should avoid performing blocking calls or synchronizing on 29 * shared resources. 30 * 31 * @param <K> the most general type of keys this listener can listen for; for 32 * example {@code Object} if any key is acceptable 33 * @param <V> the most general type of values this listener can listen for; for 34 * example {@code Object} if any key is acceptable 35 * @author Charles Fry 36 * @since 10.0 37 */ 38@Beta 39public interface RemovalListener<K, V> { 40 /** 41 * Notifies the listener that a removal occurred at some point in the past. 42 */ 43 // Technically should accept RemovalNotification<? extends K, ? extends V>, but because 44 // RemovalNotification is guaranteed covariant, let's make users' lives simpler. 45 void onRemoval(RemovalNotification<K, V> notification); 46} 47