    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
    017    package com.google.common.collect;
    018
    019    import com.google.common.annotations.Beta;
    020
    021    import java.util.concurrent.Executor;
    022
    023    import javax.annotation.Nullable;
    024
    025    /**
    026     * A collection of common eviction listeners.
    027     *
    028     * @author Charles Fry
    029     * @since 7.0
    030     * @deprecated Caching functionality in {@code MapMaker} is being moved to
    031     *     {@link com.google.common.cache.CacheBuilder}. Functionality similar to
    032     *     {@code EvictionListeners} is provided by {@link
    033     *     com.google.common.cache.RemovalListeners}. <b>This class is scheduled for
    034     *     deletion from Guava in Guava release 11.0.</b>
    035     */
    036    @Beta
    037    @Deprecated
    038    public
    039    final class EvictionListeners {
    040
    041      private EvictionListeners() {}
    042
    043      /**
    044       * Returns an asynchronous {@code MapEvictionListener} which processes all
    045       * eviction notifications asynchronously, using {@code executor}.
    046       *
    047       * @param listener the backing listener
    048       * @param executor the executor with which eviciton notifications are
    049       *     asynchronously executed
    050       * @deprecated Caching functionality in {@code MapMaker} is being moved to
    051       *     {@link com.google.common.cache.CacheBuilder}. Functionality similar to
    052       *     {@code EvictionListeners#asynchronous} is provided by
    053       *     {@link com.google.common.cache.RemovalListeners#asynchronous}.
    054       *     <b>This method is scheduled for deletion from Guava in Guava release 11.0.</b>
    055       */
    056      @Deprecated
    057      public static <K, V> MapEvictionListener<K, V> asynchronous(
    058          final MapEvictionListener<K, V> listener, final Executor executor) {
    059        return new MapEvictionListener<K, V>() {
    060          @Override
    061          public void onEviction(@Nullable final K key, @Nullable final V value) {
    062            executor.execute(new Runnable() {
    063              @Override
    064              public void run() {
    065                listener.onEviction(key, value);
    066              }
    067            });
    068          }
    069        };
    070      }
    071
    072    }