2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.util
;
20 import java
.lang
.ref
.Reference
;
21 import java
.lang
.ref
.SoftReference
;
23 import org
.apache
.yetus
.audience
.InterfaceAudience
;
26 * A {@code SoftReference} based shared object pool.
27 * The objects are kept in soft references and
28 * associated with keys which are identified by the {@code equals} method.
29 * The objects are created by ObjectFactory on demand.
30 * The object creation is expected to be lightweight,
31 * and the objects may be excessively created and discarded.
34 @InterfaceAudience.Private
35 public class SoftObjectPool
<K
, V
> extends ObjectPool
<K
, V
> {
37 public SoftObjectPool(ObjectFactory
<K
, V
> objectFactory
) {
41 public SoftObjectPool(ObjectFactory
<K
, V
> objectFactory
, int initialCapacity
) {
42 super(objectFactory
, initialCapacity
);
45 public SoftObjectPool(ObjectFactory
<K
, V
> objectFactory
, int initialCapacity
,
46 int concurrencyLevel
) {
47 super(objectFactory
, initialCapacity
, concurrencyLevel
);
51 public Reference
<V
> createReference(K key
, V obj
) {
52 return new SoftObjectReference(key
, obj
);
55 private class SoftObjectReference
extends SoftReference
<V
> {
58 SoftObjectReference(K key
, V obj
) {
59 super(obj
, staleRefQueue
);
65 public K
getReferenceKey(Reference
<V
> ref
) {
66 return ((SoftObjectReference
) ref
).key
;