public class ChannelLocal<T> extends java.lang.Object implements java.lang.Iterable<java.util.Map.Entry<Channel,T>>
Channel. Think of this as a
variation of ThreadLocal whose key is a Channel rather than
a Thread.currentThread(). One difference is that you always have to
specify the Channel to access the variable.
Alternatively, you might want to use the
ChannelHandlerContext.attachment
property, which performs better.
| 构造器和说明 |
|---|
ChannelLocal()
|
ChannelLocal(boolean removeOnClose)
Creates a
Channel local variable. |
| 限定符和类型 | 方法和说明 |
|---|---|
T |
get(Channel channel)
Returns the value of this variable.
|
protected T |
initialValue(Channel channel)
Returns the initial value of the variable.
|
java.util.Iterator<java.util.Map.Entry<Channel,T>> |
iterator()
Returns a read-only
Iterator that holds all Map.Entry's of this ChannelLocal |
T |
remove(Channel channel)
Removes the variable and returns the removed value.
|
T |
set(Channel channel,
T value)
Sets the value of this variable.
|
T |
setIfAbsent(Channel channel,
T value)
Sets the value of this variable only when no value was set.
|
public ChannelLocal()
public ChannelLocal(boolean removeOnClose)
Channel local variable.removeOnClose - if true the ChannelLocal will remove a
Channel from it own once the Channel was closed.protected T initialValue(Channel channel)
null. Override it to change the initial value.channel - the channel where this local variable is accessed withpublic T set(Channel channel, T value)
null if there was no old value.public T setIfAbsent(Channel channel, T value)
null if the specified value was set.
An existing value if failed to set.public T remove(Channel channel)
initialValue(Channel),
which is null by default.null) if no value was set.