HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-common / src / main / java / org / apache / hadoop / hbase / nio / RefCnt.java
blob018c8b44ef4f630b84d264d112933055cbe45b1f
1 /**
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.nio;
20 import org.apache.hadoop.hbase.io.ByteBuffAllocator;
21 import org.apache.hadoop.hbase.io.ByteBuffAllocator.Recycler;
22 import org.apache.yetus.audience.InterfaceAudience;
24 import org.apache.hbase.thirdparty.io.netty.util.AbstractReferenceCounted;
25 import org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted;
27 /**
28 * Maintain an reference count integer inside to track life cycle of {@link ByteBuff}, if the
29 * reference count become 0, it'll call {@link Recycler#free()} exactly once.
31 @InterfaceAudience.Private
32 public class RefCnt extends AbstractReferenceCounted {
34 private Recycler recycler = ByteBuffAllocator.NONE;
36 /**
37 * Create an {@link RefCnt} with an initial reference count = 1. If the reference count become
38 * zero, the recycler will do nothing. Usually, an Heap {@link ByteBuff} will use this kind of
39 * refCnt to track its life cycle, it help to abstract the code path although it's not really
40 * needed to track on heap ByteBuff.
42 public static RefCnt create() {
43 return new RefCnt(ByteBuffAllocator.NONE);
46 public static RefCnt create(Recycler recycler) {
47 return new RefCnt(recycler);
50 public RefCnt(Recycler recycler) {
51 this.recycler = recycler;
54 @Override
55 protected final void deallocate() {
56 this.recycler.free();
59 @Override
60 public final ReferenceCounted touch(Object hint) {
61 throw new UnsupportedOperationException();