passing data between ChannelHandlers
Matt DeLuco
list_usr at spacebox.net
Tue Oct 25 21:41:50 EDT 2011
I was thinking of adding session support to netty's HttpRequest.
And probably some kind of cookie object since the session manager would need
to get the session cookie when establishing the session on client connect.
I just like the way java servlets provide access to sessions and cookies
directly through the HttpServletRequest. Session management is all
transparent to the programmer. One can just get the session object via
HttpServletRequest.getSession() and use it like a Map<String,Object>.
HttpServletRequest also provides Cookie[] getCookies(). But personally I've
always been a fan of creating some kind of Map<String, Cookie> object to
deal with cookies. For example, I've created a "CookieHandler" whose
handleUpstream() method decodes the cookies, creates a CookieMap, and puts
it in a ChannelLocal for all handlers. CookieHandler's handleDownstream()
then takes the CookieMap and encodes the cookies and puts them on the
HttpResponse. All ChannelHandlers in between can get, set, and expire
cookies in the CookieMap.
I don't know if any of this is within the intended scope of netty, however.
MD
On Tue, Oct 25, 2011 at 2:28 AM, Norman Maurer <norman.maurer at googlemail.com
> wrote:
> Hi there,
>
> can you give some more details and what you try to do ?
>
> Bye,
> Norman
>
>
> 2011/10/25 Matt DeLuco <list_usr at spacebox.net>:
> > Thank you, Norman!
> > I have to say though, this all seems like a very roundabout way of
> keeping
> > track of session data for a Channel.
> > Is there any interest in adding a session interface to HttpRequest,
> > something like javax.servlet.http.HttpSession found in
> > javax.servlet.http.HttpRequest?
> > I thought if there was an interface one could implement the storage
> > mechanism - file/database/memcached, etc.
> > MD
> >
> > On Mon, Oct 24, 2011 at 6:16 AM, Norman Maurer
> > <norman.maurer at googlemail.com> wrote:
> >>
> >> Hi there,
> >>
> >> just to follow up. I committed some code to handle the removal without
> >> user interaction:
> >>
> >>
> >>
> https://issues.jboss.org/browse/NETTY-447?page=com.atlassian.jirafisheyeplugin:fisheye-issuepanel#issue-tabs
> >>
> >> So it will be in the next release...
> >>
> >> Bye
> >> Norman
> >>
> >> 2011/10/24 Norman Maurer <norman.maurer at googlemail.com>:
> >> > Hi Matt,
> >> >
> >> > comments inline..
> >> >
> >> > 2011/10/24 Matt DeLuco <list_usr at spacebox.net>:
> >> >> I found what I was looking for - a brief example of ChannelLocal is
> >> >> found in
> >> >> the ChannelHandler documentation (ps: it might be worth repeating in
> >> >> the
> >> >> ChannelLocal docs..) But now I'm wondering:
> >> >> The example shows a DataServerState class - where would that class be
> >> >> instantiated such that all handlers have access to it? I thought I
> >> >> might
> >> >> instantiate it in my server startup code, pass it to the
> >> >> ChannelPipelineFactory where I could pass it on to the constructor of
> >> >> each
> >> >> ChannelHandler. Is there another way?
> >> >
> >> > I think thats the easiest way and should work very well.
> >> >
> >> >> Also, at some point before the Channel closes would I have to be sure
> >> >> to
> >> >> remove any ChannelLocal variable references? That is, ChannelLocals
> >> >> map
> >> >> values to Channels, so would I have to be sure to remove each
> reference
> >> >> so
> >> >> values to closed Channels don't pile up, creating a memory leak? If
> >> >> so,
> >> >> how/where could I attach an event handler to a Channel to do this?
> >> >> Would I
> >> >> have to do this in a ChannelHandler (I don't like that idea, because
> >> >> which
> >> >> ChannelHandler do I put it in?) or create some kind of custom
> >> >> ChannelFactory?
> >> >
> >> > Just add an SimpleUpstreamChannelHandler and override the
> >> > channelClosed(..) method. There you can remove it.
> >> > I think it would also be nice to allow the ChannelLocal to cleanup it
> >> > self by register and ChannelListener to it that takes care of the
> >> > remove and so prevent the leak. I will open a jira issue for it and
> >> > implement it.
> >> >
> >> >
> >> >> Thanks.
> >> >> MD
> >> >>
> >> >> On Fri, Oct 21, 2011 at 3:36 AM, Norman Maurer
> >> >> <norman.maurer at googlemail.com> wrote:
> >> >>>
> >> >>> I was using it before in a project but remoted it in favor of
> >> >>> ChannelHandlerContext.setAttachment(..).
> >> >>>
> >> >>> But it worked quited fine for me. You can see the old code here:
> >> >>>
> >> >>>
> >> >>>
> >> >>>
> http://svn.apache.org/viewvc/james/protocols/tags/protocols-1.5/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelUpstreamHandler.java?view=markup
> >> >>>
> >> >>> Bye,
> >> >>> Norman
> >> >>>
> >> >>> Ps: What does not work for you ?
> >> >>>
> >> >>> 2011/10/21 Matt DeLuco <list_usr at spacebox.net>:
> >> >>> > Where can I find some examples of ChannelLocal in use?
> >> >>> > I'm not getting the results I expect, but I don't think I'm using
> it
> >> >>> > correctly either.
> >> >>> > MD
> >> >>> >
> >> >>> > On Sun, Oct 16, 2011 at 7:14 AM, Norman Maurer
> >> >>> > <norman.maurer at googlemail.com> wrote:
> >> >>> >>
> >> >>> >> You can set anything you want as attachment. But it's only
> visible
> >> >>> >> in
> >> >>> >> the same handler....
> >> >>> >>
> >> >>> >> If you want to share stuff between handler you should checkout
> >> >>> >> ChannelLocal
> >> >>> >>
> >> >>> >> Bye
> >> >>> >> Norman
> >> >>> >> 2011/10/16, Matt DeLuco <list_usr at spacebox.net>:
> >> >>> >> > Before composing this message I had noticed
> >> >>> >> > ChannelHandlerContext.setAttachment(Object) and
> getAttachment().
> >> >>> >> > But
> >> >>> >> > for some reason I came to the conclusion that it wasn't
> intended
> >> >>> >> > for
> >> >>> >> > what I want to do.
> >> >>> >> >
> >> >>> >> > I came to that conclusion in part because I found it strange
> that
> >> >>> >> > it's
> >> >>> >> > only possible to set one attachment, rather than being able to
> >> >>> >> > attach
> >> >>> >> > a set (or map) of objects. Could I just attach a map to the
> >> >>> >> > context
> >> >>> >> > and store whatever I want in that map, to pass objects between
> >> >>> >> > ChannelHandlers?
> >> >>> >> >
> >> >>> >> > MD
> >> >>> >> >
> >> >>> >> >
> >> >>> >> > On Sat, Oct 15, 2011 at 9:42 PM, Matt DeLuco
> >> >>> >> > <list_usr at spacebox.net>
> >> >>> >> > wrote:
> >> >>> >> >> Is it possible to pass data between ChannelHandlers, or store
> >> >>> >> >> data
> >> >>> >> >> somewhere that the handlers in a specific pipeline/channel can
> >> >>> >> >> access
> >> >>> >> >> throughout the lifetime of the request?
> >> >>> >> >>
> >> >>> >> >> For example, I have my own class for dealing with http
> cookies,
> >> >>> >> >> "CookieMap". I'd like to have a SimpleChannelHandler that
> >> >>> >> >> creates a
> >> >>> >> >> CookieMap to be used by handlers further upstream, and then
> sets
> >> >>> >> >> the
> >> >>> >> >> cookies in the CookieMap on the response on their way back
> >> >>> >> >> downstream.
> >> >>> >> >>
> >> >>> >> >> MD
> >> >>> >> >>
> >> >>> >> >
> >> >>> >> > _______________________________________________
> >> >>> >> > netty-users mailing list
> >> >>> >> > netty-users at lists.jboss.org
> >> >>> >> > https://lists.jboss.org/mailman/listinfo/netty-users
> >> >>> >> >
> >> >>> >> _______________________________________________
> >> >>> >> netty-users mailing list
> >> >>> >> netty-users at lists.jboss.org
> >> >>> >> https://lists.jboss.org/mailman/listinfo/netty-users
> >> >>> >
> >> >>> >
> >> >
> >> > Bye,
> >> > Norman
> >> >
> >>
> >> _______________________________________________
> >> netty-users mailing list
> >> netty-users at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/netty-users
> >
> >
> > _______________________________________________
> > netty-users mailing list
> > netty-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/netty-users
> >
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20111025/9db8eddb/attachment-0001.html
More information about the netty-users
mailing list