ainterface / ainterface   0.1

Apache License 2.0 GitHub

Runs an Erlang node on an ActorSystem of Akka.

Scala versions: 2.11

Ainterface

Build Status

Ainterface provides APIs to communicate with Erlang processes, like Jinterface. And APIs of Ainterface are designed to integrate Akka with Erlang seamlessly.

Notice

Since Ainterface is an experimental project, there is no guarantee that APIs will not be changed.

TODO

  • Published(non hidden) mode support
  • Short node names support
  • Non distributed mode support
  • Provides binary pattern matching for ByteString

Usage

Dependency

You should add the following dependency.

libraryDependencies += "com.okumin" %% "ainterface" % "0.1"

Configuration

In application.conf,

akka {
  ainterface {
    # The name of root actor of ainterface-system.
    root-name = "ainterface-system"

    init {
      # -name
      # Makes the Erlang runtime system into a distributed node and configure the name.
      name = "node-name-your-application"

      # -setcookie
      # Sets the magic cookie of the node to Cookie.
      # If `setcookie` is not specified, `$HOME/.erlang.cookie` is used.
      #setcookie = ""
    }
  }
}

Example

First, start an Erlang node and EPMD.

$ erl -name mofu
Erlang/OTP 17 [erts-6.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V6.2.1  (abort with ^G)
([email protected])1>

Set up Ainterface.

scala> val config = com.typesafe.config.ConfigFactory.parseString("""
     | akka {
     |   loglevel = "ERROR"
     |   ainterface {
     |     root-name = "ainterface-system"
     |     init.name = "ainterface-sample" // the node name
     |   }
     | }
     | """)
config: com.typesafe.config.Config = Config(SimpleConfigObject({"akka":{"ainterface":{"init":{"name":"ainterface-sample"},"root-name":"ainterface-system"},"loglevel":"ERROR"}}))

scala> val system = akka.actor.ActorSystem("sample", config)
system: akka.actor.ActorSystem = akka://sample

scala> akka.ainterface.AinterfaceSystem.init(system) // initialize

Start an echo server with the registered name echo.

scala> val echo = system.actorOf(akka.actor.Props[ainterface.EchoActor])
echo: akka.actor.ActorRef = Actor[akka://sample/user/$a#1942167954]

You can send messages from the Erlang node to Akka! The echo server returns his pid and hello message.

([email protected])1> {echo, '[email protected]'} ! {self(), hello}.
{<0.38.0>,hello}
([email protected])2> flush().
Shell got {<6209.1.0>,hello}
ok

The other examples are here.

License

Apache 2.0