17

Has anyone made a Servlet API implementation built on top of Netty? I'm tempted to build my own as I can't google an implementation.

Basically I'm looking to support just enough to get jersey working (hopefully jersey is not doing any threadlocal stuff).

skaffman
  • 398,947
  • 96
  • 818
  • 769
Adam Gent
  • 47,843
  • 23
  • 153
  • 203
  • @Adam, as I understand Netty is generic Java NIO Client Server Socket Framework - Its mainly for writing network apps in java. (http://www.jboss.org/netty/community#nabble-td4918947) Can you a bit more specific about why you would need Servlet API for Netty and why existing servers like Jetty/Tomcat are not addressing your needs ? – Santosh Sep 16 '11 at 06:46
  • 3
    @Santosh The hope is to break away from the existing paradigm of one thread per request. One thread per request does not scale that well compared to an event io queue. – Adam Gent Sep 16 '11 at 10:38

4 Answers4

18

Jersey does not require servlet - runs fine even with the lightweight http server included in JDK or even runs with Grizzly NIO framework (which is similar to Netty - see grizzly.java.net). To see what it takes to make it run with Netty, you may want to look at jersey-grizzly2 module in Jersey workspace - would be nice if you would be willing to develop that and contribute to the Jersey project. Now, to disappoint you, Jersey does use ThreadLocals. We have been planning to introduce support for non-blocking async calls, but that requires a fair amount of refactoring, so will only come with 2.0 version (implementing JAX-RS 2.0 once that's final). Anyway, apart from the non-blocking stuff, it is still useful to run it on Grizzly-like framework such as Netty for its "light-weightness".

Martin Matula
  • 7,969
  • 1
  • 31
  • 35
  • Thanks! I look to see if I can contribute in anyway. – Adam Gent Sep 19 '11 at 13:44
  • Maybe I can use this for the threadlocals: https://issues.jboss.org/browse/NETTY-93 – Adam Gent Sep 19 '11 at 22:30
  • Hi Adam, that's right - we are planning to take advantage of a similar thing in Grizzly and potentially other frameworks eventually. The thing is, this requires Jersey core libs refactoring - it is not just a question of writing a Netty plugin. That's why we likely won't take care of it before Jersey 2.0. – Martin Matula Sep 20 '11 at 19:40
  • So the real question: is the Grizzly NIO integration actually safe since Jersey is using ThreadLocals? – Matt Wonlaw Jun 04 '13 at 23:20
  • Only Jersey 1.x faces this issue, and yes, it is safe, since it processes the requests synchronously - i.e. does not take advantage of the non-blocking features of Grizzly. – Martin Matula Jun 22 '13 at 16:01
4

If you want use Jersey with Netty, you probably need to be safe and use org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory

not,

org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory

This will allow the ThreadLocal stuff work correctly under load.

Of course, when Jersey upgrades to not use ThreadLocal, but ChannelLocal, this will not longer be needed.

Sastrija
  • 3,284
  • 6
  • 47
  • 64
Bob Stiles
  • 41
  • 1
2

If you want to get Jersey working with Netty you can use the bindings available at https://github.com/cgbystrom/jersey-netty

cgbystrom
  • 1,927
  • 1
  • 14
  • 11
1

Do you looking for Netty-Servlet-bridge?

This project provides a Servlet API implementation for Netty.IO framework (http://netty.io/).

Netty Servlet Bridge allows integration of existing Servlet API based web-applications into the Netty-backed infrastructure.

Community
  • 1
  • 1
Anton Bessonov
  • 9,208
  • 3
  • 35
  • 38