public class ChannelLocal<T> extends Object implements Iterable<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.
Constructor and Description |
---|
ChannelLocal()
|
ChannelLocal(boolean removeOnClose)
Creates a
Channel local variable. |
Modifier and Type | Method and Description |
---|---|
T |
get(Channel channel)
Returns the value of this variable.
|
protected T |
initialValue(Channel channel)
Returns the initial value of the variable.
|
Iterator<Map.Entry<Channel,T>> |
iterator()
|
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.Copyright © 2008-2013 The Netty Project. All Rights Reserved.