## org.jboss.netty.channel
Class ChannelLocal<T>

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

    public class ChannelLocal<T>

extends Object

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.

Version:
  $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
Author:
  The Netty Project, Trustin Lee

Constructor Summary
`ChannelLocal()` Creates a `Channel` local variable.

Method Summary
`T` `get(Channel channel)` Returns the value of this variable.
`protected T` `initialValue(Channel channel)` Returns the initial value of the variable.
`T` `remove(Channel channel)` Removes the variable.
`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.

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.

### 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.

  Returns:
    the removed value. `null` if no value was set.

Copyright © 2008-2010 JBoss, a division of Red Hat, Inc.. All Rights Reserved.