Skip to content
This repository has been archived by the owner on Apr 15, 2018. It is now read-only.

Commit

Permalink
Node should leave the cluster when Constructr is terminated (closes #119
Browse files Browse the repository at this point in the history
) (#120)
  • Loading branch information
berardino authored and hseeberger committed Aug 25, 2016
1 parent d95fe5a commit 5d1470d
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package de.heikoseeberger.constructr.akka
import akka.actor.{ Actor, ActorLogging, ActorRef, Address, FSM, Props, SupervisorStrategy, Terminated }
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{ InitialStateAsEvents, MemberExited, MemberJoined, MemberLeft, MemberRemoved, MemberUp }
import akka.cluster.MemberStatus.Up
import de.heikoseeberger.constructr.coordination.Coordination
import de.heikoseeberger.constructr.machine.ConstructrMachine

Expand Down Expand Up @@ -69,9 +70,17 @@ final class Constructr private extends Actor with ActorLogging with ActorSetting
override def receive = Actor.emptyBehavior

private def active(machine: ActorRef): Receive = {
case Terminated(`machine`) =>
log.error("Terminating the system, because constructr-machine has terminated!")
context.system.terminate()
case Terminated(`machine`) => {
val cluster = Cluster(context.system)
val selfAddress = cluster.selfAddress
if (cluster.state.members.exists(member => member.address == selfAddress && member.status == Up)) {
log.error("Leaving the cluster, because constructr-machine has terminated!")
cluster.leave(selfAddress)
} else {
log.error("Terminating the system, because constructr-machine has terminated!")
context.system.terminate()
}
}

case MemberRemoved(member, _) if member.address == Cluster(context.system).selfAddress =>
log.error("Terminating the system, because member has been removed!")
Expand Down

0 comments on commit 5d1470d

Please sign in to comment.