001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel;
018    
019    /**
020     * Represents a map of values which timeout after a period of inactivity.
021     *
022     * @version 
023     */
024    public interface TimeoutMap<K, V> extends Runnable {
025    
026        /**
027         * Looks up the value in the map by the given key.
028         *
029         * @param key the key of the value to search for
030         * @return the value for the given key or <tt>null</tt> if it is not present (or has timed out)
031         */
032        V get(K key);
033    
034        /**
035         * Returns a copy of the keys in the map
036         *
037         * @return the keys
038         */
039        Object[] getKeys();
040    
041        /**
042         * Returns the size of the map
043         *
044         * @return the size
045         */
046        int size();
047    
048        /**
049         * Adds the key value pair into the map such that some time after the given
050         * timeout the entry will be evicted
051         *
052         * @param key   the key
053         * @param value the value
054         * @param timeoutMillis  timeout in millis
055         */
056        void put(K key, V value, long timeoutMillis);
057    
058        /**
059         * Callback when the value has been evicted
060         *
061         * @param key the key
062         * @param value the value
063         * @return <tt>true</tt> to remove the evicted value,
064         *         or <tt>false</tt> to veto the eviction and thus keep the value.
065         */
066        boolean onEviction(K key, V value);
067    
068        /**
069         * Removes the object with the given key
070         *
071         * @param key  key for the object to remove
072         * @return the value for the given key or <tt>null</tt> if it is not present (or has timed out)
073         */
074        V remove(K key);
075    
076        /**
077         * Purges any old entries from the map
078         */
079        void purge();
080    }