2010-09-30

Java-Erlang Bridging

...couple of relevant resources on this matter...
Java and Erlang are not mutually exclusive, they complement each other. I personally have learned to embrace both because very few complex business problems can be modeled exclusively from an object oriented or functional paradigm. The solutions to these problems can be sequential or concurrent. Jinterface can cleanly divide (and conquer) a system into parts suitable for Java and parts suitable for Erlang.
There are two basic mechanisms for communicating with Erlang, described briefly here. Note that the two mechanisms are not intended to be used together. Which mechanism you choose depends on your application and the level of control it needs.

You can use OtpNode, which can manage incoming and outgoing connections for you. With OtpNode a thread is automatically started to listen for incoming connections, make necessary outgoing connections, and dispatch messages to their recipients. OtpNode supports the concept of mailboxes, allowing you to have several Java components communicating independently with Erlang.

If you need more control (but less support from the library), you can manage connections yourself using the OtpSelf and OtpConnection classes, in which case you can control explicitly which connections are made and which messages are sent. Received messages are not dispatched by OtpConnection.

The classes OtpPeer, OtpSelf and OtpServer are used to represent OTP nodes and are neccessary in order to set up communication between the Java thread and a remote node. Once a connection has been established, it is represented by an OtpConnection, through which all communication goes.

No comments: