rpc

package
Version: v0.0.0-...-7b6ac62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateIncomingContext

func CreateIncomingContext(ctx context.Context, db string, shardID int32, logicNode models.Node) context.Context

CreateIncomingContext creates incoming context with given parameters, mainly for test rpc server, mock incoming context.

func CreateIncomingContextWithNode

func CreateIncomingContextWithNode(ctx context.Context, node models.Node) context.Context

CreateIncomingContextWithNode creates incoming context with given parameters, mainly for test rpc server, mock incoming context.

func CreateOutgoingContextWithNode

func CreateOutgoingContextWithNode(ctx context.Context, node models.Node) context.Context

CreateOutgoingContextWithNode creates outgoing context with logic node.

func GetDatabaseFromContext

func GetDatabaseFromContext(ctx context.Context) (string, error)

GetDatabaseFromContext returns database.

func GetFollowerFromContext

func GetFollowerFromContext(ctx context.Context) (models.NodeID, error)

GetFollowerFromContext returns follower's node id.

func GetLeaderFromContext

func GetLeaderFromContext(ctx context.Context) (models.NodeID, error)

GetLeaderFromContext returns leader's node id.

func GetLogicNodeFromContext

func GetLogicNodeFromContext(ctx context.Context) (*models.Node, error)

GetLogicNodeFromContext returns the logicNode.

func GetReplicasFromContext

func GetReplicasFromContext(ctx context.Context) ([]models.NodeID, error)

GetReplicasFromContext returns replicas' node id.

func GetShardIDFromContext

func GetShardIDFromContext(ctx context.Context) (int32, error)

GetShardIDFromContext returns shardID.

Types

type ClientConnFactory

type ClientConnFactory interface {
	// GetClientConn returns the grpc ClientConn for target node.
	// One connection for a target node.
	// Concurrent safe.
	GetClientConn(target models.Node) (*grpc.ClientConn, error)
}

ClientConnFactory is the factory for grpc ClientConn.

func GetClientConnFactory

func GetClientConnFactory() ClientConnFactory

GetClientConnFactory returns a singleton ClientConnFactory.

type ClientStreamFactory

type ClientStreamFactory interface {
	// LogicNode returns the a logic Node which will be transferred to the target server for identification.
	LogicNode() models.Node
	// CreateWriteClient creates a stream WriteClient.
	CreateWriteClient(db string, shardID int32, target models.Node) (protoStorageV1.WriteService_WriteClient, error)
	// CreateTaskClient creates a stream task client
	CreateTaskClient(target models.Node) (protoCommonV1.TaskService_HandleClient, error)
	// CreateWriteServiceClient creates a WriteServiceClient
	CreateWriteServiceClient(target models.Node) (protoStorageV1.WriteServiceClient, error)
	// CreateReplicaServiceClient creates a protoReplicaV1.ReplicaServiceClient.
	CreateReplicaServiceClient(target models.Node) (protoReplicaV1.ReplicaServiceClient, error)
}

ClientStreamFactory is the factory to get ClientStream.

func NewClientStreamFactory

func NewClientStreamFactory(logicNode models.Node) ClientStreamFactory

NewClientStreamFactory returns a factory to get clientStream.

type GRPCServer

type GRPCServer interface {
	// Start starts grpc server
	Start() error
	// Stop stops grpc server
	Stop()
	// GetServer returns the grpc server
	GetServer() *grpc.Server
}

func NewGRPCServer

func NewGRPCServer(bindAddress string) GRPCServer

type TaskClientFactory

type TaskClientFactory interface {
	// CreateTaskClient creates a task client stream if not exist
	CreateTaskClient(target models.Node) error
	// GetTaskClient returns the task client stream by target node
	GetTaskClient(target string) protoCommonV1.TaskService_HandleClient
	// CloseTaskClient closes the task client stream for target node
	CloseTaskClient(targetNodeID string) (closed bool, err error)
	// SetTaskReceiver set task receiver for handling task response
	SetTaskReceiver(taskReceiver TaskReceiver)
}

TaskClientFactory represents the task stream manage

func NewTaskClientFactory

func NewTaskClientFactory(currentNode models.Node) TaskClientFactory

NewTaskClientFactory creates a task client factory

type TaskReceiver

type TaskReceiver interface {
	// Receive receives the task result
	Receive(req *protoCommonV1.TaskResponse) error
}

TaskReceiver represents the task result receiver

type TaskServerFactory

type TaskServerFactory interface {
	// GetStream returns a ServerStream for a node.
	GetStream(node string) protoCommonV1.TaskService_HandleServer
	// Register registers a stream for a node.
	Register(node string, stream protoCommonV1.TaskService_HandleServer) (epoch int64)
	// Deregister unregisters a stream for node, if returns true, unregister successfully.
	Deregister(epoch int64, node string) bool
	// Nodes returns all registered nodes.
	Nodes() []models.Node
}

TaskServerFactory represents a factory to get server stream.

func NewTaskServerFactory

func NewTaskServerFactory() TaskServerFactory

NewTaskServerFactory returns the singleton server stream factory

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to