• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala UnreachableMember类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中akka.cluster.ClusterEvent.UnreachableMember的典型用法代码示例。如果您正苦于以下问题:Scala UnreachableMember类的具体用法?Scala UnreachableMember怎么用?Scala UnreachableMember使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了UnreachableMember类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Registration

//设置package包名称以及导入依赖的类
package com.bob.scalatour.akka.cluster

import akka.actor.{ActorPath, ActorRef, Actor}
import akka.cluster.{Member, Cluster}
import akka.cluster.ClusterEvent.{MemberEvent, UnreachableMember, MemberUp, InitialStateAsEvents}

object Registration extends Serializable

trait EventMessage extends Serializable

case class RawNginxRecord(sourceHost: String, line: String) extends EventMessage

case class NginxRecord(sourceHost: String, eventCode: String, line: String) extends EventMessage

case class FilteredRecord(sourceHost: String, eventCode: String, line: String, logDate: String, realIp: String) extends EventMessage

abstract class ClusterRoledWorker extends Actor {

  // ????Cluster??
  val cluster = Cluster(context.system)
  // ????????????
  var workers = IndexedSeq.empty[ActorRef]

  @throws[Exception](classOf[Exception])
  override def preStart(): Unit = {
    super.preStart()
    // ??????
    cluster.subscribe(self, initialStateMode = InitialStateAsEvents, classOf[MemberUp], classOf[UnreachableMember], classOf[MemberEvent])
  }

  @throws[Exception](classOf[Exception])
  override def postStop(): Unit = {
    cluster.unsubscribe(self)
    super.postStop()
  }

  def register(member: Member, createPath: (Member) => ActorPath): Unit = {
    val actorPath = createPath(member)
    println("Actor path: " + actorPath)
    val actorSelection = context.actorSelection(actorPath)
    actorSelection ! Registration
  }

}

 
开发者ID:bobxwang,项目名称:scalatour,代码行数:45,代码来源:ClusterWorker.scala


示例2: ComputeActor

//设置package包名称以及导入依赖的类
package hk.edu.polyu.datamining.pamap2.actor

import java.util.concurrent.TimeUnit

import akka.actor._
import akka.cluster.ClusterEvent.{InitialStateAsEvents, MemberEvent, UnreachableMember}
import hk.edu.polyu.datamining.pamap2.Main
import hk.edu.polyu.datamining.pamap2.actor.MessageProtocol.{ComputeNodeHeartBeat, DispatcherHeartBeat, RequestNodeInfo}
import hk.edu.polyu.datamining.pamap2.actor.MessageProtocolFactory.NodeInfo
import hk.edu.polyu.datamining.pamap2.database.DatabaseHelper
import hk.edu.polyu.datamining.pamap2.utils.Lang._

import scala.collection.mutable
import scala.concurrent.ExecutionContext.Implicits._
import scala.concurrent.duration.Duration


object ComputeActor {
  lazy val numberOfWorker = {
    val x = Main.config.getInt("compute.number_of_worker")
    if (x > 0) x else Runtime.getRuntime.availableProcessors()
  }
}

class ComputeActor extends CommonActor {
  val workers = mutable.Set.empty[ActorRef]
  var lastTimeDispatcherHeartBeat: Long = System.currentTimeMillis()

  override def preStart = {
    // init worker pool
    for (i <- 0 until ComputeActor.numberOfWorker) {
      log info s"start worker - $i"
      workers += context.actorOf(Props[WorkerActor])
    }
    // set repeat timer to report resources
    context.system.scheduler.schedule(Duration.Zero,
      Duration.create(ActorUtils.ReportInterval, TimeUnit.MILLISECONDS), self, ComputeNodeHeartBeat)

    //    cluster.subscribe(self,initialStateMode = InitialStateAsEvents,
    //      classOf[MemberEvent],classOf[UnreachableMember])
  }

  override def postStop = {
    SingletonActor.Dispatcher.proxy ! MessageProtocol.UnRegisterComputeNode(DatabaseHelper.clusterSeedId)
    workers.foreach(context.stop)
    workers.retain(_ => false)
  }

  override def receive: Receive = {
    case ComputeNodeHeartBeat => SingletonActor.Dispatcher.proxy ! NodeInfo.newInstance(system)
      if (lastTimeDispatcherHeartBeat < getMargin)
        workers.foreach(_ ! MessageProtocol.ReBindDispatcher)
    case DispatcherHeartBeat => lastTimeDispatcherHeartBeat = System.currentTimeMillis()
    case RequestNodeInfo => SingletonActor.Dispatcher.proxy ! NodeInfo.newInstance(context.system)

    case msg => showError(s"Unsupported msg : $msg")
  }

} 
开发者ID:polyu-datamining-2016,项目名称:data-mining-pamap2,代码行数:60,代码来源:ComputeActor.scala


示例3: Main

//设置package包名称以及导入依赖的类
package hu.jonas.client

import akka.actor.{Actor, ActorLogging, ActorPath, ActorSystem, Props}
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{InitialStateAsEvents, MemberEvent, MemberUp, UnreachableMember}
import akka.cluster.client.{ClusterClient, ClusterClientSettings}
import com.typesafe.config.ConfigFactory
import hu.jonas.cluster.ClusterController

object Main extends App {

  val system = ActorSystem("Cluster", ConfigFactory.load("client"))

  val client = system.actorOf(Props[Client], "Proxy")
}

class Client extends Actor with ActorLogging {

  val cluster = Cluster(context.system)

  val initialContacts = Set(
    ActorPath.fromString("akka.tcp://[email protected]:2551/system/receptionist"))

  val setting = ClusterClientSettings(context.system).withInitialContacts(initialContacts)
  val client = context.system.actorOf(ClusterClient.props(setting), "Client")

  def send(msg: Any): Unit = {
      client ! ClusterClient.Send("/user/Controller", msg, localAffinity = true)
  }

  override def preStart() = {
    cluster.subscribe(self, initialStateMode = InitialStateAsEvents,
      classOf[MemberEvent], classOf[UnreachableMember])
  }

  override def postStop() = {
    cluster.unsubscribe(self)
  }

  def receive = {
    case MemberUp(member) =>
      log.info("Member is up")
      send(ClusterController.Status)
    case msg @ _ =>
      log.info(s"Got message $msg")
  }
} 
开发者ID:jonasrichard,项目名称:simple-cluster,代码行数:48,代码来源:Client.scala


示例4: ReducerRequest

//设置package包名称以及导入依赖的类
package com.rikima.mr.akka

import akka.actor.{Props, Actor, ActorLogging}
import akka.cluster.ClusterEvent.{MemberEvent, MemberRemoved, UnreachableMember, MemberUp}



case class ReducerRequest(data: String)
case class ReducerResponse(data: String)

object Reducers {
  def props(start_id: Int, num: Int): Props = Props(new Reducers(start_id, num))
}

class Reducers(start_id: Int, num: Int = 2) extends Actor {
  (0 until num).foreach {
    case c =>
      val id = start_id + c
      val a = context.actorOf(Props[Reducer], name=s"r$id")
      println(s"reducer actor: $a")
  }

  def receive = {
    case message =>
      println(message)
  }
}

class Reducer extends Actor with ActorLogging {
  override def preStart = {
    log.debug(Thread.currentThread.getName + " is started.")
  }


  override def postStop = {
    log.debug(Thread.currentThread.getName + " is stopped.")
  }


  def receive = {
    case MemberUp(member) =>
      log.info("Member is Up: {}", member.address)

    case UnreachableMember(member) =>
      log.info("Member detected as unreachable: {}", member)

    case MemberRemoved(member, previousStatus) =>
      log.info("Member is Removed: {} after {}",
        member.address, previousStatus)

    case ReducerRequest(data) => {
      log.info(s"reduce($data")
      sender ! ReducerResponse(data)
    }
    case _: MemberEvent => // ignore
  }
} 
开发者ID:rikima,项目名称:akka_mr,代码行数:58,代码来源:Reducer.scala


示例5: MapperResponse

//设置package包名称以及导入依赖的类
package com.rikima.mr.akka

import akka.actor.{Props, Actor, ActorLogging}
import akka.cluster.ClusterEvent.{MemberEvent, MemberRemoved, UnreachableMember, MemberUp}


case class MapperResponse(data: String)
case class MapperRequest(data: String)

object Mappers {
  def props(start_id: Int, num: Int): Props = Props(new Mappers(start_id, num))
}

class Mappers(start_id: Int, num: Int = 2) extends Actor {
  (0 until num).foreach {
    case c =>
      val id = start_id + c
      val a = context.actorOf(Props[Mapper], name=s"m$id")
      println(s"mapper actor: $a")
  }

  def receive = {
    case message =>
      println(message)
  }
}

class Mapper extends Actor with ActorLogging {


  override def preStart = {
    log.debug(Thread.currentThread.getName + " is started.")
  }


  override def postStop = {
    log.debug(Thread.currentThread.getName + " is stopped.")
  }


  def receive = {
    case MemberUp(member) =>
      log.info("Member is Up: {}", member.address)

    case UnreachableMember(member) =>
      log.info("Member detected as unreachable: {}", member)

    case MemberRemoved(member, previousStatus) =>
      log.info("Member is Removed: {} after {}",
        member.address, previousStatus)

    case MapperRequest(data) =>
      log.info(s"MapperRequest($data)")
      sender ! MapperResponse(data)

    case _: MemberEvent => // ignore
  }
} 
开发者ID:rikima,项目名称:akka_mr,代码行数:59,代码来源:Mapper.scala


示例6: ClusterController

//设置package包名称以及导入依赖的类
package com.dazito.scala.dakkabase.exceptions

import akka.actor.Actor
import akka.actor.Actor.Receive
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{MemberEvent, UnreachableMember}
import akka.event.Logging


class ClusterController extends Actor {

    val log = Logging(context.system, this)
    val cluster = Cluster(context.system)

    @scala.throws[Exception](classOf[Exception])
    override def preStart(): Unit = {
        cluster.subscribe(self, classOf[MemberEvent], classOf[UnreachableMember])
    }

    @scala.throws[Exception](classOf[Exception])
    override def postStop(): Unit = {
        cluster.unsubscribe(self)
    }

    override def receive: Receive = {
        case x: MemberEvent => log.info("MemberEvent: {}", x)
        case x: UnreachableMember => log.info("UnreachableMember: {}", x)
    }
} 
开发者ID:dazito,项目名称:LearningAkkaScalaServer,代码行数:30,代码来源:ClusterController.scala


示例7: ServerActor

//设置package包名称以及导入依赖的类
package com.juanjo.akka.encrypt.actors

import akka.actor._
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{MemberEvent, MemberUp, UnreachableMember}
import com.juanjo.akka.encrypt.common.domain.SecureMessage
import com.juanjo.akka.encrypt.config.ServerConfig
import org.apache.log4j.Logger

object ServerActor {
  def props(cluster: Cluster): Props = Props(new ServerActor(cluster))

}


class ServerActor(cluster:Cluster) extends Actor with ServerConfig  {
  lazy val logger = Logger.getLogger(classOf[ServerActor])

  override def preStart(): Unit = {
    super.preStart()
    cluster.subscribe(self, classOf[MemberEvent])

  }

  def receive: Receive = {
    case SecureMessage(p) => logger.info(s"******Secure message from a client: $p")
    case MemberUp(member) => logger.info(s"******New Member is up: $member")
    case UnreachableMember(member) =>logger.info(s"*******Unreachable member: $member")
  }
} 
开发者ID:jjlopezm,项目名称:AkkaEncrypt,代码行数:31,代码来源:ServerActor.scala


示例8: ClusterController

//设置package包名称以及导入依赖的类
package com.akkadb.actors

import akka.actor.Actor
import akka.cluster.Cluster
import akka.cluster.ClusterEvent.{UnreachableMember, MemberEvent}
import akka.event.Logging


class ClusterController extends Actor {
  val log = Logging(context.system, this)
  val cluster = Cluster(context.system)

  override def preStart() {
    cluster.subscribe(self, classOf[MemberEvent], classOf[UnreachableMember])
  }

  override def postStop() {
    cluster.unsubscribe(self)
  }

  override def receive = {
    case x: MemberEvent => log.info("MemberEvent: {}", x)
    case x: UnreachableMember => log.info("UnreachableMember {}: ", x)
  }
} 
开发者ID:singh05,项目名称:akkadb,代码行数:26,代码来源:ClusterController.scala



注:本文中的akka.cluster.ClusterEvent.UnreachableMember类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Flash类代码示例发布时间:2022-05-23
下一篇:
Scala TraceContext类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap