O'Reilly logo

Erlang Programming by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interworking with Java

The JInterface Java package provides a high-level model of Erlang-style processes and communication in Java. You can use this package alone to give Erlang-style concurrency in Java, or you can use it as part of a mixed Java/Erlang distributed system, allowing a Java system to contain Erlang components or vice versa.

A Java package such as JInterface consists of a collection of Java classes, mostly beginning with the prefix Otp. This section will describe the most common of them, providing examples of passing messages and handling data types when communicating between Erlang and Java. You can find additional information on JInterface and its Erlang classes in the “Interface and Communication Applications” section of the Erlang/OTP documentation. The running example for this section is a rework of the remote procedure call (RPC) example in Chapter 11.

Nodes and Mailboxes

We described Erlang nodes in Chapter 11, where we also introduced distributed programming in Erlang. An Erlang node is identified by its name, which consists of an identifier with a hostname (in short or long form); each host can run a number of nodes, if their names are different.

The OtpNode class gives the JInterface representation of an Erlang node:

OtpNode bar = new OtpNode("bar");

This creates the Java object bar—which we’ll call a node—that represents the Erlang node bar, running on the host where the statement is executed.

You can create a process on this node by creating a mailbox, which is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required