RpcEndpointRef


概述

RpcEndpointRef是远程 [RpcEndpoint] 的引用。[RpcEndpointRef] 是线程安全的。

1. 源码剖析

1.1 变量

RpcEndpointRef是一个抽象类,有三个val变量(通过在sparkConf中设置来修改):

  • maxRetries = RpcUtils.numRetries(SparkConf)
  • retryWaitMs = RpcUtils.retryWaitMs(SparkConf)
  • defaultAskTimeout = RpcUtils.askRpcTimeout(SparkConf)

1.2 两个getter

1.2.1 获取address
  def address: RpcAddress
1.2.2 获取name
  def name: String

1.3 通信方法

1.3.1 send():单向异步消息
  /**
   * Sends a one-way asynchronous message. Fire-and-forget semantics.
   * 发送单向异步消息。"一时无二"的语义。
   */
  def send(message: Any): Unit
1.3.2 ask():发送异步消息,非阻塞等待回复

指定超时时间:

  • 将消息发送到相应的 [Rpcendpoint.receiveAndReplyAndReply)],并返回 [Future] 以在指定超时内接收回复。
  • 此方法仅发送消息一次,从不重试。
  def ask[T: ClassTag](message: Any, timeout: RpcTimeout): Future[T]

默认超时时间:

  • 将消息发送到相应的 [Rpcendpoint.receiveAndReplyAndReply)],并返回 [Future] 以在默认超时内接收回复。
  • 此方法仅发送消息一次,从不重试。
  def ask[T: ClassTag](message: Any): Future[T] = ask(message, defaultAskTimeout)
1.3.3 askSync():发送同步消息,阻塞等待回复

指定超时时间:

  • 将消息发送到相应的[RpcEndpoint.receiveAndReply]并在指定超时内获取结果,如果失败,将引发异常。
  • 注意:这是一个阻塞操作,可能会花费大量时间,因此不要在[[RpcEndpoint]的消息循环中调用它。
  def askSync[T: ClassTag](message: Any, timeout: RpcTimeout): T = {
    val future = ask[T](message, timeout)
    timeout.awaitResult(future)
  }

默认超时时间:

  • 将消息发送到相应的[RpcEndpoint.receiveAndReply]并在默认超时内获取结果,如果失败,将引发异常。
  • 注意:这是一个阻塞操作,可能会花费大量时间,因此不要在[[RpcEndpoint]的消息循环中调用它。
  def askSync[T: ClassTag](message: Any): T = askSync(message, defaultAskTimeout)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值