本文整理汇总了Scala中akka.cluster.MemberStatus类的典型用法代码示例。如果您正苦于以下问题:Scala MemberStatus类的具体用法?Scala MemberStatus怎么用?Scala MemberStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemberStatus类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ClusterDomainEventListener
//设置package包名称以及导入依赖的类
package akka_in_action.cluster
import akka.actor.{Actor, ActorLogging}
import akka.cluster.{Cluster, MemberStatus}
import akka.cluster.ClusterEvent._
class ClusterDomainEventListener extends Actor
with ActorLogging {
Cluster(context.system).subscribe(self, classOf[ClusterDomainEvent])
def receive = {
case MemberUp(member) => log.info(s"$member UP.")
case MemberExited(member) => log.info(s"$member EXITED")
case MemberRemoved(member, previousStatus) => {
if(previousStatus == MemberStatus.exiting) {
log.info(s"Member $member gracefully exited, REMOVED")
} else {
log.info(s"$member downed after unreachable, REMOVED")
}
}
case UnreachableMember(member) => log.info(s"$member UNREACHABLE")
case state: CurrentClusterState => log.info(s"Cluster state: $state")
}
override def postStop(): Unit = {
Cluster(context.system).unsubscribe(self)
super.postStop()
}
}
示例2: preStart
//设置package包名称以及导入依赖的类
package it.agilelab.bigdata.wasp.core.cluster
import akka.actor.{Actor, ActorLogging}
import akka.cluster.{Metric, NodeMetrics, Cluster}
import akka.cluster.ClusterEvent._
import akka.cluster.Member
import akka.cluster.MemberStatus
override def preStart(): Unit = cluster.subscribe(self, classOf[ClusterDomainEvent])
override def postStop(): Unit = cluster.unsubscribe(self)
def receive: Actor.Receive = {
case MemberUp(member) =>
onMemberUp(member)
case UnreachableMember(member) =>
onUnreachableMember(member)
case MemberRemoved(member, previousStatus) =>
onMemberRemoved(member, previousStatus)
case ClusterMetricsChanged(forNode) =>
forNode collectFirst {
case m if m.address == cluster.selfAddress =>
log.debug("{}", filter(m.metrics))
}
case _: MemberEvent =>
}
def filter(nodeMetrics: Set[Metric]): String = {
val filtered = nodeMetrics collect { case v if v.name != "processors" => s"${v.name}:${v.value}" }
s"NodeMetrics[${filtered.mkString(",")}]"
}
def onMemberUp(member: Member) = log.info("Member {} joined cluster.", member.address)
def onUnreachableMember(member: Member) = log.info("Member detected as unreachable: {}", member)
def onMemberRemoved(member: Member, previousStatus: MemberStatus) = log.info("Member is Removed: {} after {}", member.address, previousStatus)
}
示例3: BackendActor
//设置package包名称以及导入依赖的类
package com.example
import akka.actor.{Actor, ActorLogging, RootActorPath}
import akka.cluster.ClusterEvent.{CurrentClusterState, MemberUp}
import akka.cluster.{Cluster, Member, MemberStatus}
class BackendActor extends Actor with ActorLogging {
val cluster = Cluster(context.system)
override def preStart(): Unit = {
cluster.subscribe(self, classOf[MemberUp])
}
override def postStop(): Unit = {
cluster.unsubscribe(self)
}
override def receive: Receive = {
case state: CurrentClusterState =>
log.info("receive current cluster state")
state.members.filter(_.status == MemberStatus.Up).foreach(register)
case MemberUp(member) =>
log.info("register new member")
register(member)
case string: String =>
log.info(string)
}
def register(member: Member): Unit = {
if (member.hasRole("frontend")) {
context.actorSelection(RootActorPath(member.address) / "user" / "Frontend") ! "Register"
}
}
}
示例4:
//设置package包名称以及导入依赖的类
package smarthouse.restapi.http.ws
import java.net.URI
import java.time.OffsetDateTime
import akka.cluster.MemberStatus
import org.json4s.CustomSerializer
import org.json4s.JsonAST.JString
trait JsonSerializers {
val memberStatusSerializer = new CustomSerializer[MemberStatus](format => ( {
case JString("Exiting") => MemberStatus.Exiting
case JString("Up") => MemberStatus.Up
case JString("Joining") => MemberStatus.Joining
case JString("Leaving") => MemberStatus.Leaving
case JString("Removed") => MemberStatus.Removed
case JString("Down") => MemberStatus.Down
}, {
case x: MemberStatus =>
JString(x.toString)
}
))
val uriSerializer = new CustomSerializer[URI](format => ( {
case JString(string) => new URI(string)
}, {
case x: URI =>
JString(x.toString)
}
))
val offsetDateTime = new CustomSerializer[OffsetDateTime](format => ( {
case JString(string) => OffsetDateTime.parse(string)
}, {
case x: OffsetDateTime =>
JString(x.toLocalDateTime.toString)
}
))
}
示例5: ChannelCluster
//设置package包名称以及导入依赖的类
package org.cg.spark.databroker
import akka.actor.ActorLogging
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.CurrentClusterState
import akka.actor.Address
import akka.cluster.ClusterEvent.MemberUp
import akka.cluster.ClusterEvent.MemberRemoved
import akka.cluster.ClusterEvent.MemberEvent
import akka.actor.Actor
import akka.cluster.MemberStatus
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
import akka.actor.Props
import scala.util.Try
import java.io.File
class ChannelCluster extends Actor with ActorLogging {
val cluster = Cluster(context.system)
override def preStart(): Unit = {
cluster.subscribe(self, classOf[ChannelCluster])
}
override def postStop() = {
cluster unsubscribe (self)
}
var nodes = Set.empty[Address]
def receive = {
case state: CurrentClusterState =>
nodes = state.members.collect {
case m if m.status == MemberStatus.Up => m.address
}
case MemberUp(member) =>
nodes += member.address
log.info("Member is Up: {}. {} nodes in cluster",
member.address, nodes.size)
case MemberRemoved(member, _) =>
nodes -= member.address
log.info("Member is Removed: {}. {} nodes cluster",
member.address, nodes.size)
case _: MemberEvent => // ignore
}
}
示例6: QuorumLeaderAutoDownBase
//设置package包名称以及导入依赖的类
package tanukki.akka.cluster.autodown
import akka.actor.Address
import akka.cluster.{MemberStatus, Member}
import akka.cluster.MemberStatus.Down
import scala.concurrent.duration.FiniteDuration
abstract class QuorumLeaderAutoDownBase(quorumRole: Option[String], quorumSize: Int, downIfOutOfQuorum: Boolean, autoDownUnreachableAfter: FiniteDuration)
extends QuorumAwareCustomAutoDownBase(quorumSize, autoDownUnreachableAfter) {
override def onLeaderChanged(leader: Option[Address]): Unit = {
if (quorumRole.isEmpty && isLeader) downPendingUnreachableMembers()
}
override def onRoleLeaderChanged(role: String, leader: Option[Address]): Unit = {
quorumRole.foreach { r =>
if (r == role && isRoleLeaderOf(r)) downPendingUnreachableMembers()
}
}
override def onMemberRemoved(member: Member, previousStatus: MemberStatus): Unit = {
if (isQuorumMet(quorumRole)) {
if (isLeaderOf(quorumRole)) {
downPendingUnreachableMembers()
}
} else {
down(selfAddress)
}
super.onMemberRemoved(member, previousStatus)
}
override def downOrAddPending(member: Member): Unit = {
if (isLeaderOf(quorumRole)) {
down(member.address)
replaceMember(member.copy(Down))
} else {
pendingAsUnreachable(member)
}
}
override def downOrAddPendingAll(members: Set[Member]): Unit = {
if (isQuorumMetAfterDown(members, quorumRole)) {
members.foreach(downOrAddPending)
} else if (downIfOutOfQuorum) {
shutdownSelf()
}
}
}
示例7: ClusterDomainEventListener
//设置package包名称以及导入依赖的类
package aia.cluster.words
import akka.actor.{ActorLogging, Actor}
import akka.cluster.{MemberStatus, Cluster}
import akka.cluster.ClusterEvent._
class ClusterDomainEventListener extends Actor
with ActorLogging {
Cluster(context.system).subscribe(self, classOf[ClusterDomainEvent])
def receive ={
case MemberUp(member) =>
log.info(s"$member UP.")
case MemberExited(member)=>
log.info(s"$member EXITED.")
case MemberRemoved(member, previousState)=>
if(previousState == MemberStatus.Exiting) {
log.info(s"Member $member Previously gracefully exited, REMOVED.")
} else {
log.info(s"$member Previously downed after unreachable, REMOVED.")
}
case UnreachableMember(member) =>
log.info(s"$member UNREACHABLE")
case ReachableMember(member) =>
log.info(s"$member REACHABLE")
case state: CurrentClusterState =>
log.info(s"Current state of the cluster: $state")
}
override def postStop(): Unit = {
Cluster(context.system).unsubscribe(self)
super.postStop()
}
}
示例8: ClusterMembership
//设置package包名称以及导入依赖的类
package demo
import akka.actor.{Actor, ActorLogging, Props}
import akka.cluster.ClusterEvent._
import akka.cluster.{Member, Cluster, MemberStatus}
import scala.collection.immutable.SortedSet
object ClusterMembership {
def props(cluster: Cluster) = Props(new ClusterMembership(cluster))
}
class ClusterMembership(cluster: Cluster) extends Actor with ActorLogging {
override def preStart = {
cluster.subscribe(self, classOf[ClusterDomainEvent])
}
private def evolve(clusterMembers: SortedSet[Member]): Receive = {
case MemberUp(member) =>
log.info("MemberUp = {}", member.address)
context become (evolve(clusterMembers + member))
case MemberExited(member) =>
log.info("MemberExited = {}", member.address)
case ReachableMember(member) =>
log.info("ReachableMember = {}", member.address)
case UnreachableMember(member) =>
log.info("UnreachableMember = {}", member.address)
case MemberRemoved(member, prev) =>
if (prev == MemberStatus.Exiting) log.info("{} gracefully exited", member.address)
else log.info("{} downed after being Unreachable", member.address)
context become evolve(clusterMembers - member)
case state: CurrentClusterState =>
log.info("Cluster state = {}", state.members)
context become evolve(state.members)
case 'Members =>
sender() ! clusterMembers.mkString(",")
}
override def receive = evolve(SortedSet[Member]())
}
示例9: UserListener
//设置package包名称以及导入依赖的类
package de.chasmo.chat
import akka.actor._
import akka.cluster.{Cluster, MemberStatus}
import akka.cluster.ClusterEvent.{CurrentClusterState, MemberEvent, MemberRemoved, MemberUp}
class UserListener extends Actor with ActorLogging {
val cluster = Cluster(context.system)
override def preStart(): Unit =
cluster.subscribe(self, classOf[MemberEvent])
override def postStop(): Unit =
cluster unsubscribe self
var nodes = Set.empty[Address]
def receive = {
case state: CurrentClusterState =>
nodes = state.members.collect {
case m if m.status == MemberStatus.Up => m.address
}
case MemberUp(member) =>
nodes += member.address
log.info("Member is Up: {}. {} nodes in cluster",
member.address, nodes.size)
case MemberRemoved(member, _) =>
nodes -= member.address
log.info("Member is Removed: {}. {} nodes cluster",
member.address, nodes.size)
case _: MemberEvent => // ignore
}
}
object UserListener {
def props: Props = Props(classOf[UserListener])
}
示例10: ClusterDomainEventListener
//设置package包名称以及导入依赖的类
package de.codecentric.gatling.cluster
import akka.actor.{ActorLogging, Actor}
import akka.cluster.{MemberStatus, Cluster}
import akka.cluster.ClusterEvent._
class ClusterDomainEventListener extends Actor
with ActorLogging {
Cluster(context.system).subscribe(self, classOf[ClusterDomainEvent])
def receive = {
case MemberUp(member) =>
log.info(s"$member UP.")
case MemberExited(member) =>
log.info(s"$member EXITED.")
case MemberRemoved(member, previousState) =>
if (previousState == MemberStatus.Exiting) {
log.info(s"Member $member Previously gracefully exited, REMOVED.")
} else {
log.info(s"$member Previously downed after unreachable, REMOVED.")
}
case UnreachableMember(member) =>
log.info(s"$member UNREACHABLE")
case ReachableMember(member) =>
log.info(s"$member REACHABLE")
case state: CurrentClusterState =>
log.info(s"Current state of the cluster: $state")
}
override def postStop(): Unit = {
Cluster(context.system).unsubscribe(self)
super.postStop()
}
}
示例11: AlcaudonClient
//设置package包名称以及导入依赖的类
package org.alcaudon.api
import akka.actor.{Actor, ActorLogging, ActorSelection, RootActorPath}
import akka.cluster.ClusterEvent.{CurrentClusterState, MemberUp}
import akka.cluster.{Cluster, Member, MemberStatus}
import org.alcaudon.core.{ActorConfig, DataflowGraph}
object AlcaudonClient {
case class RegisterDataflowJob(dataflow: DataflowGraph)
case object UnknownCoordinator
}
class AlcaudonClient extends Actor with ActorLogging with ActorConfig {
import AlcaudonClient._
val cluster = Cluster(context.system)
override def preStart(): Unit = cluster.subscribe(self, classOf[MemberUp])
override def postStop(): Unit = cluster.unsubscribe(self)
var coordinator: Option[ActorSelection] = None
def receive = receiveCoordinatorNode
def receiveCoordinatorNode: Receive = {
case state: CurrentClusterState =>
val coordinator = state.members
.filter(member =>
member.status == MemberStatus.Up && member.hasRole("coordinator"))
.map(getCoordinatorNodePath)
if (coordinator.size == 1)
context.become(receiveWithCoordinator(coordinator.head))
case MemberUp(member) =>
if (member.hasRole("coordinator"))
context.become(receiveWithCoordinator(getCoordinatorNodePath(member)))
case _ =>
sender() ! UnknownCoordinator
}
def receiveWithCoordinator(coordinator: ActorSelection): Receive = {
case request: RegisterDataflowJob =>
coordinator ! request
}
def getCoordinatorNodePath(member: Member): ActorSelection =
context.actorSelection(
RootActorPath(member.address) / "user" / "coordinator")
}