idlrpc

package
v0.0.0-...-b7b4667 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package idlrpc rpc-backend-go framework interface

Index

Constants

View Source
const (
	RpcNotInit = iota
	RpcRunning
	RpcClosed
)
View Source
const (
	ProxyConnected = iota
	ProxyDisconnected
)
View Source
const (
	InvalidGlobalIndex = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallUuid

type CallUuid uint32

CallUuid stub call uuid generate by manager

type IProxy

type IProxy interface {

	// GetUUID service uuid
	// @detail get service uuid id which generated by rpc-repo
	GetUUID() uint64

	// GetSignature
	// get method human-readable name
	GetSignature(uint32) string

	// GetID
	//get proxy instance ID, priority delivery service instance
	GetID() ProxyId

	// SetID
	// set proxy instance ID
	SetID(ProxyId)

	// SetTargetID
	// last return service id, maybe some service box need
	SetTargetID(uint32)

	// GetTargetID
	// return last return service id
	GetTargetID() uint32

	// GetGlobalIndex
	// return proxy global index
	GetGlobalIndex() protocol.GlobalIndexType

	// SetGlobalIndex
	// set proxy global index
	SetGlobalIndex(indexType protocol.GlobalIndexType)

	// IsOneWay oneway
	//@detail is one way function which not wait for return
	//@param method id
	IsOneWay(uint32) bool

	// GetSrvName
	//@detail get proxy name
	GetSrvName() string

	// SetTransport
	// @detail set transport
	SetTransport(transport transport.ITransport)

	// GetTransport
	// return transport
	GetTransport() transport.ITransport

	// IsConnected
	// check transport valid state
	IsConnected() bool

	// SetRpc set rpc instance to proxy
	SetRpc(IRpc)

	// GetRpc get rpc instance from proxy
	GetRpc() IRpc
	// contains filtered or unexported methods
}

IProxy user's idl proxy interface, using as client to call remote function; rpc framework set transport to it

type IProxyHandler

type IProxyHandler interface {
	OnRelay(trans transport.ITransport, header *protocol.RpcMsgHeader) error
}

type IRpc

type IRpc interface {
	Init(...Option) error
	// Start rpc framework,init data and start some goroutine
	Start() error
	// Tick Calls the main loop in the user master coroutine。
	Tick() error
	// ShutDown close rpc framework close
	ShutDown() error
	// Options options get rpc options
	Options() *Options
	// OnMessage deal network message
	OnMessage(trans transport.ITransport, ctx context.Context) error
	// OnProxyMessage trans proxy message to inside service
	OnProxyMessage(tran transport.ITransport, ph IProxyHandler) error
	// RegisterService register user impl service struct to framework
	RegisterService(service IService) error
	// Call service proxy call remote sync
	//Return resp unmarshalled proto buffer and exec result
	Call(proxyId IProxy, methodId, timeout uint32, retry int32, message proto.Message) ([]byte, error)
	// GetProxyFromPeer get proxy by stub call
	GetProxyFromPeer(ctx context.Context, uuid uint64) (IProxy, error)
	// GetServiceProxy get service proxy
	GetServiceProxy(uuid uint64, trans transport.ITransport) (IProxy, error)
	// AddProxyCreator add proxy creator
	AddProxyCreator(uuid uint64, pc ProxyCreator) error
	// AddStubCreator add stub creator
	AddStubCreator(uuid uint64, bc StubCreator) error
}

func CreateRpcFramework

func CreateRpcFramework() IRpc

type ISDK

type ISDK interface {
	GetUuid() uint64
	GetNickName() string
	IsProxy() bool
	Register(IRpc) error
}

ISDK sdk interface

type IService

type IService interface {

	// GetUUID service uuid, generated by rpc-repo
	GetUUID() uint64

	// GetNickName return custom service nickname !
	GetNickName() string

	// OnAfterFork init service by framework, user can init some custom data in this function
	OnAfterFork(ctx context.Context) bool

	// OnTick tick your service the same goroutine
	OnTick() bool

	// OnBeforeDestroy before service unload, you can clean your own data in this func
	OnBeforeDestroy() bool
}

IService user custom service framework interface

type IStub

type IStub interface {
	//GetUUID service uuid, generate by rpc-repo
	GetUUID() SvcUuid
	//GetServiceName service name
	GetServiceName() string
	//GetSignature method human-readable name
	GetSignature(methodId uint32) string
	//GetMutipleNum service goroutine num, read from idl keyword multiple
	GetMutipleNum() uint32
	//IsOneWay one way function, not send response
	IsOneWay(methodId uint32) bool
	// Call will trigger service's method
	// return encode response buffer data and errors
	Call(context.Context, uint32, []byte) ([]byte, error)
	//OnAfterFork invoke by framework after spawned
	//init service data or load db data in this function
	OnAfterFork(ctx context.Context) bool
	//OnBeforeDestroy invoke by framework before uninitialized
	//clean service data in this function
	OnBeforeDestroy() bool
	//OnTick tick by service manager in logic tick
	OnTick() bool
	//GetStatus get service status
	//TODO: for hot update
	GetStatus() ServiceStatus
	//SetStatus set service status
	SetStatus(status ServiceStatus)
}

IStub rpc stub of service's side

type Option

type Option func(*Options)

func WithCallTrace

func WithCallTrace(open bool) Option

func WithLogger

func WithLogger(logger log.ILogger) Option

func WithStackTrace

func WithStackTrace(open bool) Option

func WithUserData

func WithUserData(key, val interface{}) Option

type Options

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

func (*Options) CallTrace

func (o *Options) CallTrace() bool

func (*Options) StackTrace

func (o *Options) StackTrace() bool

type PackageInfo

type PackageInfo struct {
	ServiceUUID uint64          //service uuid
	Creator     SdkCreateHandle //Sdk Creator handle
}

PackageInfo service package information

type ProxyBase

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

ProxyBase proxy common struct impl

func (*ProxyBase) GetGlobalIndex

func (base *ProxyBase) GetGlobalIndex() protocol.GlobalIndexType

func (*ProxyBase) GetID

func (base *ProxyBase) GetID() ProxyId

func (*ProxyBase) GetRpc

func (base *ProxyBase) GetRpc() IRpc

func (*ProxyBase) GetTargetID

func (base *ProxyBase) GetTargetID() uint32

func (*ProxyBase) GetTransport

func (base *ProxyBase) GetTransport() transport.ITransport

func (*ProxyBase) IsConnected

func (base *ProxyBase) IsConnected() bool

func (*ProxyBase) SetGlobalIndex

func (base *ProxyBase) SetGlobalIndex(index protocol.GlobalIndexType)

func (*ProxyBase) SetID

func (base *ProxyBase) SetID(id ProxyId)

func (*ProxyBase) SetRpc

func (base *ProxyBase) SetRpc(r IRpc)

func (*ProxyBase) SetTargetID

func (base *ProxyBase) SetTargetID(id uint32)

func (*ProxyBase) SetTransport

func (base *ProxyBase) SetTransport(trans transport.ITransport)

SetTransport set network message transport called by creator

type ProxyCreator

type ProxyCreator func(transport.ITransport) IProxy

ProxyCreator proxy creator, one client may connect to differently service

type ProxyId

type ProxyId proxy.ProxyUuid

type ProxyManager

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

ProxyManager manager connect proxy for rpc framework, multiple may be read & write TODO add transport id 2 service uid cache

func (*ProxyManager) Add

func (p *ProxyManager) Add(proxy IProxy) error

func (*ProxyManager) Destroy

func (p *ProxyManager) Destroy(proxyId ProxyId) error

func (*ProxyManager) GeneProxyId

func (p *ProxyManager) GeneProxyId() ProxyId

func (*ProxyManager) Get

func (p *ProxyManager) Get(proxyId ProxyId) (IProxy, error)

type ProxyMap

type ProxyMap map[ProxyId]IProxy //key, proxyid, value proxy interface

type SdkCreateHandle

type SdkCreateHandle func(...string) (ISDK, error)

SdkCreateHandle rpc sdk creator, return sdk instance

type ServiceCache

type ServiceCache map[SvcUuid]*stubWrapper

ServiceCache service storage struct

type ServiceCreator

type ServiceCreator func(interface{}) IService

ServiceCreator service creator

type ServiceStatus

type ServiceStatus uint32
const (
	SERVICE_RESOLVED ServiceStatus = iota + 1 //ready for servicing
	SERVICE_UPDATING                          //stop receive message, wait for update
)

type StubCall

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

StubCall remote call data

func (*StubCall) CallID

func (sc *StubCall) CallID() uint32

CallID rpc remote proxyCall call id

func (*StubCall) GetBody

func (sc *StubCall) GetBody() []byte

func (*StubCall) GetServiceUUID

func (sc *StubCall) GetServiceUUID() uint64

func (*StubCall) GetUUID

func (sc *StubCall) GetUUID() CallUuid

GetUUID stub call uuid

func (*StubCall) GlobalIndex

func (sc *StubCall) GlobalIndex() protocol.GlobalIndexType

func (*StubCall) MethodID

func (sc *StubCall) MethodID() uint32

MethodID rpc method call id

type StubCreator

type StubCreator func(v interface{}) IStub

StubCreator stub factory

type StubManager

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

StubManager stub manager, manager registered service

func (*StubManager) Add

func (m *StubManager) Add(ctx context.Context, impl IStub) (err error)

func (*StubManager) GeneUuid

func (m *StubManager) GeneUuid() CallUuid

func (*StubManager) Get

func (m *StubManager) Get(uuid SvcUuid) *stubWrapper

func (*StubManager) Init

func (m *StubManager) Init(logger log.ILogger)

func (*StubManager) Tick

func (m *StubManager) Tick()

func (*StubManager) UnInit

func (m *StubManager) UnInit()

type SvcUuid

type SvcUuid uint64

SvcUuid service uuid type

type Trans2Proxy

type Trans2Proxy map[uint64]IProxy //service uuid, proxy interface

Directories

Path Synopsis
Generated by the go idl tools.
Generated by the go idl tools.
text 语法模板定义
text 语法模板定义
internal
pkg
log

Jump to

Keyboard shortcuts

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