memory

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 17 Imported by: 7

Documentation

Overview

Package memory provides the memory RPC server for go-orb.

Package memory provides a memory RPC mux that handles orb middleware.

Index

Constants

View Source
const (
	// DefaultMaxConcurrentStreams for memory.
	DefaultMaxConcurrentStreams = 256
)
View Source
const Name = "memory"

Name is the plugin name.

Variables

This section is empty.

Functions

func CreateClientServerPair

func CreateClientServerPair(ctx context.Context, endpoint string) (*Stream, *Stream)

CreateClientServerPair creates a pair of connected streams for client and server.

func New

func New(
	serviceName string,
	serviceVersion string,
	epName string,
	acfg any,
	logger log.Logger,
	reg registry.Type,
) (orbserver.Entrypoint, error)

New creates a memory Server from a Config struct.

func Provide

func Provide(
	serviceName string,
	serviceVersion string,
	epName string,
	configs map[string]any,
	logger log.Logger,
	reg registry.Type,
	opts ...orbserver.Option,
) (orbserver.Entrypoint, error)

Provide creates a new entrypoint for a single address. You can create multiple entrypoints for multiple addresses and ports.

func WithHandlers

func WithHandlers(h ...server.RegistrationFunc) server.Option

WithHandlers adds custom handlers.

func WithLogLevel

func WithLogLevel(level string) server.Option

WithLogLevel changes the log level from the inherited logger.

func WithLogPlugin

func WithLogPlugin(plugin string) server.Option

WithLogPlugin changes the log level from the inherited logger.

func WithMaxConcurrentStreams

func WithMaxConcurrentStreams(n int) server.Option

WithMaxConcurrentStreams sets the worker pool size.

Types

type Config

type Config struct {
	server.EntrypointConfig `yaml:",inline"`

	// MaxConcurrentStreams is the worker pool size.
	MaxConcurrentStreams int `json:"maxConcurrentStreams" yaml:"maxConcurrentStreams"`

	// Logger allows you to dynamically change the log level and plugin for a
	// specific entrypoint.
	Logger log.Config `json:"logger" yaml:"logger"`
}

Config provides options to the entrypoint.

func NewConfig

func NewConfig(options ...server.Option) *Config

NewConfig will create a new default config for the entrypoint.

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux is an implementation of Handler to serve drpc connections to the appropriate Receivers registered by Descriptions.

func (*Mux) HandleRPC

func (m *Mux) HandleRPC(stream drpc.Stream, rpc string) (err error)

HandleRPC handles the rpc that has been requested by the stream.

func (*Mux) Register

func (m *Mux) Register(srv interface{}, desc drpc.Description) error

Register associates the RPCs described by the description in the server. It returns an error if there was a problem registering it.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the memory Server for go-orb.

func (*Server) AddEndpoint

func (s *Server) AddEndpoint(name string)

AddEndpoint adds an endpoint to the internal list. This is used by the Register() callback function.

func (*Server) AddHandler

func (s *Server) AddHandler(handler orbserver.RegistrationFunc)

AddHandler adds a handler for later registration.

func (*Server) Address

func (s *Server) Address() string

Address returns an empty string as memory server doesn't have a network address.

func (*Server) Enabled

func (s *Server) Enabled() bool

Enabled returns if this entrypoint has been enabled in config.

func (*Server) Name

func (s *Server) Name() string

Name returns the entrypoint name.

func (*Server) Network

func (s *Server) Network() string

Network returns the network the entrypoint listens on.

func (*Server) Register

func (s *Server) Register(register orbserver.RegistrationFunc)

Register executes a registration function on the entrypoint.

func (*Server) Request

func (s *Server) Request(ctx context.Context, infos client.RequestInfos, req any, result any, opts *client.CallOptions) error

Request implements the client.MemoryServer interface.

func (*Server) Router

func (s *Server) Router() *Mux

Router returns the memory mux.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start registers the memory server with the client package.

func (*Server) Stop

func (s *Server) Stop(_ context.Context) error

Stop will unregister the memory server from the client package.

func (*Server) Stream

func (s *Server) Stream(
	ctx context.Context,
	infos client.RequestInfos,
	opts *client.CallOptions,
) (client.StreamIface[any, any], error)

Stream creates a new bidirectional stream for memory-based RPC communication.

func (*Server) String

func (s *Server) String() string

String returns the entrypoint type.

func (*Server) Transport

func (s *Server) Transport() string

Transport returns the client transport to use: "memory".

func (*Server) Type

func (s *Server) Type() string

Type returns the component type.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream implements the client.StreamIface and the drpc.Stream interface for memory-based streaming.

func (*Stream) Close

func (s *Stream) Close() error

Close closes the stream.

func (*Stream) CloseSend

func (s *Stream) CloseSend() error

CloseSend closes the send side of the stream but keeps the receive side open.

func (*Stream) Context

func (s *Stream) Context() context.Context

Context returns the stream's context.

func (*Stream) MsgRecv

func (s *Stream) MsgRecv(msg drpc.Message, _ drpc.Encoding) error

MsgRecv receives a message from the stream.

func (*Stream) MsgSend

func (s *Stream) MsgSend(msg drpc.Message, _ drpc.Encoding) error

MsgSend sends a message through the stream.

func (*Stream) Recv

func (s *Stream) Recv(msg any) error

Recv receives a message from the stream.

func (*Stream) Send

func (s *Stream) Send(msg any) error

Send sends a message through the stream.

Jump to

Keyboard shortcuts

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