core

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 25 Imported by: 28

Documentation

Overview

Package core is motan-go base package. contains base struct, interface and default implement.

Index

Constants

View Source
const (
	FrameworkException = iota
	// ServiceException : exception by service call
	ServiceException
	// BizException : exception by service implements
	BizException
)

--------------all global public constants-------------- exception type

View Source
const (
	// EndPointFilterType filter for endpoint
	EndPointFilterType = iota
	// ClusterFilterType filter for cluster
	ClusterFilterType
)

filter type

View Source
const (
	NodeTypeKey             = "nodeType"
	Hakey                   = "haStrategy"
	Lbkey                   = "loadbalance"
	TimeOutKey              = "requestTimeout"
	MinTimeOutKey           = "minRequestTimeout"
	MaxTimeOutKey           = "maxRequestTimeout"
	SessionTimeOutKey       = "registrySessionTimeout"
	RetriesKey              = "retries"
	ApplicationKey          = "application"
	VersionKey              = "version"
	FilterKey               = "filter"
	RegistryKey             = "registry"
	WeightKey               = "weight"
	SerializationKey        = "serialization"
	RefKey                  = "ref"
	ExportKey               = "export"
	ModuleKey               = "module"
	GroupKey                = "group"
	ProviderKey             = "provider"
	ProxyKey                = "proxy"
	AddressKey              = "address"
	GzipSizeKey             = "mingzSize"
	HostKey                 = "host"
	RemoteIPKey             = "remoteIP"
	ProxyRegistryKey        = "proxyRegistry"
	ConnectTimeoutKey       = "connectTimeout"
	ConnectRetryIntervalKey = "connectRetryInterval"
	ClientConnectionKey     = "clientConnection"
	ErrorCountThresholdKey  = "errorCountThreshold"
	KeepaliveIntervalKey    = "keepaliveInterval"
	UnixSockKey             = "unixSock"
	ManagementUnixSockKey   = "managementUnixSock"
	ManagementPortRangeKey  = "managementPortRange"
	HTTPProxyUnixSockKey    = "httpProxyUnixSock"
)

common url parameter key

View Source
const (
	NodeTypeService = "service"
	NodeTypeReferer = "referer"
	NodeTypeAgent   = "agent"
)

nodeType

View Source
const (
	Receive       = "receive"
	Decode        = "decode"
	Convert       = "convert"
	ClFilter      = "clusterFilter"
	EpFilterStart = "selectEndpoint"
	EpFilterEnd   = "endpointFilter"
	Encode        = "encode"
	Send          = "send"
)

trace span name

View Source
const (
	ENoEndpoints = 1001
	ENoChannel   = 1002
)

errorCodes

View Source
const (
	SwitcherSection = "switcher"

	// URLConfKey is config id
	// config Keys
	URLConfKey = "conf-id"
)
View Source
const (
	DefaultAttachmentSize     = 16
	DefaultRPCContextMetaSize = 8

	ProtocolLocal = "local"
)
View Source
const (
	DefaultWriteTimeout = 5 * time.Second
)
View Source
const (
	MetaUpstreamCode = "upstreamCode"
)

meta keys

Variables

View Source
var (
	// TracePolicy is trace policy for mesh request, this func is called by each request, trace will enable if this func return a TraceContext
	TracePolicy TracePolicyFunc = NoTrace

	// RandomTraceBase is random base for RandomTrace
	RandomTraceBase        = 10
	MaxTraceSize    uint64 = 10000
)
View Source
var (
	Port        = flag.Int("port", 0, "agent listen port")
	Eport       = flag.Int("eport", 0, "agent export service port when as a reverse proxy server")
	Hport       = flag.Int("hport", 0, "http forward proxy server port")
	Mport       = flag.Int("mport", 0, "agent manage port")
	Pidfile     = flag.String("pidfile", "", "agent manage port")
	CfgFile     = flag.String("c", "", "motan run conf")
	LocalIP     = flag.String("localIP", "", "local ip for motan register")
	IDC         = flag.String("idc", "", "the idc info for agent or client.")
	Pool        = flag.String("pool", "", "application pool config. like 'application-idc-level'")
	Application = flag.String("application", "", "assist for application pool config.")
	Recover     = flag.Bool("recover", false, "recover from accidental exit")
)

all env flag in motan-go

View Source
var ErrNotEnough = errors.New("BytesBuffer: not enough bytes")
View Source
var ErrOverflow = errors.New("BytesBuffer: integer overflow")
View Source
var (
	PanicStatFunc func()
)

Functions

func CanSetContext

func CanSetContext(s interface{}, context *Context)

CanSetContext :CanSetContext

func FirstUpper

func FirstUpper(s string) string

func GetAllGroups

func GetAllGroups(gr GroupDiscoverableRegistry) []string

func GetLocalIP

func GetLocalIP() string

GetLocalIP falg of localIP > ipnet

func GetLocalIPs

func GetLocalIPs() []string

GetLocalIPs ip from ipnet

func GetReqInfo

func GetReqInfo(request Request) string

func GetURLFilters

func GetURLFilters(url *URL, extFactory ExtensionFactory) (clusterFilter ClusterFilter, endpointFilters []Filter)

func HandlePanic

func HandlePanic(f func())

func Initialize

func Initialize(s interface{})

Initialize : Initialize if implement Initializable

func InterfaceToString

func InterfaceToString(in interface{}) string

func IsSame

func IsSame(m1 map[string]string, m2 map[string]string, key string, defaultValue string) bool

func ListenUnixSock

func ListenUnixSock(unixSockAddr string) (net.Listener, error)

ListenUnixSock try to listen a unix socket address this method using by create motan agent server, management server and http proxy server

func ParseExportInfo

func ParseExportInfo(export string) (string, int, error)

func RegistLocalProvider

func RegistLocalProvider(service string, provider Provider)

func ServiceInGroup

func ServiceInGroup(sr ServiceDiscoverableRegistry, group string, service string) bool

func SliceShuffle

func SliceShuffle(slice []string) []string

func TrimSplit

func TrimSplit(s string, sep string) []string

TrimSplit slices s into all substrings separated by sep and returns a slice of the substrings between those separators, specially trim all substrings.

Types

type AsyncResult

type AsyncResult struct {
	StartTime int64
	Done      chan *AsyncResult
	Reply     interface{}
	Error     error
}

AsyncResult : async call result

type AtomicString

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

func NewAtomicString

func NewAtomicString(str string) *AtomicString

func (*AtomicString) Load

func (s *AtomicString) Load() string

func (*AtomicString) Store

func (s *AtomicString) Store(str string)

type Attachment

type Attachment interface {
	GetAttachments() *StringMap
	GetAttachment(key string) string
	SetAttachment(key string, value string)
}

Attachment : can get, set attachments.

type BytesBuffer

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

BytesBuffer is a variable-sized buffer of bytes with Read and Write methods. BytesBuffer is not thread safe for multi goroutine operation.

func CreateBytesBuffer

func CreateBytesBuffer(data []byte) *BytesBuffer

CreateBytesBuffer create a BytesBuffer from data bytes

func CreateBytesBufferWithOrder

func CreateBytesBufferWithOrder(data []byte, order binary.ByteOrder) *BytesBuffer

CreateBytesBufferWithOrder create a BytesBuffer from data bytes with bytes order

func NewBytesBuffer

func NewBytesBuffer(initsize int) *BytesBuffer

NewBytesBuffer create a empty BytesBuffer with initial size

func NewBytesBufferWithOrder

func NewBytesBufferWithOrder(initsize int, order binary.ByteOrder) *BytesBuffer

NewBytesBufferWithOrder create a empty BytesBuffer with initial size and byte order

func (*BytesBuffer) Bytes

func (b *BytesBuffer) Bytes() []byte

func (*BytesBuffer) Cap

func (b *BytesBuffer) Cap() int

func (*BytesBuffer) GetRPos

func (b *BytesBuffer) GetRPos() int

GetRPos get the read position of BytesBuffer

func (*BytesBuffer) GetWPos

func (b *BytesBuffer) GetWPos() int

GetWPos get the write position of BytesBuffer

func (*BytesBuffer) Len

func (b *BytesBuffer) Len() int

func (*BytesBuffer) Next

func (b *BytesBuffer) Next(n int) ([]byte, error)

func (*BytesBuffer) Read

func (b *BytesBuffer) Read(p []byte) (n int, err error)

func (*BytesBuffer) ReadByte

func (b *BytesBuffer) ReadByte() (byte, error)

func (*BytesBuffer) ReadFull

func (b *BytesBuffer) ReadFull(p []byte) error

func (*BytesBuffer) ReadInt

func (b *BytesBuffer) ReadInt() (int, error)

ReadInt read next int32

func (*BytesBuffer) ReadUint16

func (b *BytesBuffer) ReadUint16() (n uint16, err error)

func (*BytesBuffer) ReadUint32

func (b *BytesBuffer) ReadUint32() (n uint32, err error)

func (*BytesBuffer) ReadUint64

func (b *BytesBuffer) ReadUint64() (n uint64, err error)

func (*BytesBuffer) ReadVarint

func (b *BytesBuffer) ReadVarint() (x uint64, err error)

func (*BytesBuffer) ReadZigzag32

func (b *BytesBuffer) ReadZigzag32() (x uint64, err error)

func (*BytesBuffer) ReadZigzag64

func (b *BytesBuffer) ReadZigzag64() (x uint64, err error)

func (*BytesBuffer) Remain

func (b *BytesBuffer) Remain() int

func (*BytesBuffer) Reset

func (b *BytesBuffer) Reset()

func (*BytesBuffer) SetRPos

func (b *BytesBuffer) SetRPos(pos int)

SetRPos get the read position of BytesBuffer

func (*BytesBuffer) SetWPos

func (b *BytesBuffer) SetWPos(pos int)

SetWPos set the write position of BytesBuffer

func (*BytesBuffer) Write

func (b *BytesBuffer) Write(bytes []byte)

Write write a byte array append the BytesBuffer, and the wpos will increase len(bytes)

func (*BytesBuffer) WriteByte

func (b *BytesBuffer) WriteByte(c byte)

WriteByte write a byte append the BytesBuffer, the wpos will increase one

func (*BytesBuffer) WriteUint16

func (b *BytesBuffer) WriteUint16(u uint16)

WriteUint16 write a uint16 append the BytesBuffer acording to buffer's order

func (*BytesBuffer) WriteUint32

func (b *BytesBuffer) WriteUint32(u uint32)

func (*BytesBuffer) WriteUint64

func (b *BytesBuffer) WriteUint64(u uint64)

func (*BytesBuffer) WriteVarint

func (b *BytesBuffer) WriteVarint(u uint64) int

func (*BytesBuffer) WriteZigzag32

func (b *BytesBuffer) WriteZigzag32(u uint32) int

func (*BytesBuffer) WriteZigzag64

func (b *BytesBuffer) WriteZigzag64(u uint64) int

type Caller

type Caller interface {
	WithURL
	Status
	Call(request Request) Response
	Destroyable
}

Caller : can process a motan request. the call maybe process from remote by endpoint, maybe process by some kinds of provider

type Cloneable

type Cloneable interface {
	Clone() interface{}
}

Cloneable : can clone itself, the return type interface{} must be the type which implement this interface

type ClusterFilter

type ClusterFilter interface {
	Filter
	SetNext(nextFilter ClusterFilter)
	GetNext() ClusterFilter
	//Filter for Cluster
	Filter(haStrategy HaStrategy, loadBalance LoadBalance, request Request) Response
}

ClusterFilter : filter for cluster

func GetLastClusterFilter

func GetLastClusterFilter() ClusterFilter

type CommandNotifyListener

type CommandNotifyListener interface {
	Identity
	NotifyCommand(registryURL *URL, commandType int, commandInfo string)
}

CommandNotifyListener : support command notify

type Context

type Context struct {
	ConfigFile       string
	Config           *cfg.Config
	RegistryURLs     map[string]*URL
	RefersURLs       map[string]*URL
	HTTPClientURLs   map[string]*URL
	BasicReferURLs   map[string]*URL
	ServiceURLs      map[string]*URL
	BasicServiceURLs map[string]*URL
	AgentURL         *URL
	ClientURL        *URL
	ServerURL        *URL
	// contains filtered or unexported fields
}

Context for agent, client, server. context is created depends on config file

func NewContext

func NewContext(configFile string, application string, pool string) *Context

func NewContextFromConfig

func NewContextFromConfig(conf *cfg.Config, application string, pool string) *Context

func (*Context) Initialize

func (c *Context) Initialize()

type CopyOnWriteMap

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

func NewCopyOnWriteMap

func NewCopyOnWriteMap() *CopyOnWriteMap

func (*CopyOnWriteMap) Delete

func (m *CopyOnWriteMap) Delete(key interface{}) (pv interface{})

func (*CopyOnWriteMap) Len

func (m *CopyOnWriteMap) Len() int

func (*CopyOnWriteMap) Load

func (m *CopyOnWriteMap) Load(key interface{}) (interface{}, bool)

func (*CopyOnWriteMap) LoadOrNil

func (m *CopyOnWriteMap) LoadOrNil(key interface{}) interface{}

func (*CopyOnWriteMap) Range

func (m *CopyOnWriteMap) Range(f func(k, v interface{}) bool)

func (*CopyOnWriteMap) Store

func (m *CopyOnWriteMap) Store(key, value interface{})

func (*CopyOnWriteMap) Swap

func (m *CopyOnWriteMap) Swap(newMap map[interface{}]interface{}) map[interface{}]interface{}

type DefaultExtensionFactory

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

func (*DefaultExtensionFactory) GetEndPoint

func (d *DefaultExtensionFactory) GetEndPoint(url *URL) EndPoint

func (*DefaultExtensionFactory) GetFilter

func (d *DefaultExtensionFactory) GetFilter(name string) Filter

func (*DefaultExtensionFactory) GetHa

func (d *DefaultExtensionFactory) GetHa(url *URL) HaStrategy

func (*DefaultExtensionFactory) GetLB

func (d *DefaultExtensionFactory) GetLB(url *URL) LoadBalance

func (*DefaultExtensionFactory) GetMessageHandler

func (d *DefaultExtensionFactory) GetMessageHandler(name string) MessageHandler

func (*DefaultExtensionFactory) GetProvider

func (d *DefaultExtensionFactory) GetProvider(url *URL) Provider

func (*DefaultExtensionFactory) GetRegistry

func (d *DefaultExtensionFactory) GetRegistry(url *URL) Registry

func (*DefaultExtensionFactory) GetSerialization

func (d *DefaultExtensionFactory) GetSerialization(name string, id int) Serialization

func (*DefaultExtensionFactory) GetServer

func (d *DefaultExtensionFactory) GetServer(url *URL) Server

func (*DefaultExtensionFactory) Initialize

func (d *DefaultExtensionFactory) Initialize()

func (*DefaultExtensionFactory) RegistExtEndpoint

func (d *DefaultExtensionFactory) RegistExtEndpoint(name string, newEndpoint NewEndpointFunc)

func (*DefaultExtensionFactory) RegistExtFilter

func (d *DefaultExtensionFactory) RegistExtFilter(name string, newFilter DefaultFilterFunc)

func (*DefaultExtensionFactory) RegistExtHa

func (d *DefaultExtensionFactory) RegistExtHa(name string, newHa NewHaFunc)

func (*DefaultExtensionFactory) RegistExtLb

func (d *DefaultExtensionFactory) RegistExtLb(name string, newLb NewLbFunc)

func (*DefaultExtensionFactory) RegistExtProvider

func (d *DefaultExtensionFactory) RegistExtProvider(name string, newProvider NewProviderFunc)

func (*DefaultExtensionFactory) RegistExtRegistry

func (d *DefaultExtensionFactory) RegistExtRegistry(name string, newRegistry NewRegistryFunc)

func (*DefaultExtensionFactory) RegistExtServer

func (d *DefaultExtensionFactory) RegistExtServer(name string, newServer NewServerFunc)

func (*DefaultExtensionFactory) RegistryExtMessageHandler

func (d *DefaultExtensionFactory) RegistryExtMessageHandler(name string, newMessage NewMessageHandlerFunc)

func (*DefaultExtensionFactory) RegistryExtSerialization

func (d *DefaultExtensionFactory) RegistryExtSerialization(name string, id int, newSerialization NewSerializationFunc)

type DefaultFilterFunc

type DefaultFilterFunc func() Filter

type DeserializableValue

type DeserializableValue struct {
	Serialization Serialization
	Body          []byte
}

DeserializableValue : for lazy deserialize

func (*DeserializableValue) Deserialize

func (d *DeserializableValue) Deserialize(v interface{}) (interface{}, error)

Deserialize : Deserialize

func (*DeserializableValue) DeserializeMulti

func (d *DeserializableValue) DeserializeMulti(v []interface{}) ([]interface{}, error)

DeserializeMulti : DeserializeMulti

type Destroyable

type Destroyable interface {
	Destroy()
}

Destroyable : can destroy ....

type DiscoverCommand

type DiscoverCommand interface {
	SubscribeCommand(url *URL, listener CommandNotifyListener)
	UnSubscribeCommand(url *URL, listener CommandNotifyListener)
	DiscoverCommand(url *URL) string
}

DiscoverCommand : discover command for client or agent

type DiscoverService

type DiscoverService interface {
	Subscribe(url *URL, listener NotifyListener)

	Unsubscribe(url *URL, listener NotifyListener)

	Discover(url *URL) []*URL
}

DiscoverService : discover service for cluster

type EndPoint

type EndPoint interface {
	Name
	Caller
	SetSerialization(s Serialization)
	SetProxy(proxy bool)
}

EndPoint : can process a remote rpc call

type EndPointFilter

type EndPointFilter interface {
	Filter
	SetNext(nextFilter EndPointFilter)
	GetNext() EndPointFilter
	//Filter for endpoint
	Filter(caller Caller, request Request) Response
}

EndPointFilter : filter for endpoint

func GetLastEndPointFilter

func GetLastEndPointFilter() EndPointFilter

type Exception

type Exception struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
	ErrType int    `json:"errtype"`
}

Exception :Exception

type Exporter

type Exporter interface {
	Export(server Server, extFactory ExtensionFactory, context *Context) error
	Unexport() error
	SetProvider(provider Provider)
	GetProvider() Provider
	Available()
	Unavailable()
	IsAvailable() bool
	WithURL
}

Exporter : export and manage a service. one exporter bind with a service

type ExtensionFactory

type ExtensionFactory interface {
	GetHa(url *URL) HaStrategy
	GetLB(url *URL) LoadBalance
	GetFilter(name string) Filter
	GetRegistry(url *URL) Registry
	GetEndPoint(url *URL) EndPoint
	GetProvider(url *URL) Provider
	GetServer(url *URL) Server
	GetMessageHandler(name string) MessageHandler
	GetSerialization(name string, id int) Serialization
	RegistExtFilter(name string, newFilter DefaultFilterFunc)
	RegistExtHa(name string, newHa NewHaFunc)
	RegistExtLb(name string, newLb NewLbFunc)
	RegistExtEndpoint(name string, newEndpoint NewEndpointFunc)
	RegistExtProvider(name string, newProvider NewProviderFunc)
	RegistExtRegistry(name string, newRegistry NewRegistryFunc)
	RegistExtServer(name string, newServer NewServerFunc)
	RegistryExtMessageHandler(name string, newMessage NewMessageHandlerFunc)
	RegistryExtSerialization(name string, id int, newSerialization NewSerializationFunc)
}

ExtensionFactory : can regiser and get all kinds of extension implements.

type Filter

type Filter interface {
	Name
	// filter must be prototype
	NewFilter(url *URL) Filter
	HasNext() bool
	GetIndex() int
	GetType() int32
}

Filter : filter request or response in a call processing

type FilterEndPoint

type FilterEndPoint struct {
	URL           *URL
	Filter        EndPointFilter
	StatusFilters []Status
	Caller        Caller
}

func (*FilterEndPoint) Call

func (f *FilterEndPoint) Call(request Request) Response

func (*FilterEndPoint) Destroy

func (f *FilterEndPoint) Destroy()

func (*FilterEndPoint) GetName

func (f *FilterEndPoint) GetName() string

func (*FilterEndPoint) GetURL

func (f *FilterEndPoint) GetURL() *URL

func (*FilterEndPoint) IsAvailable

func (f *FilterEndPoint) IsAvailable() bool

func (*FilterEndPoint) SetProxy

func (f *FilterEndPoint) SetProxy(proxy bool)

func (*FilterEndPoint) SetSerialization

func (f *FilterEndPoint) SetSerialization(s Serialization)

func (*FilterEndPoint) SetURL

func (f *FilterEndPoint) SetURL(url *URL)

type FinishHandleFunc

type FinishHandleFunc func()

func (FinishHandleFunc) Handle

func (f FinishHandleFunc) Handle()

type FinishHandler

type FinishHandler interface {
	Handle()
}

type GroupDiscoverableRegistry

type GroupDiscoverableRegistry interface {
	Registry
	DiscoverAllGroups() ([]string, error)
}

type HaStrategy

type HaStrategy interface {
	Name
	WithURL
	Call(request Request, loadBalance LoadBalance) Response
}

HaStrategy : high availability strategy

type Identity

type Identity interface {
	GetIdentity() string
}

Identity : get id

type Initializable

type Initializable interface {
	Initialize()
}

Initializable :Initializable

type LoadBalance

type LoadBalance interface {
	OnRefresh(endpoints []EndPoint)

	Select(request Request) EndPoint

	SelectArray(request Request) []EndPoint

	SetWeight(weight string)
}

LoadBalance : loadBalance for cluster

type MessageHandler

type MessageHandler interface {
	Call(request Request) (res Response)
	AddProvider(p Provider) error
	RmProvider(p Provider)
	GetProvider(serviceName string) Provider
}

MessageHandler : handler message(request) for Server

type MotanRequest

type MotanRequest struct {
	RequestID   uint64
	ServiceName string
	Method      string
	MethodDesc  string
	Arguments   []interface{}
	Attachment  *StringMap
	RPCContext  *RPCContext
	// contains filtered or unexported fields
}

MotanRequest : Request default implement

func (*MotanRequest) Clone

func (m *MotanRequest) Clone() interface{}

func (*MotanRequest) GetArguments

func (m *MotanRequest) GetArguments() []interface{}

func (*MotanRequest) GetAttachment

func (m *MotanRequest) GetAttachment(key string) string

GetAttachment GetAttachment

func (*MotanRequest) GetAttachments

func (m *MotanRequest) GetAttachments() *StringMap

func (*MotanRequest) GetMethod

func (m *MotanRequest) GetMethod() string

GetMethod GetMethod

func (*MotanRequest) GetMethodDesc

func (m *MotanRequest) GetMethodDesc() string

GetMethodDesc GetMethodDesc

func (*MotanRequest) GetRPCContext

func (m *MotanRequest) GetRPCContext(canCreate bool) *RPCContext

func (*MotanRequest) GetRequestID

func (m *MotanRequest) GetRequestID() uint64

func (*MotanRequest) GetServiceName

func (m *MotanRequest) GetServiceName() string

GetServiceName GetServiceName

func (*MotanRequest) ProcessDeserializable

func (m *MotanRequest) ProcessDeserializable(toTypes []interface{}) error

ProcessDeserializable : DeserializableValue to real params according toType some serialization can deserialize without toType, so nil toType can be accepted in these serializations

func (*MotanRequest) SetArguments

func (m *MotanRequest) SetArguments(arguments []interface{})

func (*MotanRequest) SetAttachment

func (m *MotanRequest) SetAttachment(key string, value string)

SetAttachment : SetAttachment

type MotanResponse

type MotanResponse struct {
	RequestID   uint64
	Value       interface{}
	Exception   *Exception
	ProcessTime int64
	Attachment  *StringMap
	RPCContext  *RPCContext
	// contains filtered or unexported fields
}

func BuildExceptionResponse

func BuildExceptionResponse(requestid uint64, e *Exception) *MotanResponse

func (*MotanResponse) GetAttachment

func (m *MotanResponse) GetAttachment(key string) string

func (*MotanResponse) GetAttachments

func (m *MotanResponse) GetAttachments() *StringMap

func (*MotanResponse) GetException

func (m *MotanResponse) GetException() *Exception

func (*MotanResponse) GetProcessTime

func (m *MotanResponse) GetProcessTime() int64

func (*MotanResponse) GetRPCContext

func (m *MotanResponse) GetRPCContext(canCreate bool) *RPCContext

func (*MotanResponse) GetRequestID

func (m *MotanResponse) GetRequestID() uint64

func (*MotanResponse) GetValue

func (m *MotanResponse) GetValue() interface{}

func (*MotanResponse) ProcessDeserializable

func (m *MotanResponse) ProcessDeserializable(toType interface{}) error

ProcessDeserializable : same with MotanRequest

func (*MotanResponse) SetAttachment

func (m *MotanResponse) SetAttachment(key string, value string)

func (*MotanResponse) SetProcessTime

func (m *MotanResponse) SetProcessTime(time int64)

type Name

type Name interface {
	GetName() string
}

Name is a interface can get and set name. especially for extension implements

type NewEndpointFunc

type NewEndpointFunc func(url *URL) EndPoint

type NewHaFunc

type NewHaFunc func(url *URL) HaStrategy

type NewLbFunc

type NewLbFunc func(url *URL) LoadBalance

type NewMessageHandlerFunc

type NewMessageHandlerFunc func() MessageHandler

type NewProviderFunc

type NewProviderFunc func(url *URL) Provider

type NewRegistryFunc

type NewRegistryFunc func(url *URL) Registry

type NewSerializationFunc

type NewSerializationFunc func() Serialization

type NewServerFunc

type NewServerFunc func(url *URL) Server

type NotifyListener

type NotifyListener interface {
	Identity
	Notify(registryURL *URL, urls []*URL)
}

NotifyListener : NotifyListener

type Pinger

type Pinger struct {
	Interval    time.Duration
	Timeout     time.Duration
	Count       int
	PacketsSent int
	PacketsRecv int
	Rtts        []time.Duration
	Size        int
	// contains filtered or unexported fields
}

func NewPinger

func NewPinger(addr string, count int, timeout time.Duration, size int, privileged bool) (*Pinger, error)

func (*Pinger) Addr

func (p *Pinger) Addr() string

func (*Pinger) IPAddr

func (p *Pinger) IPAddr() *net.IPAddr

func (*Pinger) Ping

func (p *Pinger) Ping() error

type Provider

type Provider interface {
	SetService(s interface{})
	Caller
	GetPath() string
}

Provider : service provider

func GetLocalProvider

func GetLocalProvider(service string) Provider

type RPCContext

type RPCContext struct {
	ExtFactory      ExtensionFactory
	OriginalMessage interface{}
	Oneway          bool
	Proxy           bool
	GzipSize        int
	BodySize        int
	SerializeNum    int
	Serialized      bool

	// for call
	AsyncCall bool
	Result    *AsyncResult
	Reply     interface{}

	Meta *StringMap
	// various time, it's owned by motan request context
	RequestSendTime     time.Time
	RequestReceiveTime  time.Time
	ResponseSendTime    time.Time
	ResponseReceiveTime time.Time

	FinishHandlers []FinishHandler

	// trace context
	Tc *TraceContext
}

RPCContext : Context for RPC call

func (*RPCContext) AddFinishHandler

func (c *RPCContext) AddFinishHandler(handler FinishHandler)

func (*RPCContext) OnFinish

func (c *RPCContext) OnFinish()

type RegisterService

type RegisterService interface {
	Register(serverURL *URL)
	UnRegister(serverURL *URL)
	Available(serverURL *URL)
	Unavailable(serverURL *URL)
	GetRegisteredServices() []*URL
}

RegisterService : register service for rpc server

type Registry

Registry : can subscribe or register service

type Request

type Request interface {
	Attachment
	Cloneable
	GetServiceName() string // service name  e.g. request path.or interface name
	GetMethod() string
	GetMethodDesc() string
	GetArguments() []interface{}
	GetRequestID() uint64
	GetRPCContext(canCreate bool) *RPCContext
	ProcessDeserializable(toTypes []interface{}) error
}

Request : motan request

type Response

type Response interface {
	Attachment
	GetValue() interface{}
	GetException() *Exception
	GetRequestID() uint64
	GetProcessTime() int64
	SetProcessTime(time int64)
	GetRPCContext(canCreate bool) *RPCContext
	ProcessDeserializable(toType interface{}) error
}

Response : motan response

type Serialization

type Serialization interface {
	GetSerialNum() int
	Serialize(v interface{}) ([]byte, error)
	DeSerialize(b []byte, v interface{}) (interface{}, error)
	SerializeMulti(v []interface{}) ([]byte, error)
	DeSerializeMulti(b []byte, v []interface{}) ([]interface{}, error)
}

Serialization : Serialization

func GetSerialization

func GetSerialization(url *URL, extFactory ExtensionFactory) Serialization

type Server

type Server interface {
	WithURL
	Name
	Destroyable
	SetMessageHandler(mh MessageHandler)
	GetMessageHandler() MessageHandler
	Open(block bool, proxy bool, handler MessageHandler, extFactory ExtensionFactory) error
}

Server : rpc server which listen port and process request

type ServiceDiscoverableRegistry

type ServiceDiscoverableRegistry interface {
	Registry
	DiscoverAllServices(group string) ([]string, error)
}

type SetContext

type SetContext interface {
	SetContext(context *Context)
}

SetContext :SetContext

type SnapshotConf

type SnapshotConf struct {
	// SnapshotInterval is the interval of creating snapshot
	SnapshotInterval time.Duration
	SnapshotDir      string
}

SnapshotConf is model for registry snapshot config.

type SnapshotService

type SnapshotService interface {
	StartSnapshot(conf *SnapshotConf)
}

SnapshotService : start registry snapshot

type Span

type Span struct {
	Name     string    `json:"name"`
	Addr     string    `json:"address"`
	Time     time.Time `json:"time"`
	Duration int64     `json:"duration"`
}

type Status

type Status interface {
	IsAvailable() bool
}

Status : for cluster or endpoint to check is available

type StringMap

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

StringMap goroutine safe string map, this will just be used in few goroutines so just use a simple implementation

func NewStringMap

func NewStringMap(cap int) *StringMap

func (*StringMap) Copy

func (m *StringMap) Copy() *StringMap

func (*StringMap) Delete

func (m *StringMap) Delete(key string)

func (*StringMap) Len

func (m *StringMap) Len() int

func (*StringMap) Load

func (m *StringMap) Load(key string) (value string, ok bool)

func (*StringMap) LoadOrEmpty

func (m *StringMap) LoadOrEmpty(key string) string

func (*StringMap) Range

func (m *StringMap) Range(f func(k, v string) bool)

Range calls f sequentially for each key and value present in the map If f returns false, range stops the iteration

func (*StringMap) RawMap

func (m *StringMap) RawMap() map[string]string

func (*StringMap) Store

func (m *StringMap) Store(key, value string)

type Switcher

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

func (*Switcher) GetName

func (s *Switcher) GetName() string

func (*Switcher) IsOpen

func (s *Switcher) IsOpen() bool

func (*Switcher) SetValue

func (s *Switcher) SetValue(value bool)

func (*Switcher) Watch

func (s *Switcher) Watch(listeners ...SwitcherListener)

type SwitcherListener

type SwitcherListener interface {
	Notify(value bool)
}

type SwitcherManager

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

func GetSwitcherManager

func GetSwitcherManager() *SwitcherManager

func (*SwitcherManager) GetAllSwitchers

func (s *SwitcherManager) GetAllSwitchers() map[string]bool

func (*SwitcherManager) GetSwitcher

func (s *SwitcherManager) GetSwitcher(name string) *Switcher

func (*SwitcherManager) Register

func (s *SwitcherManager) Register(name string, value bool, listeners ...SwitcherListener)

type TCPKeepAliveListener

type TCPKeepAliveListener struct {
	*net.TCPListener
}

func (TCPKeepAliveListener) Accept

func (ln TCPKeepAliveListener) Accept() (net.Conn, error)

type TestEndPoint

type TestEndPoint struct {
	URL         *URL
	ProcessTime int64
}

func (*TestEndPoint) Call

func (t *TestEndPoint) Call(request Request) Response

func (*TestEndPoint) Destroy

func (t *TestEndPoint) Destroy()

func (*TestEndPoint) GetName

func (t *TestEndPoint) GetName() string

func (*TestEndPoint) GetURL

func (t *TestEndPoint) GetURL() *URL

func (*TestEndPoint) IsAvailable

func (t *TestEndPoint) IsAvailable() bool

func (*TestEndPoint) SetProxy

func (t *TestEndPoint) SetProxy(proxy bool)

func (*TestEndPoint) SetSerialization

func (t *TestEndPoint) SetSerialization(s Serialization)

func (*TestEndPoint) SetURL

func (t *TestEndPoint) SetURL(url *URL)

type TestEndPointFilter

type TestEndPointFilter struct {
	Index int
	URL   *URL
	// contains filtered or unexported fields
}

func (*TestEndPointFilter) Filter

func (t *TestEndPointFilter) Filter(caller Caller, request Request) Response

func (*TestEndPointFilter) GetIndex

func (t *TestEndPointFilter) GetIndex() int

func (*TestEndPointFilter) GetName

func (t *TestEndPointFilter) GetName() string

func (*TestEndPointFilter) GetNext

func (t *TestEndPointFilter) GetNext() EndPointFilter

func (*TestEndPointFilter) GetType

func (t *TestEndPointFilter) GetType() int32

func (*TestEndPointFilter) HasNext

func (t *TestEndPointFilter) HasNext() bool

func (*TestEndPointFilter) NewFilter

func (t *TestEndPointFilter) NewFilter(url *URL) Filter

func (*TestEndPointFilter) SetNext

func (t *TestEndPointFilter) SetNext(nextFilter EndPointFilter)

type TestFilter

type TestFilter struct {
	Index int
	URL   *URL
	// contains filtered or unexported fields
}

func (*TestFilter) Filter

func (t *TestFilter) Filter(haStrategy HaStrategy, loadBalance LoadBalance, request Request) Response

func (*TestFilter) GetIndex

func (t *TestFilter) GetIndex() int

func (*TestFilter) GetName

func (t *TestFilter) GetName() string

func (*TestFilter) GetNext

func (t *TestFilter) GetNext() ClusterFilter

func (*TestFilter) GetType

func (t *TestFilter) GetType() int32

func (*TestFilter) HasNext

func (t *TestFilter) HasNext() bool

func (*TestFilter) NewFilter

func (t *TestFilter) NewFilter(url *URL) Filter

func (*TestFilter) SetNext

func (t *TestFilter) SetNext(nextFilter ClusterFilter)

type TestHaStrategy

type TestHaStrategy struct {
	URL *URL
}

func (*TestHaStrategy) Call

func (t *TestHaStrategy) Call(request Request, loadBalance LoadBalance) Response

func (*TestHaStrategy) GetName

func (t *TestHaStrategy) GetName() string

func (*TestHaStrategy) GetURL

func (t *TestHaStrategy) GetURL() *URL

func (*TestHaStrategy) SetURL

func (t *TestHaStrategy) SetURL(url *URL)

type TestLoadBalance

type TestLoadBalance struct {
	Endpoints []EndPoint
}

func (*TestLoadBalance) OnRefresh

func (t *TestLoadBalance) OnRefresh(endpoints []EndPoint)

func (*TestLoadBalance) Select

func (t *TestLoadBalance) Select(request Request) EndPoint

func (*TestLoadBalance) SelectArray

func (t *TestLoadBalance) SelectArray(request Request) []EndPoint

func (*TestLoadBalance) SetWeight

func (t *TestLoadBalance) SetWeight(weight string)

type TestObject

type TestObject struct {
	Str string
}

type TestProvider

type TestProvider struct {
	URL *URL
}

func (*TestProvider) Call

func (t *TestProvider) Call(request Request) Response

func (*TestProvider) Destroy

func (t *TestProvider) Destroy()

func (*TestProvider) GetPath

func (t *TestProvider) GetPath() string

func (*TestProvider) GetURL

func (t *TestProvider) GetURL() *URL

func (*TestProvider) IsAvailable

func (t *TestProvider) IsAvailable() bool

func (*TestProvider) SetService

func (t *TestProvider) SetService(s interface{})

func (*TestProvider) SetURL

func (t *TestProvider) SetURL(url *URL)

type TestRegistry

type TestRegistry struct {
	URL           *URL
	GroupService  map[string][]string
	DiscoverError bool
}

func (*TestRegistry) Available

func (t *TestRegistry) Available(serverURL *URL)

func (*TestRegistry) Discover

func (t *TestRegistry) Discover(url *URL) []*URL

func (*TestRegistry) DiscoverAllGroups

func (t *TestRegistry) DiscoverAllGroups() ([]string, error)

func (*TestRegistry) DiscoverAllServices

func (t *TestRegistry) DiscoverAllServices(group string) ([]string, error)

func (*TestRegistry) GetName

func (t *TestRegistry) GetName() string

func (*TestRegistry) GetRegisteredServices

func (t *TestRegistry) GetRegisteredServices() []*URL

func (*TestRegistry) GetURL

func (t *TestRegistry) GetURL() *URL

func (*TestRegistry) InitRegistry

func (t *TestRegistry) InitRegistry()

func (*TestRegistry) Register

func (t *TestRegistry) Register(serverURL *URL)

func (*TestRegistry) SetURL

func (t *TestRegistry) SetURL(url *URL)

func (*TestRegistry) StartSnapshot

func (t *TestRegistry) StartSnapshot(conf *SnapshotConf)

func (*TestRegistry) Subscribe

func (t *TestRegistry) Subscribe(url *URL, listener NotifyListener)

func (*TestRegistry) UnRegister

func (t *TestRegistry) UnRegister(serverURL *URL)

func (*TestRegistry) Unavailable

func (t *TestRegistry) Unavailable(serverURL *URL)

func (*TestRegistry) Unsubscribe

func (t *TestRegistry) Unsubscribe(url *URL, listener NotifyListener)

type TraceContext

type TraceContext struct {
	Rid      uint64                 `json:"requestid"`
	Addr     string                 `json:"address"`
	Values   map[string]interface{} `json:"values"`
	ReqSpans []*Span                `json:"request_spans"`
	ResSpans []*Span                `json:"response_spans"`
	// contains filtered or unexported fields
}

func AlwaysTrace

func AlwaysTrace(rid uint64, ext *StringMap) *TraceContext

AlwaysTrace : trace every request unless the tracecontext size over MaxTraceSize.

func GetTraceContexts

func GetTraceContexts() []*TraceContext

GetTraceContexts get && remove all TraceContext in holder, and create a new TraceContext holder.

func NewTraceContext

func NewTraceContext(rid uint64) *TraceContext

NewTraceContext : create a new TraceContext and hold to holder. it will return nil, if TraceContext size of holder is over MaxTraceSize.

func NoTrace

func NoTrace(rid uint64, ext *StringMap) *TraceContext

NoTrace : not trace. default trace policy.

func RandomTrace

func RandomTrace(rid uint64, ext *StringMap) *TraceContext

RandomTrace : trace ratio is 1/RandomTraceBase

func (*TraceContext) PutReqSpan

func (t *TraceContext) PutReqSpan(span *Span)

PutReqSpan : put a trace Span at request phase

func (*TraceContext) PutResSpan

func (t *TraceContext) PutResSpan(span *Span)

PutResSpan : put a trace Span at response phase

type TracePolicyFunc

type TracePolicyFunc func(rid uint64, ext *StringMap) *TraceContext

type URL

type URL struct {
	Protocol   string            `json:"protocol"`
	Host       string            `json:"host"`
	Port       int               `json:"port"`
	Path       string            `json:"path"` //e.g. service name
	Group      string            `json:"group"`
	Parameters map[string]string `json:"parameters"`
	// contains filtered or unexported fields
}

func FromExtInfo

func FromExtInfo(extinfo string) *URL

func (*URL) CanServe

func (u *URL) CanServe(other *URL) bool

func (*URL) ClearCachedInfo

func (u *URL) ClearCachedInfo()

func (*URL) Copy

func (u *URL) Copy() *URL

func (*URL) GetAddressStr

func (u *URL) GetAddressStr() string

func (*URL) GetIdentity

func (u *URL) GetIdentity() string

GetIdentity return the identity of url. identity info includes protocol, host, port, path, group the identity will cached, so must clear cached info after update above info by calling ClearCachedInfo()

func (*URL) GetInt

func (u *URL) GetInt(key string) (int64, bool)

func (*URL) GetIntValue

func (u *URL) GetIntValue(key string, defaultValue int64) int64

func (*URL) GetMethodIntValue

func (u *URL) GetMethodIntValue(method string, methodDesc string, key string, defaultValue int64) int64

func (*URL) GetMethodPositiveIntValue

func (u *URL) GetMethodPositiveIntValue(method string, methodDesc string, key string, defaultValue int64) int64

func (*URL) GetParam

func (u *URL) GetParam(key string, defaultValue string) string

func (*URL) GetPortStr

func (u *URL) GetPortStr() string

func (*URL) GetPositiveIntValue

func (u *URL) GetPositiveIntValue(key string, defaultvalue int64) int64

func (*URL) GetStringParamsWithDefault

func (u *URL) GetStringParamsWithDefault(key string, defaultvalue string) string

func (*URL) GetTimeDuration

func (u *URL) GetTimeDuration(key string, unit time.Duration, defaultDuration time.Duration) time.Duration

GetTimeDuration get time duration from params.

func (*URL) MergeParams

func (u *URL) MergeParams(params map[string]string)

func (*URL) PutParam

func (u *URL) PutParam(key string, value string)

func (*URL) ToExtInfo

func (u *URL) ToExtInfo() string

type WithURL

type WithURL interface {
	GetURL() *URL
	SetURL(url *URL)
}

WithURL : can set and get URL

Jump to

Keyboard shortcuts

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