org.jboss.netty.channel

## Class ChannelLocal<T>

- java.lang.Object
- - org.jboss.netty.channel.ChannelLocal<T>

All Implemented Interfaces:
  Iterable<Map.Entry<Channel,T>>

    public class ChannelLocal<T>
    extends Object
    implements Iterable<Map.Entry<Channel,T>>

A global variable that is local to a `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 Summary

Constructors
Constructor and Description
`ChannelLocal()` Creates a `Channel` local variable by calling `ChannelLocal(boolean)` with `false` as parameter
`ChannelLocal(boolean removeOnClose)` Creates a `Channel` local variable.

### Method Summary

Methods
`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()` 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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ChannelLocal

    public ChannelLocal()

Creates a `Channel` local variable by calling `ChannelLocal(boolean)` with `false` as parameter

#### ChannelLocal

    public ChannelLocal(boolean removeOnClose)

Creates a `Channel` local variable.

Parameters:
  `removeOnClose` - if `true` the `ChannelLocal` will remove a `Channel` from it own once the `Channel` was closed.

### Method Detail

#### initialValue

    protected T initialValue(Channel channel)

Returns the initial value of the variable. By default, it returns `null`. Override it to change the initial value.

Parameters:
  `channel` - the channel where this local variable is accessed with

#### get

    public T get(Channel channel)

Returns the value of this variable.

#### set

    public T set(Channel channel,
        T value)

Sets the value of this variable.

Returns:
  the old value. `null` if there was no old value.

#### setIfAbsent

    public T setIfAbsent(Channel channel,
                T value)

Sets the value of this variable only when no value was set.

Returns:
  `null` if the specified value was set. An existing value if failed to set.

#### remove

    public T remove(Channel channel)

Removes the variable and returns the removed value. If no value was set, this method returns the return value of `initialValue(Channel)`, which is `null` by default.

Returns:
  the removed value. an initial value (by default `null`) if no value was set.

#### iterator

    public Iterator<Map.Entry<Channel,T>> iterator()

Returns a read-only `Iterator` that holds all `Map.Entry`'s of this ChannelLocal

Specified by:
  `iterator` in interface `Iterable<Map.Entry<Channel,T>>`