Overview

Compiling CAF requires CMake and a C++11-compatible compiler. To get and compile the sources on UNIX-like systems, type the following in a terminal:

git clone https://github.com/actor-framework/actor-framework
cd actor-framework
./configure
make -C build
make -C build test [optional]
make -C build install [as root, optional]

If the output of make test indicates an error, please submit a bug report that includes (a) your compiler version, (b) your OS, and (c) the content of the file build/Testing/Temporary/LastTest.log.

The configure script provides several build options for advanced configuration. Please run ./configure -h to see all available options. If you are building CAF only as a dependency, disabling the unit tests and the examples can safe you some time during the build.

Note

The configure script provides a convenient way for creating a build directory and calling CMake. Users that are familiar with CMake can of course also use CMake directly and avoid using the configure script entirely.

On Windows, we recomment using the CMake GUI to generate a Visual Studio project file for CAF.

Features

  • Lightweight, fast and efficient actor implementations
  • Network transparent messaging
  • Error handling based on Erlang’s failure model
  • Pattern matching for messages as internal DSL to ease development
  • Thread-mapped actors for soft migration of existing applications
  • Publish/subscribe group communication

Minimal Compiler Versions

  • GCC 4.8
  • Clang 3.4
  • Visual Studio 2015, Update 3

Supported Operating Systems

  • Linux
  • Mac OS X
  • Windows (static library only)

Hello World Example

#include <string>
#include <iostream>

#include "caf/all.hpp"

using std::endl;
using std::string;

using namespace caf;

behavior mirror(event_based_actor* self) {
  // return the (initial) actor behavior
  return {
    // a handler for messages containing a single string
    // that replies with a string
    [=](const string& what) -> string {
      // prints "Hello World!" via aout (thread-safe cout wrapper)
      aout(self) << what << endl;
      // reply "!dlroW olleH"
      return string(what.rbegin(), what.rend());
    }
  };
}

void hello_world(event_based_actor* self, const actor& buddy) {
  // send "Hello World!" to our buddy ...
  self->request(buddy, std::chrono::seconds(10), "Hello World!").then(
    // ... wait up to 10s for a response ...
    [=](const string& what) {
      // ... and print it
      aout(self) << what << endl;
    }
  );
}

void caf_main(actor_system& system) {
  // create a new actor that calls 'mirror()'
  auto mirror_actor = system.spawn(mirror);
  // create another actor that calls 'hello_world(mirror_actor)';
  system.spawn(hello_world, mirror_actor);
  // system will wait until both actors are destroyed before leaving main
}

// creates a main function for us that calls our caf_main
CAF_MAIN()