• Stars
    star
    56
  • Rank 514,128 (Top 11 %)
  • Language
    Scala
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library to register and lookup actors by names in an Akka cluster

Glokka = Global + Akka

Glokka is a Scala library that allows you to register and lookup actors by names in an Akka cluster. See:

Glokka is used in Xitrum to implement its distributed SockJS feature.

See Glokka's Scaladoc.

SBT

libraryDependencies += "tv.cntt" %% "glokka" % "2.6.1"

Create registry

import akka.actor.ActorSystem
import glokka.Registry

val system    = ActorSystem("MyClusterSystem")
val proxyName = "my proxy name"
val registry  = Registry.start(system, proxyName)
  • You can start multiple registry actors. They must have different proxyName.
  • For convenience, proxyName can be any String, you don't have to URI-escape it.

Register actor by props

// For convenience, ``actorName`` can be any String, you don't have to URI-escape it.
val actorName = "my actor name"

// Props to create the actor you want to register.
val props = ...

registry ! Registry.Register(actorName, props)

If the named actor exists, the registry will just return it. You will receive:

Registry.Found(actorName, actorRef)

Otherwise props will be used to create the actor locally (when the actor dies, it will be unregistered automatically). You will receive:

Registry.Created(actorName, actorRef)

If you don't need to differentiate Found and Created:

registry ! Registry.Register(actorName, props)
context.become {
  case msg: Registry.FoundOrCreated =>
    val actorName = msg.name
    val actorRef  = msg.ref
}

Register actor by ref

registry ! Registry.Register(actorName, actorRefToRegister)

If the actor has not been registered, or has already been registered with the same name, you will receive:

Registry.Registered(actorName, actorRef)

Otherwise if there's another actor that has been registered with the name, you will receive:

Registry.Conflict(actorName, otherActorRef, actorRefToRegister)

In this case, you may need to stop actorRefToRegister, depending on your application logic.

Lookup actor by name

Send:

registry ! Registry.Lookup(actorName)

You will receive:

Registry.Found(actorName, actorRef)

Or:

Registry.NotFound(actorName)

Tell

If you don't want to lookup and keep the actor reference:

registry ! Registry.Tell(actorName, msg)
registry ! Registry.Tell(actorName, props, msg)
  • If the named actor exists, msg will be sent to it.
  • Otherwise, props will be used to create the named actor, and msg will be sent to it.

Cluster

Glokka can run in Akka non-cluster mode (local or remote). While developing, you can run Akka in local mode, then later config Akka to run in cluster mode.

In cluster mode, Glokka uses Akka's Cluster Singleton Pattern to maintain an actor that stores the name -> actorRef lookup table.

Akka config file for a node should look like config_example/application.conf (note MyClusterSystem in the source code example above and in the config file).

More Repositories

1

xitrum

Async and clustered Scala web framework and HTTP(S) server
Scala
447
star
2

scalive

Connect a Scala REPL to running JVM processes without any prior setup
Java
198
star
3

scaposer

GNU Gettext .po file loader for Scala
Scala
38
star
4

scala-xgettext

Scala compiler plugin that acts like GNU xgettext command to extract i18n strings in Scala source code files to Gettext .po file
Scala
25
star
5

xitrum-new

Empty Xitrum project skeleton, like the one created by "rails new"
Scala
21
star
6

xitrum-demos

Demos for Xitrum
Scala
19
star
7

xitrum-package

SBT plugin for collecting dependency .jar files for standalone Scala programs
Scala
18
star
8

comy

Simple URL shortener using Xitrum and MongoDB
Scala
16
star
9

sclasner

Scala classpath scanner
Scala
10
star
10

xitrum-doc

Xitrum Guide Book and presentations about Xitrum
CSS
8
star
11

RhinoCoffeeScript

coffee-script.js precompiled to JVM .class file by Rhino
Java
7
star
12

agent7

Java agent to reload .class files; it uses file watch API available in Java 7+
Java
5
star
13

xitrum-scalate

Template engine for Xitrum based on Scalate
Scala
4
star
14

xitrum-hazelcast

Cache and server side session store for Xitrum, based on Hazelcast
Scala
3
star
15

xitrum-multimodule-demo

http://groups.google.com/group/xitrum-framework/browse_thread/thread/7588995934854a56
Scala
2
star
16

xitrum-ko

Knockout.js plugin for Xitrum
Scala
1
star
17

xitrum-scalatags

Template engine for Xitrum based on ScalaTags
Scala
1
star
18

xitrum-tictactoe

Tictactoe web game - Demo for Akka and Xitrum
Scala
1
star
19

xitrum-framework.github.io

Source code of the home page of Xitrum framework
HTML
1
star