rpc

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer added in v0.16.0

func NewServer(opts ...grpc.ServerOption) *grpc.Server

NewServer calls grpc.NewServer function. The package github.com/kakao/varlog/pkg/rpc registers the gogoproto codec to the gRPC. Therefore calling this method rather than grpc.NewServer makes the application server use the gogoproto codec instead of the regular proto codec.

func TestNewConn

func TestNewConn(t *testing.T, ctx context.Context, bufsize ...int) (listener net.Listener, connect func() *Conn)

Types

type Conn

type Conn struct {
	Conn *grpc.ClientConn
	// contains filtered or unexported fields
}

func NewConn

func NewConn(ctx context.Context, address string, opts ...grpc.DialOption) (*Conn, error)

NewConn creates a new gRPC connection to the specified address using google.golang.org/grpc.NewClient. Note that this method does not perform any I/O, meaning the connection is not immediately established. If the server is unavailable, this method will not return an error. The connection is established automatically when an RPC is made using the returned Conn. DialOptions such as WithBlock, WithTimeout, and WithReturnConnectionError are not considered. Ensure to close the returned Conn after usage to avoid resource leaks.

func (*Conn) Close

func (c *Conn) Close() (err error)

Close terminates the gRPC connection. This method ensures that the connection is closed only once, even if called multiple times. It is important to call Close after the connection is no longer needed to release resources properly.

type Manager

type Manager[T comparable] struct {
	// contains filtered or unexported fields
}

Manager keeps RPC connections for each target. Type parameter T should be a comparable type that identifies the target peer, for instance, types.StorageNodeID and types.NodeID. Manager can be shared by multiple clients.

func NewManager

func NewManager[T comparable](opts ...ManagerOption) (*Manager[T], error)

NewManager creates a Manager.

func (*Manager[T]) Close

func (m *Manager[T]) Close() (err error)

Close closes all underlying connections managed by the Manager.

func (*Manager[T]) CloseClient

func (m *Manager[T]) CloseClient(id T) error

CloseClient closes a connection identified by the argument id and removes the connection from the manager. It returns nil if the connection does not exist.

func (*Manager[T]) GetOrConnect

func (m *Manager[T]) GetOrConnect(ctx context.Context, id T, addr string, grpcDialOptions ...grpc.DialOption) (*Conn, error)

GetOrConnect returns an RPC connection that is cached or established if not exist.

type ManagerOption

type ManagerOption interface {
	// contains filtered or unexported methods
}

ManagerOptions is a type for options of Manager.

func WithDefaultGRPCDialOptions

func WithDefaultGRPCDialOptions(defaultGRPCDialOptions ...grpc.DialOption) ManagerOption

WithDefaultGRPCDialOptions sets default GRPC DialOptions.

func WithLogger

func WithLogger(logger *zap.Logger) ManagerOption

WithLogger sets a logger.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL