{"issue":{"created_at":"2011-12-07T06:52:16Z","state":"closed","updated_at":"2011-12-13T18:38:06Z","user":{"gravatar_id":"e81901854b7f5c44ddd92499fc51cacc","id":439362,"url":"https://api.github.com/users/normanmaurer","avatar_url":"https://secure.gravatar.com/avatar/e81901854b7f5c44ddd92499fc51cacc?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"normanmaurer"},"comments":16,"body":"Most users are looking for a way to assign some attachment to a Channel. At the moment they have two choices (out of the box).\r\n\r\n1) Use a shared ChannelLocal instance for this\r\n2) Use ChannelHandlerContext for this (the attachment is only visible in the ChannelHandler which belongs the the context here).\r\n\r\nChannelLocal is often not easy to spot for new-comers and also add some extra overhead because of the needed CAS semantic.\r\n\r\nWe should add methods to the Channel interface to set and get an Channel related attachment + @deprecate ChannelLocal. This will make it easier for users and also eliminate the overhead which ChannelLocal introduce.  ","assignee":{"gravatar_id":"e81901854b7f5c44ddd92499fc51cacc","id":439362,"url":"https://api.github.com/users/normanmaurer","avatar_url":"https://secure.gravatar.com/avatar/e81901854b7f5c44ddd92499fc51cacc?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"normanmaurer"},"id":2471876,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[{"name":"feature","color":"02e10c","url":"https://api.github.com/repos/netty/netty/labels/feature"},{"name":"improvement","color":"0b02e1","url":"https://api.github.com/repos/netty/netty/labels/improvement"}],"number":101,"title":"Allow to set/get attachment on Channel","closed_at":"2011-12-07T07:12:23Z","html_url":"https://github.com/netty/netty/issues/101","url":"https://api.github.com/repos/netty/netty/issues/101","milestone":{"created_at":"2011-11-16T13:42:54Z","state":"open","closed_issues":5,"due_on":null,"creator":{"gravatar_id":"9bd0a2752ec49d888172ed1effd521d8","id":173918,"url":"https://api.github.com/users/trustin","avatar_url":"https://secure.gravatar.com/avatar/9bd0a2752ec49d888172ed1effd521d8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"trustin"},"number":2,"title":"4.0.0.Alpha1","description":null,"url":"https://api.github.com/repos/netty/netty/milestones/2","open_issues":15}},"action":"created","comment":{"created_at":"2011-12-13T18:38:06Z","updated_at":"2011-12-13T18:38:06Z","user":{"gravatar_id":"c67b277b92a2be906f96b8e70105a2db","id":495438,"url":"https://api.github.com/users/rshelley","avatar_url":"https://secure.gravatar.com/avatar/c67b277b92a2be906f96b8e70105a2db?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"rshelley"},"body":"I can see Norman's point, but from a developer's perspective, a lazy create of a small HashMap would be an easier (and cleaner) implementation. \r\n\r\nMap blah = new HashMap();\r\nfoo.put(\"foo\",\"bar\");\r\nchannel.setAttachment(blah);\r\nchannel.getAttachment().get(\"foo\");\r\n\r\nas opposed to:\r\n\r\nchannel.setAttachment(\"foo\",\"bar\");\r\nchannel.getAttachment(\"foo\");\r\n\r\nThe only issue you'll see with the latter approach is type safety. I can't assume that all my attachments would be strings (as in the example above). More likely, I'll have a mix of object types. To that you could add a type parameter to getAttachment:\r\n\r\nchannel.getAttachment(\"foo\", String.class);\r\n\r\nAnd that will return null if foo doesn't exist or if foo is not a String.","id":3127318,"url":"https://api.github.com/repos/netty/netty/issues/comments/3127318"}}