views:

639

answers:

3

I'm planning on writing an RPC server in Java. The server needs to accept incoming RPCs - probably over HTTP - and answer them. Fairly basic stuff. Support for 'long polling' or 'hanging' RPCs isn't necessary, so a thread-per-request model ought to be perfectly adequate.

If I were writing this in Python, I would probably use a framework like twisted. In C, something like glibc. In each case, the framework provides an implementation of the general 'select loop' core of handling IO and invoking higher level constructs that deal with it, eventually leading to my application being called for events such as receiving an RPC.

It's a long time since I wrote anything substantial in Java, though, so I don't know what the state of the art or the suggested solutions are for this sort of thing. Possibly there's even parts of the standard library I can easily use to do this. Hence my question to StackOverflow: What frameworks are there out there that would be suitable for a task like this?

Note that although I may use HTTP for the RPCs, this is emphatically not a web application - and as such, a web framework is not appropriate.

+2  A: 

Apache MINA is a very well designed asynchronous non-blocking networking framework. It provides byte-oriented access to read and write packet data. Building atop that it has a filter system where additional layers can be added, providing things like line-oriented text parsing, encryption (via TLS), compression, etc.

PS: The 2.0 release series is highly recommended, even though it's still in "milestone" form, it's proven very stable and is nearing a final release.

Mark Renouf
This looks excellent. I'll hold off marking it as 'the' answer in case someone comes up with something even better, though. ;)
Nick Johnson
One question, though: The HTTP example they provide implements the HTTP protocol itself, and the API only seems to contain support for proxying HTTP. Do you know if there's a built-in or well-used MINA library for handling HTTP requests?
Nick Johnson
@Arachnid AsyncWeb (http://mina.apache.org/asyncweb/) is an HTTP layer built atop MINA. Though if you are indeed serving this RPC protocol over HTTP requests, then you might be better off just writing a servlet and hosting it in any of the web-app containers out there.
Mark Renouf
A better link: http://docs.safehaus.org/display/ASYNCWEB/Home See also: https://grizzly.dev.java.net/
Mark Renouf
Thanks again. I'd give you a +2 if I could. ;)
Nick Johnson
+1  A: 

You have multiple choice:

  • Roll your own solution with the existing SDK for socket programming.
  • Java RMI, the remote method invocation framework.
  • Java CORBA bindings, is no longer considered current.
  • Java Web Service frameworks, are quite complex. Look at Apache CXF and the different J2EE products.

Then you have different systems running above HTTP transport like JSON/XML-RPC where you need a Web server. Even though you rule them out.

Pierre
Why does use of JSON or XML require a web server?
Mark Renouf
I already have (most of) the wire format of the RPCs decided for me, so I'm not looking for an RPC library per-se - just a general network programming framework.
Nick Johnson
@tweakt you are right. I was specifically thinking of JSON over HTTP or XML over HTTP. That's why...
Pierre
+1  A: 

You could consider using some thing as simple as Jetty the internals of jetty are very stable and can handle quite silly number of connections. If you implement the jetty specific handler interface you can also do with out all of the servlet and JSP support libraries making it quite a small embedable app server.

Gareth Davis