Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
Jian Li | 5e505c6 | 2016-12-05 02:44:24 +0900 | [diff] [blame] | 16 | package org.onosproject.lisp.ctl.impl.map; |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 17 | |
Jian Li | e530690 | 2016-12-09 00:09:46 +0900 | [diff] [blame] | 18 | import java.util.Collection; |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 19 | import java.util.Set; |
| 20 | |
| 21 | /** |
| 22 | * A {@link java.util.concurrent.ConcurrentMap} that supports timed entry |
| 23 | * eviction. |
| 24 | */ |
| 25 | public interface ExpireMap<K, V> { |
| 26 | |
| 27 | /** |
| 28 | * Associates the specified value with the specified key in this map for the |
| 29 | * specified duration (optional operation). If the map previously contained |
| 30 | * a mapping for the key, the old value is replaced by the specified value. |
| 31 | * |
| 32 | * @param key key with which the specified value is to be associated |
| 33 | * @param value value to be associated with the specified key |
| 34 | * @param expireMs the maximum amount of time in ms during which the map |
| 35 | * entry should remain in the map, this can also be |
| 36 | * considered as (time-to-live: TTL) value. Note that when |
| 37 | * we assign a value of 0, the map entry will be immediately |
| 38 | * remove from the map. |
| 39 | * |
| 40 | * @throws UnsupportedOperationException if the <tt>put</tt> operation |
| 41 | * is not supported by this map |
| 42 | * @throws ClassCastException if the class of the specified key or value |
| 43 | * prevents it from being stored in this map |
| 44 | * @throws NullPointerException if the specified key or value is null |
| 45 | * and this map does not permit null keys or values |
| 46 | * @throws IllegalArgumentException if some property of the specified key |
| 47 | * or value prevents it from being stored in this map |
| 48 | */ |
| 49 | void put(K key, V value, long expireMs); |
| 50 | |
| 51 | /** |
| 52 | * Associates the specified value with the specified key in this map for the |
| 53 | * specified duration (optional operation). If the map previously contained |
| 54 | * a mapping for the key, the old value is replaced by the specified value. |
| 55 | * With this method, we can specify the expireMs with default value. |
| 56 | * |
| 57 | * @param key key with which the specified value is to be associated |
| 58 | * @param value value to be associated with the specified key |
| 59 | * |
| 60 | * @throws UnsupportedOperationException if the <tt>put</tt> operation |
| 61 | * is not supported by this map |
| 62 | * @throws ClassCastException if the class of the specified key or value |
| 63 | * prevents it from being stored in this map |
| 64 | * @throws NullPointerException if the specified key or value is null |
| 65 | * and this map does not permit null keys or values |
| 66 | * @throws IllegalArgumentException if some property of the specified key |
| 67 | * or value prevents it from being stored in this map |
| 68 | */ |
| 69 | void put(K key, V value); |
| 70 | |
| 71 | /** |
| 72 | * Returns the value to which the specified key is mapped, |
| 73 | * or {@code null} if this map contains no mapping for the key. |
| 74 | * |
| 75 | * @param key the key whose associated value is to be returned |
| 76 | * @return the value to which the specified key is mapped, or |
| 77 | * {@code null} if this map contains no mapping for the key |
| 78 | * @throws ClassCastException if the key is of an inappropriate type for |
| 79 | * this map |
| 80 | * @throws NullPointerException if the specified key is null and this map |
| 81 | * does not permit null keys |
| 82 | */ |
| 83 | V get(K key); |
| 84 | |
| 85 | /** |
| 86 | * Removes all of the mappings from this map (optional operation). |
| 87 | * The map will be empty after this call returns. |
| 88 | * |
| 89 | * @throws UnsupportedOperationException if the <tt>clear</tt> operation |
| 90 | * is not supported by this map |
| 91 | */ |
| 92 | void clear(); |
| 93 | |
| 94 | /** |
| 95 | * Returns <tt>true</tt> if this map contains a mapping for the specified |
| 96 | * key. More formally, returns <tt>true</tt> if and only if |
| 97 | * this map contains a mapping for a key <tt>k</tt> such that |
| 98 | * <tt>(key==null ? k==null : key.equals(k))</tt>. (There can be |
| 99 | * at most one such mapping.) |
| 100 | * |
| 101 | * @param key key whose presence in this map is to be tested |
| 102 | * @return <tt>true</tt> if this map contains a mapping for the specified |
| 103 | * key |
| 104 | * @throws ClassCastException if the key is of an inappropriate type for |
| 105 | * this map |
| 106 | * @throws NullPointerException if the specified key is null and this map |
| 107 | * does not permit null keys |
| 108 | */ |
| 109 | boolean containsKey(K key); |
| 110 | |
| 111 | /** |
| 112 | * Returns a {@link Set} view of the keys contained in this map. |
| 113 | * The set is backed by the map, so changes to the map are |
| 114 | * reflected in the set, and vice-versa. If the map is modified |
| 115 | * while an iteration over the set is in progress (except through |
| 116 | * the iterator's own <tt>remove</tt> operation), the results of |
| 117 | * the iteration are undefined. The set supports element removal, |
| 118 | * which removes the corresponding mapping from the map, via the |
| 119 | * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>, |
| 120 | * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> |
| 121 | * operations. It does not support the <tt>add</tt> or <tt>addAll</tt> |
| 122 | * operations. |
| 123 | * |
| 124 | * @return a set view of the keys contained in this map |
| 125 | */ |
| 126 | Set<K> keySet(); |
| 127 | |
| 128 | /** |
Jian Li | e530690 | 2016-12-09 00:09:46 +0900 | [diff] [blame] | 129 | * Returns a {@link Collection} view of the values contained in this map. |
| 130 | * The collection is backed by the map, so changes to the map are |
| 131 | * reflected in the collection, and vice-versa. If the map is |
| 132 | * modified while an iteration over the collection is in progress |
| 133 | * (except through the iterator's own <tt>remove</tt> operation), |
| 134 | * the results of the iteration are undefined. The collection |
| 135 | * supports element removal, which removes the corresponding |
| 136 | * mapping from the map, via the <tt>Iterator.remove</tt>, |
| 137 | * <tt>Collection.remove</tt>, <tt>removeAll</tt>, |
| 138 | * <tt>retainAll</tt> and <tt>clear</tt> operations. It does not |
| 139 | * support the <tt>add</tt> or <tt>addAll</tt> operations. |
| 140 | * |
| 141 | * @return a collection view of the values contained in this map |
| 142 | */ |
| 143 | Collection<V> values(); |
| 144 | |
| 145 | /** |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 146 | * Returns <tt>true</tt> if this map contains no key-value mappings. |
| 147 | * |
| 148 | * @return <tt>true</tt> if this map contains no key-value mappings |
| 149 | */ |
| 150 | boolean isEmpty(); |
| 151 | |
| 152 | /** |
| 153 | * Removes the mapping for a key from this map if it is present |
| 154 | * (optional operation). More formally, if this map contains a mapping |
| 155 | * from key <tt>k</tt> to value <tt>v</tt> such that |
| 156 | * <code>(key==null ? k==null : key.equals(k))</code>, that mapping |
| 157 | * is removed. (The map can contain at most one such mapping.) |
| 158 | * |
| 159 | * @param key key whose mapping is to be removed from the map |
| 160 | * @return the previous value associated with <tt>key</tt>, or |
| 161 | * <tt>null</tt> if there was no mapping for <tt>key</tt>. |
| 162 | * @throws UnsupportedOperationException if the <tt>remove</tt> operation |
| 163 | * is not supported by this map |
| 164 | * @throws ClassCastException if the key is of an inappropriate type for |
| 165 | * this map |
| 166 | * @throws NullPointerException if the specified key is null and this |
| 167 | * map does not permit null keys |
| 168 | */ |
| 169 | V remove(K key); |
| 170 | |
| 171 | /** |
| 172 | * Returns the number of key-value mappings in this map. If the |
| 173 | * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns |
| 174 | * <tt>Integer.MAX_VALUE</tt>. |
| 175 | * |
| 176 | * @return the number of key-value mappings in this map |
| 177 | */ |
| 178 | int size(); |
| 179 | } |