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    
017    package com.google.common.cache;
018    
019    import com.google.common.annotations.Beta;
020    
021    /**
022     * An object that can receive a notification when an entry is removed from a cache. The removal
023     * resulting in notification could have occured to an entry being manually removed or replaced, or
024     * due to eviction resulting from timed expiration, exceeding a maximum size, or garbage
025     * collection.
026     *
027     * <p>An instance may be called concurrently by multiple threads to process different entries.
028     * Implementations of this interface should avoid performing blocking calls or synchronizing on
029     * shared resources.
030     *
031     * @param <K> the most general type of keys this listener can listen for; for
032     *     example {@code Object} if any key is acceptable
033     * @param <V> the most general type of values this listener can listen for; for
034     *     example {@code Object} if any key is acceptable
035     * @author Charles Fry
036     * @since 10.0
037     */
038    @Beta
039    public interface RemovalListener<K, V> {
040      /**
041       * Notifies the listener that a removal occurred at some point in the past.
042       */
043      // Technically should accept RemovalNotification<? extends K, ? extends V>, but because
044      // RemovalNotification is guaranteed covariant, let's make users' lives simpler.
045      void onRemoval(RemovalNotification<K, V> notification);
046    }