Package io.netty.util
Class AbstractReferenceCounted
- java.lang.Object
-
- io.netty.util.AbstractReferenceCounted
-
- All Implemented Interfaces:
ReferenceCounted
- Direct Known Subclasses:
AbstractDnsMessage
,AbstractHttpData
,AbstractMemcacheObject
,ArrayRedisMessage
,DefaultFileRegion
,HAProxyMessage
,InternalAttribute
,PemPrivateKey
,PemValue
public abstract class AbstractReferenceCounted extends java.lang.Object implements ReferenceCounted
Abstract base class for classes wants to implementReferenceCounted
.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<AbstractReferenceCounted>
AIF_UPDATER
private int
refCnt
private static long
REFCNT_FIELD_OFFSET
private static ReferenceCountUpdater<AbstractReferenceCounted>
updater
-
Constructor Summary
Constructors Constructor Description AbstractReferenceCounted()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
deallocate()
Called oncerefCnt()
is equals 0.private boolean
handleRelease(boolean result)
int
refCnt()
Returns the reference count of this object.boolean
release()
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.boolean
release(int decrement)
Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.ReferenceCounted
retain()
Increases the reference count by1
.ReferenceCounted
retain(int increment)
Increases the reference count by the specifiedincrement
.protected void
setRefCnt(int refCnt)
An unsafe operation intended for use by a subclass that sets the reference count of the buffer directlyReferenceCounted
touch()
Records the current access location of this object for debugging purposes.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.util.ReferenceCounted
touch
-
-
-
-
Field Detail
-
REFCNT_FIELD_OFFSET
private static final long REFCNT_FIELD_OFFSET
-
AIF_UPDATER
private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<AbstractReferenceCounted> AIF_UPDATER
-
updater
private static final ReferenceCountUpdater<AbstractReferenceCounted> updater
-
refCnt
private volatile int refCnt
-
-
Method Detail
-
refCnt
public int refCnt()
Description copied from interface:ReferenceCounted
Returns the reference count of this object. If0
, it means this object has been deallocated.- Specified by:
refCnt
in interfaceReferenceCounted
-
setRefCnt
protected final void setRefCnt(int refCnt)
An unsafe operation intended for use by a subclass that sets the reference count of the buffer directly
-
retain
public ReferenceCounted retain()
Description copied from interface:ReferenceCounted
Increases the reference count by1
.- Specified by:
retain
in interfaceReferenceCounted
-
retain
public ReferenceCounted retain(int increment)
Description copied from interface:ReferenceCounted
Increases the reference count by the specifiedincrement
.- Specified by:
retain
in interfaceReferenceCounted
-
touch
public ReferenceCounted touch()
Description copied from interface:ReferenceCounted
Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you viaResourceLeakDetector
. This method is a shortcut totouch(null)
.- Specified by:
touch
in interfaceReferenceCounted
-
release
public boolean release()
Description copied from interface:ReferenceCounted
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
release
public boolean release(int decrement)
Description copied from interface:ReferenceCounted
Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
handleRelease
private boolean handleRelease(boolean result)
-
deallocate
protected abstract void deallocate()
Called oncerefCnt()
is equals 0.
-
-