Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 16 | package org.onlab.util; |
| 17 | |
| 18 | import java.util.concurrent.ConcurrentHashMap; |
| 19 | import java.util.concurrent.ConcurrentMap; |
| 20 | |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 21 | import org.apache.commons.lang3.concurrent.ConcurrentInitializer; |
| 22 | |
| 23 | /** |
| 24 | * Creates an instance of new ConcurrentHashMap on each {@link #get()} call. |
| 25 | * <p> |
| 26 | * To be used with |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 27 | * {@link org.apache.commons.lang3.concurrent.ConcurrentUtils#createIfAbsent} |
| 28 | * </p> |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 29 | * |
| 30 | * @param <K> ConcurrentHashMap key type |
| 31 | * @param <V> ConcurrentHashMap value type |
Yuta HIGUCHI | c2e6815 | 2016-08-16 13:47:36 -0700 | [diff] [blame] | 32 | * |
| 33 | * @deprecated in Hummingbird (1.7.0) |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 34 | */ |
Yuta HIGUCHI | c2e6815 | 2016-08-16 13:47:36 -0700 | [diff] [blame] | 35 | @Deprecated |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 36 | public final class NewConcurrentHashMap<K, V> |
Sho SHIMIZU | d5c8ba1 | 2016-08-15 11:08:08 -0700 | [diff] [blame] | 37 | implements ConcurrentInitializer<ConcurrentMap<K, V>> { |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 38 | |
| 39 | public static final NewConcurrentHashMap<?, ?> INSTANCE = new NewConcurrentHashMap<>(); |
| 40 | |
| 41 | @SuppressWarnings("unchecked") |
| 42 | public static <K, V> NewConcurrentHashMap<K, V> ifNeeded() { |
| 43 | return (NewConcurrentHashMap<K, V>) INSTANCE; |
| 44 | } |
| 45 | |
| 46 | @Override |
Yuta HIGUCHI | e66d10e | 2014-10-14 16:06:13 -0700 | [diff] [blame] | 47 | public ConcurrentMap<K, V> get() { |
Yuta HIGUCHI | 39ede6a | 2014-10-03 15:23:33 -0700 | [diff] [blame] | 48 | return new ConcurrentHashMap<>(); |
| 49 | } |
| 50 | } |