Top Description Inners Fields Constructors Methods
io.netty.util

public final Class ReferenceCountUtil

extends Object
Class Inheritance
Imports
io.netty.util.internal.ObjectUtil, .StringUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory

Collection of method to handle objects that may implement ReferenceCounted.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ReferenceCountUtil.ReleasingTask

Releases the objects when the thread that called releaseLater(Object) has been terminated.

Field Summary

Modifier and TypeField and Description
private static final InternalLogger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int
refCnt(Object msg)

Returns reference count of a ReferenceCounted object.

public static boolean
release(Object msg)

Try to call ReferenceCounted#release() if the specified message implements ReferenceCounted.

public static boolean
release(Object msg, int decrement)

Try to call ReferenceCounted#release(int) if the specified message implements ReferenceCounted.

public static <T> T
releaseLater(T msg)

Deprecated this may introduce a lot of memory usage so it is generally preferable to manually release objects.
Schedules the specified object to be released when the caller thread terminates.
public static <T> T
releaseLater(T msg, int decrement)

Deprecated this may introduce a lot of memory usage so it is generally preferable to manually release objects.
Schedules the specified object to be released when the caller thread terminates.
public static <T> T
retain(T msg)

Try to call ReferenceCounted#retain() if the specified message implements ReferenceCounted.

public static <T> T
retain(T msg, int increment)

Try to call ReferenceCounted#retain(int) if the specified message implements ReferenceCounted.

public static void
safeRelease(Object msg)

Try to call ReferenceCounted#release() if the specified message implements ReferenceCounted.

public static void
safeRelease(Object msg, int decrement)

Try to call ReferenceCounted#release(int) if the specified message implements ReferenceCounted.

public static <T> T
touch(T msg)

Tries to call ReferenceCounted#touch() if the specified message implements ReferenceCounted.

public static <T> T
touch(T msg, Object hint)

Tries to call ReferenceCounted#touch(Object) if the specified message implements ReferenceCounted.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private static final InternalLogger logger

Constructor Detail

ReferenceCountUtilback to summary
private ReferenceCountUtil()

Method Detail

refCntback to summary
public static int refCnt(Object msg)

Returns reference count of a ReferenceCounted object. If object is not type of ReferenceCounted, -1 is returned.

releaseback to summary
public static boolean release(Object msg)

Try to call ReferenceCounted#release() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.

releaseback to summary
public static boolean release(Object msg, int decrement)

Try to call ReferenceCounted#release(int) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.

releaseLaterback to summary
public static <T> T releaseLater(T msg)

Deprecated

this may introduce a lot of memory usage so it is generally preferable to manually release objects.

Schedules the specified object to be released when the caller thread terminates. Note that this operation is intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the intended use case.

Annotations
@Deprecated
releaseLaterback to summary
public static <T> T releaseLater(T msg, int decrement)

Deprecated

this may introduce a lot of memory usage so it is generally preferable to manually release objects.

Schedules the specified object to be released when the caller thread terminates. Note that this operation is intended to simplify reference counting of ephemeral objects during unit tests. Do not use it beyond the intended use case.

Annotations
@Deprecated
retainback to summary
public static <T> T retain(T msg)

Try to call ReferenceCounted#retain() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.

Annotations
@SuppressWarnings:unchecked
retainback to summary
public static <T> T retain(T msg, int increment)

Try to call ReferenceCounted#retain(int) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.

Annotations
@SuppressWarnings:unchecked
safeReleaseback to summary
public static void safeRelease(Object msg)

Try to call ReferenceCounted#release() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing. Unlike release(Object) this method catches an exception raised by ReferenceCounted#release() and logs it, rather than rethrowing it to the caller. It is usually recommended to use release(Object) instead, unless you absolutely need to swallow an exception.

safeReleaseback to summary
public static void safeRelease(Object msg, int decrement)

Try to call ReferenceCounted#release(int) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing. Unlike release(Object) this method catches an exception raised by ReferenceCounted#release(int) and logs it, rather than rethrowing it to the caller. It is usually recommended to use release(Object, int) instead, unless you absolutely need to swallow an exception.

touchback to summary
public static <T> T touch(T msg)

Tries to call ReferenceCounted#touch() if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.

Annotations
@SuppressWarnings:unchecked
touchback to summary
public static <T> T touch(T msg, Object hint)

Tries to call ReferenceCounted#touch(Object) if the specified message implements ReferenceCounted. If the specified message doesn't implement ReferenceCounted, this method does nothing.

Annotations
@SuppressWarnings:unchecked
io.netty.util back to summary

private final Class ReferenceCountUtil.ReleasingTask

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Releases the objects when the thread that called releaseLater(Object) has been terminated.

Field Summary

Modifier and TypeField and Description
private final int
private final ReferenceCounted

Constructor Summary

AccessConstructor and Description
pack-priv
ReleasingTask(ReferenceCounted obj, int decrement)

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

decrementback to summary
private final int decrement
objback to summary
private final ReferenceCounted obj

Constructor Detail

ReleasingTaskback to summary
pack-priv ReleasingTask(ReferenceCounted obj, int decrement)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override