001/*
002 * Copyright (C) 2010 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.collect;
018
019import com.google.common.annotations.Beta;
020
021import javax.annotation.Nullable;
022
023/**
024 * An object that can receive a notification when an entry is evicted from a
025 * map.
026 *
027 * <p>An instance may be called concurrently by multiple threads to process
028 * different entries. Implementations of this interface should avoid performing
029 * blocking calls or synchronizing on shared resources.
030 *
031 * @param <K> the type of keys being evicted
032 * @param <V> the type of values being evicted
033 * @author Ben Manes
034 * @since 7
035 */
036@Beta
037public interface MapEvictionListener<K, V> {
038
039  /**
040   * Notifies the listener that an eviction has occurred. Eviction may be for
041   * reasons such as timed expiration, exceeding a maximum size, or due to
042   * garbage collection. Eviction notification does <i>not</i> occur due to
043   * manual removal.
044   *
045   * @param key the key of the entry that has already been evicted, or {@code
046   *     null} if its reference was collected
047   * @param value the value of the entry that has already been evicted, or
048   *     {@code null} if its reference was collected
049   */
050  void onEviction(@Nullable K key, @Nullable V value);
051}