RpcEndpoint is a contract to define an RPC endpoint that can receive messages using callbacks, i.e. functions to execute when a message arrives.

package org.apache.spark.rpc

trait RpcEndpoint {
  def onConnected(remoteAddress: RpcAddress): Unit
  def onDisconnected(remoteAddress: RpcAddress): Unit
  def onError(cause: Throwable): Unit
  def onNetworkError(cause: Throwable, remoteAddress: RpcAddress): Unit
  def onStart(): Unit
  def onStop(): Unit
  def receive: PartialFunction[Any, Unit]
  def receiveAndReply(context: RpcCallContext): PartialFunction[Any, Unit]
  val rpcEnv: RpcEnv

RpcEndpoint lives in RpcEnv after being registered by a name.

A RpcEndpoint can be registered to one and only one RpcEnv.

The lifecycle of a RpcEndpoint is onStart, receive and onStop in sequence.

receive can be called concurrently.

If you want receive to be thread-safe, use ThreadSafeRpcEndpoint.

onError method is called for any exception thrown.

Table 1. RpcEndpoint Contract
Method Description


Receives and processes a message

RpcEndpoint is a private[spark] contract.

Activating RPC Endpoint (Just Before Handling Messages) — onStart Method


stop Method