Allow to set/get an attachment on a Channel without the need of
ChannelLocal. See #101
This commit is contained in:
parent
a9a713ddcf
commit
cc761ae786
@ -57,6 +57,7 @@ public abstract class AbstractChannel implements Channel {
|
|||||||
/** Cache for the string representation of this channel */
|
/** Cache for the string representation of this channel */
|
||||||
private boolean strValConnected;
|
private boolean strValConnected;
|
||||||
private String strVal;
|
private String strVal;
|
||||||
|
private volatile Object attachment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
@ -272,6 +273,16 @@ public abstract class AbstractChannel implements Channel {
|
|||||||
return Channels.write(this, message, remoteAddress);
|
return Channels.write(this, message, remoteAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getAttachment() {
|
||||||
|
return attachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAttachment(Object attachment) {
|
||||||
|
this.attachment = attachment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link String} representation of this channel. The returned
|
* Returns the {@link String} representation of this channel. The returned
|
||||||
* string contains the {@linkplain #getId() ID}, {@linkplain #getLocalAddress() local address},
|
* string contains the {@linkplain #getId() ID}, {@linkplain #getLocalAddress() local address},
|
||||||
|
@ -362,4 +362,19 @@ public interface Channel extends Comparable<Channel> {
|
|||||||
* {@code interestOps} change request succeeds or fails
|
* {@code interestOps} change request succeeds or fails
|
||||||
*/
|
*/
|
||||||
ChannelFuture setReadable(boolean readable);
|
ChannelFuture setReadable(boolean readable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an object which is {@link #setAttachment(Object) attached} to
|
||||||
|
* this {@link Channel}.
|
||||||
|
*
|
||||||
|
* @return {@code null} if no object was attached or
|
||||||
|
* {@code null} was attached
|
||||||
|
*/
|
||||||
|
Object getAttachment();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches an object to this {@link Channel} to store a stateful information
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void setAttachment(Object attachment);
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,12 @@ import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
|
|||||||
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||||
*
|
*
|
||||||
|
* @deprecated Use {@link Channel#setAttachment(Object)} and {@link Channel#getAttachment()}
|
||||||
|
*
|
||||||
* @apiviz.stereotype utility
|
* @apiviz.stereotype utility
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class ChannelLocal<T> {
|
public class ChannelLocal<T> {
|
||||||
|
|
||||||
private final ConcurrentMap<Channel, T> map =
|
private final ConcurrentMap<Channel, T> map =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user