001/* 002 * Copyright (C) 2011 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.cache; 018 019import com.google.common.annotations.Beta; 020import com.google.common.annotations.GwtCompatible; 021 022/** 023 * An object that can receive a notification when an entry is removed from a cache. The removal 024 * resulting in notification could have occured to an entry being manually removed or replaced, or 025 * due to eviction resulting from timed expiration, exceeding a maximum size, or garbage 026 * collection. 027 * 028 * <p>An instance may be called concurrently by multiple threads to process different entries. 029 * Implementations of this interface should avoid performing blocking calls or synchronizing on 030 * shared resources. 031 * 032 * @param <K> the most general type of keys this listener can listen for; for 033 * example {@code Object} if any key is acceptable 034 * @param <V> the most general type of values this listener can listen for; for 035 * example {@code Object} if any key is acceptable 036 * @author Charles Fry 037 * @since 10.0 038 */ 039@Beta 040@GwtCompatible 041public interface RemovalListener<K, V> { 042 /** 043 * Notifies the listener that a removal occurred at some point in the past. 044 */ 045 // Technically should accept RemovalNotification<? extends K, ? extends V>, but because 046 // RemovalNotification is guaranteed covariant, let's make users' lives simpler. 047 void onRemoval(RemovalNotification<K, V> notification); 048}