Skip to content

Instantly share code, notes, and snippets.

@trustin
Created July 6, 2012 02:42
Show Gist options
  • Save trustin/3057755 to your computer and use it in GitHub Desktop.
Save trustin/3057755 to your computer and use it in GitHub Desktop.
public class MyHandler extends ChannelInboundMessageHandlerAdapter<MyMessage> {
private static final AttributeKey<MyState> STATE =
new AttributeKey<MyState>("MyHandler.state");
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
ctx.attr(STATE).set(new MyState());
ctx.fireChannelRegistered();
}
@Override
public void messageReceived(ChannelHandlerContext ctx, MyMessage msg) {
MyState state = ctx.attr(STATE).get();
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment