Protected
Protected

Cluster Membership


Module stability: IN PROGRESS

Akka supports a Cluster Membership through a JGroups based implementation. JGroups is is a P2P clustering API

Configuration


The cluster is configured in 'akka.conf' by adding the Fully Qualified Name (FQN) of the actor class and serializer:

...
<remote>
  <cluster>
    service = on
    name = "default"                                                       # The name of the cluster
    serializer = "se.scalablesolutions.akka.serialization.Serializer$Java" # FQN of the serializer class
  </cluster>
  ...
</remote>
...

How to join the cluster


The node joins the cluster when the 'RemoteNode' and/or 'RemoteServer' servers are started.

Cluster API


Interaction with the cluster is done through the 'se.scalablesolutions.akka.remote.Cluster' object.

To send a message to all actors of a specific type on other nodes in the cluster use the 'relayMessage' function:

def relayMessage(to: Class[_ <: Actor], msg: AnyRef): Unit

Here is an example:

Cluster.relayMessage(classOf[ATypeOfActor], message)

Traversing the remote nodes in the cluster to spawn remote actors:

Cluster.foreach:

def foreach(f : (RemoteAddress) => Unit) : Unit
 

Here's an example:

for(endpoint <- Cluster) spawnRemote[KungFuActor](endpoint.hostname,endpoint.port)

and:

Cluster.foreach( endpoint => spawnRemote[KungFuActor](endpoint.hostname,endpoint.port) )


Cluster.lookup:

def lookup[T](handleRemoteAddress : PartialFunction[RemoteAddress, T]) : Option[T]

Here is an example:

val myRemoteActor: Option[SomeActorType] = Cluster.lookup({
  case RemoteAddress(hostname, port) => spawnRemote[SomeActorType](hostname, port)
})
 
myRemoteActor.foreach(remoteActor => ...)

Here is another example:

Cluster.lookup({
  case remoteAddress @ RemoteAddress(_,_) => remoteAddress
}) match {
  case Some(remoteAddress) => spawnAllRemoteActors(remoteAddress)
  case None =>                handleNoRemoteNodeFound
}
Home
close
Loading...
Home Turn Off "Getting Started"
close
Loading...