<< July 20, 2006 | Home | July 22, 2006 >>

Joost: A Simple Networking Library

The Java implementation.

Justin Michel came to the OCI internal Java lunch today to present the Java version of his Joost networking library.

First person is Justin now.

I started to work on this C++ communications library four or five years ago. I worked on several projects that could use a better higher level communications library. I worked on and off on this library. In the last six months or so I got some momentum going for the library.

The library abstracts away the socket API. It uses TCP concepts, which are presumably lower level than the socket API. However by not using the socket API, the library also becomes high level and allows the writing of high performance applications.

I gave the same talk last month on the C++ version of the library. This month I'll show the Java version. The Java version is almost the exact copy of the C++ code, with the necessary changes from C++ to Java syntax and idioms.

public class HelloClient implements TcpEvents {
...
  private void run() throws Exception {
    IpAddress addr = IpAddress.getLoopback(5555);
    MessageSizeDecoder nsMsd = null;

    TcpConnection con - new TcpConnection(addr, nsMsd, this);

    myCloser.registerForShutdown();
    myCloser.add();

    System.out.println("Sending 'Hello World' to " + addr);

    OutMessage msg - ew OutMessage();
    msg.appendAscii("Hello World");
    con.send(msg);

    myCloser.waitForShutdown();
  }

  public void onReady(TcpConnection con) {
    System.out.println("Connected to " + con);
    con.disconnect();
  }

  public void onDisconnect(TcpConnection con, DisconnectReason reason) {
    if (reason.isFinishedSending()) {
      System.out.println("Server finished sending.");
    } else {
      System.out.println("Disconnected.");
      myCloser.shutdown();
    }
  }

  public void onReceive(TcpConnection con, InMessage msg, int totalSize) {
    System.out.println("Received " + msg.getLength() + " bytes.");
  }
}

The rest of the talk is the same as the C++ version.

Design

  • Event-driven interface
  • Asynchronous only
  • No blocking calls
  • High level
  • Platform and language portability
  • Performance

Features

  • Message support
  • Delayed sends
  • Delivery by thread pool
  • Retry connects
  • Flow control
  • Auto tuning

Asynch non-blocking APIs usually don't do flow controls. Joost has flow control built in.

Uses

  • Financial applications
  • Games
  • CORBA
  • Web Services
  • DDS

Classes (com.joost)

  • ImMessage
  • OutMessage
  • IpAddress
  • TcpConnection
  • TcpEndpoint
  • MessageSizeDecoder

Compared to NIO this interface is pretty simple. It is also safer. In NIO you can easily crash your application. NIO uses Sockets and Selects which have performance and portability issues.

There are four kinds of sample applications I want to write:

  • Messages
  • Large Messages
  • Streaming
  • Messages using separators

The ultimate goal is to have Joost be used by projects that might need it. My plan has been to contribute it out to the community. But I don't want it to go out too early because the design is still fluid. As the design matures my plan is to submit it to the standards bodies: boost on the C++ side and a similar body on the Java side.

First person is Weiqi now. The Q&A went on after the talk for a while.