concept Jinterface in category erlang

appears as: Jinterface
Erlang and OTP in Action

This is an excerpt from Manning's book Erlang and OTP in Action.

You can also integrate with foreign code via the Erlang distribution mechanism. Using the Erl_Interface ei C library or the Jinterface Java library—both included in Erlang/OTP—it’s possible to create a C or Java program that masquerades as an Erlang node. To a real Erlang node (that is, an Erlang VM running in distributed mode), the foreign program looks like another node—it has a node name and communicates using the Erlang distribution protocol. But for simple tasks, making such a C node (or Java node) is usually overkill. Chapter 13 will go into detail about creating a foreign node using Jinterface.

In this chapter, we first outline how the connection to HBase will look. Then, you’ll learn how Jinterface works and implement a basic Java node example. In the rest of the chapter, you’ll build on those principles to implement a bridge between Erlang and Java, allowing you to store Erlang terms in an HBase table and retrieve them. Finally, you’ll integrate this bridge with your Simple Cache application.

13.1. Integrating Erlang with Java using Jinterface

Before we dive into HBase and the integration code, let’s first look at Jinterface. Jinterface is a library written in Java that makes the Erlang distribution layer available to Java programs. It doesn’t do this in an idiomatic Java way, but exposes the Erlang distribution model with as little modification as possible. For our purposes, coming from Erlang to Java, this is a good thing: nearly every Erlang construct has a matching Java class, from nodes and mailboxes to more granular objects like tuples and atoms. Let’s go through the most important classes and talk about how they map to Erlang.

Figure 13.1. The ultimate goal of this chapter: making it possible to use HBase tables from Simple Cache via Jinterface and the HBase Java API