blob: 0d75104670cc32437399c99663951108b28bbfcd [file] [log] [blame]
Jian Li29986d82016-12-01 03:25:12 +09001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.lisp.ctl.map;
17
18import java.util.Set;
19
20/**
21 * A {@link java.util.concurrent.ConcurrentMap} that supports timed entry
22 * eviction.
23 */
24public interface ExpireMap<K, V> {
25
26 /**
27 * Associates the specified value with the specified key in this map for the
28 * specified duration (optional operation). If the map previously contained
29 * a mapping for the key, the old value is replaced by the specified value.
30 *
31 * @param key key with which the specified value is to be associated
32 * @param value value to be associated with the specified key
33 * @param expireMs the maximum amount of time in ms during which the map
34 * entry should remain in the map, this can also be
35 * considered as (time-to-live: TTL) value. Note that when
36 * we assign a value of 0, the map entry will be immediately
37 * remove from the map.
38 *
39 * @throws UnsupportedOperationException if the <tt>put</tt> operation
40 * is not supported by this map
41 * @throws ClassCastException if the class of the specified key or value
42 * prevents it from being stored in this map
43 * @throws NullPointerException if the specified key or value is null
44 * and this map does not permit null keys or values
45 * @throws IllegalArgumentException if some property of the specified key
46 * or value prevents it from being stored in this map
47 */
48 void put(K key, V value, long expireMs);
49
50 /**
51 * Associates the specified value with the specified key in this map for the
52 * specified duration (optional operation). If the map previously contained
53 * a mapping for the key, the old value is replaced by the specified value.
54 * With this method, we can specify the expireMs with default value.
55 *
56 * @param key key with which the specified value is to be associated
57 * @param value value to be associated with the specified key
58 *
59 * @throws UnsupportedOperationException if the <tt>put</tt> operation
60 * is not supported by this map
61 * @throws ClassCastException if the class of the specified key or value
62 * prevents it from being stored in this map
63 * @throws NullPointerException if the specified key or value is null
64 * and this map does not permit null keys or values
65 * @throws IllegalArgumentException if some property of the specified key
66 * or value prevents it from being stored in this map
67 */
68 void put(K key, V value);
69
70 /**
71 * Returns the value to which the specified key is mapped,
72 * or {@code null} if this map contains no mapping for the key.
73 *
74 * @param key the key whose associated value is to be returned
75 * @return the value to which the specified key is mapped, or
76 * {@code null} if this map contains no mapping for the key
77 * @throws ClassCastException if the key is of an inappropriate type for
78 * this map
79 * @throws NullPointerException if the specified key is null and this map
80 * does not permit null keys
81 */
82 V get(K key);
83
84 /**
85 * Removes all of the mappings from this map (optional operation).
86 * The map will be empty after this call returns.
87 *
88 * @throws UnsupportedOperationException if the <tt>clear</tt> operation
89 * is not supported by this map
90 */
91 void clear();
92
93 /**
94 * Returns <tt>true</tt> if this map contains a mapping for the specified
95 * key. More formally, returns <tt>true</tt> if and only if
96 * this map contains a mapping for a key <tt>k</tt> such that
97 * <tt>(key==null ? k==null : key.equals(k))</tt>. (There can be
98 * at most one such mapping.)
99 *
100 * @param key key whose presence in this map is to be tested
101 * @return <tt>true</tt> if this map contains a mapping for the specified
102 * key
103 * @throws ClassCastException if the key is of an inappropriate type for
104 * this map
105 * @throws NullPointerException if the specified key is null and this map
106 * does not permit null keys
107 */
108 boolean containsKey(K key);
109
110 /**
111 * Returns a {@link Set} view of the keys contained in this map.
112 * The set is backed by the map, so changes to the map are
113 * reflected in the set, and vice-versa. If the map is modified
114 * while an iteration over the set is in progress (except through
115 * the iterator's own <tt>remove</tt> operation), the results of
116 * the iteration are undefined. The set supports element removal,
117 * which removes the corresponding mapping from the map, via the
118 * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
119 * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
120 * operations. It does not support the <tt>add</tt> or <tt>addAll</tt>
121 * operations.
122 *
123 * @return a set view of the keys contained in this map
124 */
125 Set<K> keySet();
126
127 /**
128 * Returns <tt>true</tt> if this map contains no key-value mappings.
129 *
130 * @return <tt>true</tt> if this map contains no key-value mappings
131 */
132 boolean isEmpty();
133
134 /**
135 * Removes the mapping for a key from this map if it is present
136 * (optional operation). More formally, if this map contains a mapping
137 * from key <tt>k</tt> to value <tt>v</tt> such that
138 * <code>(key==null ? k==null : key.equals(k))</code>, that mapping
139 * is removed. (The map can contain at most one such mapping.)
140 *
141 * @param key key whose mapping is to be removed from the map
142 * @return the previous value associated with <tt>key</tt>, or
143 * <tt>null</tt> if there was no mapping for <tt>key</tt>.
144 * @throws UnsupportedOperationException if the <tt>remove</tt> operation
145 * is not supported by this map
146 * @throws ClassCastException if the key is of an inappropriate type for
147 * this map
148 * @throws NullPointerException if the specified key is null and this
149 * map does not permit null keys
150 */
151 V remove(K key);
152
153 /**
154 * Returns the number of key-value mappings in this map. If the
155 * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
156 * <tt>Integer.MAX_VALUE</tt>.
157 *
158 * @return the number of key-value mappings in this map
159 */
160 int size();
161}