edge

package
v0.14.12 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: BSD-3-Clause Imports: 33 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRestProxy added in v0.10.0

func NewRestProxy(onClientMessage, onServerMessage RestHandler) *restProxy

Types

type Builtin added in v0.5.0

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

Builtin keep track of pages distribution over Edge servers.

type DispatchCtx

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

DispatchCtx holds the context of the dispatcher's request. Each DispatchCtx could holds one or many RequestCtx. DispatchCtx lives until the last of its RequestCtx children.

func (*DispatchCtx) BufferPop added in v0.1.9

func (ctx *DispatchCtx) BufferPop(f func(envelope *rony.MessageEnvelope)) bool

func (*DispatchCtx) BufferPopAll added in v0.10.0

func (ctx *DispatchCtx) BufferPopAll(f func(envelope *rony.MessageEnvelope))

func (*DispatchCtx) BufferPush added in v0.1.9

func (ctx *DispatchCtx) BufferPush(m *rony.MessageEnvelope)

func (*DispatchCtx) BufferSize added in v0.1.9

func (ctx *DispatchCtx) BufferSize() int32

func (*DispatchCtx) Conn

func (ctx *DispatchCtx) Conn() rony.Conn

func (*DispatchCtx) Debug

func (ctx *DispatchCtx) Debug()

func (*DispatchCtx) Fill added in v0.14.1

func (ctx *DispatchCtx) Fill(requestID uint64, constructor uint64, p proto.Message, kv ...*rony.KeyValue)

func (*DispatchCtx) FillBytes added in v0.14.1

func (ctx *DispatchCtx) FillBytes(data []byte) error

func (*DispatchCtx) FillEnvelope

func (ctx *DispatchCtx) FillEnvelope(e *rony.MessageEnvelope)

func (*DispatchCtx) Get

func (ctx *DispatchCtx) Get(key string) interface{}

func (*DispatchCtx) GetBool

func (ctx *DispatchCtx) GetBool(key string) bool

func (*DispatchCtx) GetBytes

func (ctx *DispatchCtx) GetBytes(key string, defaultValue []byte) []byte

func (*DispatchCtx) GetInt64

func (ctx *DispatchCtx) GetInt64(key string, defaultValue int64) int64

func (*DispatchCtx) GetString

func (ctx *DispatchCtx) GetString(key string, defaultValue string) string

func (*DispatchCtx) Kind added in v0.1.4

func (ctx *DispatchCtx) Kind() MessageKind

Kind identifies that this dispatch context is generated from Tunnel or Gateway. This helps developer to apply different strategies based on the source of the incoming message

func (*DispatchCtx) ServerID added in v0.1.9

func (ctx *DispatchCtx) ServerID() string

func (*DispatchCtx) Set

func (ctx *DispatchCtx) Set(key string, v interface{})

func (*DispatchCtx) StreamID

func (ctx *DispatchCtx) StreamID() int64

type Dispatcher

type Dispatcher interface {
	// OnMessage is called on every message pushed to RequestCtx.
	// All the input arguments are valid in the function context, if you need to pass 'envelope' to other
	// async functions, make sure to hard copy (clone) it before sending it.
	// **NOTE**: This is not called on non-persistent connections, instead it is user's responsibility to check the
	// ctx.BufferSize() and ctx.BufferPop() functions
	OnMessage(ctx *DispatchCtx, envelope *rony.MessageEnvelope)
	// Interceptor is called before any handler called.
	// All the input arguments are valid in the function context, if you need to pass 'data' or 'envelope' to other
	// async functions, make sure to hard copy (clone) it before sending it. If 'err' is not nil then envelope will be
	// discarded, it is the user's responsibility to send back appropriate message using 'conn'
	// Note that conn IS NOT nil in any circumstances.
	Interceptor(ctx *DispatchCtx, data []byte) (err error)
	// Done will be called when the context has been finished, this lets cleaning up, or in case you need to flush the
	// messages and updates in one go.
	Done(ctx *DispatchCtx)
	// OnOpen will be called when a new connection has been opened
	OnOpen(conn rony.Conn, kvs ...*rony.KeyValue)
	// OnClose will be called when a connection is closed
	OnClose(conn rony.Conn)
}

type DummyGatewayConfig added in v0.1.8

type DummyGatewayConfig = dummyGateway.Config

type GossipClusterConfig added in v0.1.8

type GossipClusterConfig struct {
	Bootstrap      bool
	ReplicaSet     uint64
	GossipIP       string
	GossipPort     int
	AdvertisedIP   string
	AdvertisedPort int
}

type Handler

type Handler = func(ctx *RequestCtx, in *rony.MessageEnvelope)

type HandlerOption added in v0.5.7

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

HandlerOption is a structure holds all the information required for a handler.

func NewHandlerOptions added in v0.3.12

func NewHandlerOptions() *HandlerOption

func (*HandlerOption) Append added in v0.5.7

func (ho *HandlerOption) Append(h ...Handler) *HandlerOption

Append adds the h handlers after already set handlers

func (*HandlerOption) GatewayOnly added in v0.5.7

func (ho *HandlerOption) GatewayOnly() *HandlerOption

GatewayOnly makes this method only available through gateway messages.

func (*HandlerOption) Prepend added in v0.5.7

func (ho *HandlerOption) Prepend(h ...Handler) *HandlerOption

Prepend adds the h handlers before already set handlers

func (*HandlerOption) SetConstructor added in v0.6.3

func (ho *HandlerOption) SetConstructor(constructors ...uint64) *HandlerOption

func (*HandlerOption) SetHandler added in v0.6.3

func (ho *HandlerOption) SetHandler(h ...Handler) *HandlerOption

SetHandler replaces the handlers for this constructor with h

func (*HandlerOption) TunnelOnly added in v0.5.7

func (ho *HandlerOption) TunnelOnly() *HandlerOption

TunnelOnly makes this method only available through tunnel messages.

type InsertOption added in v0.10.0

type InsertOption func(*trieNode)

InsertOption is just a function which accepts a pointer to a trieNode which can alt its `Handler`, `Tag` and `Data` fields.

See `WithHandler`, `WithTag` and `WithData`.

func WithProxyFactory added in v0.10.0

func WithProxyFactory(proxy RestProxy) InsertOption

WithProxyFactory sets the node's `Handler` field (useful for HTTP).

func WithTag added in v0.10.0

func WithTag(tag string) InsertOption

WithTag sets the node's `Tag` field (may be useful for HTTP).

type MessageKind added in v0.5.8

type MessageKind byte
const (
	GatewayMessage MessageKind
	TunnelMessage
)

func (MessageKind) String added in v0.5.8

func (c MessageKind) String() string

type Option

type Option func(edge *Server)

func WithCustomDispatcher added in v0.14.11

func WithCustomDispatcher(d Dispatcher) Option

WithCustomDispatcher enables custom dispatcher to write your specific event handlers.

func WithCustomRouter added in v0.14.1

func WithCustomRouter(r rony.Router) Option

func WithCustomerCluster added in v0.14.1

func WithCustomerCluster(c rony.Cluster) Option

func WithDataDir added in v0.5.0

func WithDataDir(path string) Option

func WithGossipCluster added in v0.1.5

func WithGossipCluster(clusterConfig GossipClusterConfig) Option

WithGossipCluster enables the cluster in gossip mode. This mod is eventually consistent mode but there is no need to a central key-value store or any other 3rd party service to run the cluster

func WithInMemoryStore added in v0.12.9

func WithInMemoryStore(b bool) Option

WithInMemoryStore make the store in-memory and non-persistent.

func WithScyllaRouter added in v0.14.1

func WithScyllaRouter(config ScyllaRouterConfig) Option

func WithSqlRouter added in v0.14.6

func WithSqlRouter(config SqlRouterConfig) Option

func WithTcpGateway

func WithTcpGateway(gatewayConfig TcpGatewayConfig) Option

WithTcpGateway set the gateway to tcp which can support http and/or websocket Only one gateway could be set and if you set another gateway it panics on runtime.

func WithTestGateway

func WithTestGateway(gatewayConfig DummyGatewayConfig) Option

WithTestGateway set the gateway to a dummy gateway which is useful for writing tests. Only one gateway could be set and if you set another gateway it panics on runtime.

func WithUdpTunnel added in v0.1.8

func WithUdpTunnel(config UdpTunnelConfig) Option

WithUdpTunnel set the tunnel to a udp based tunnel which provides communication channel between edge servers.

type ParamsSetter added in v0.10.0

type ParamsSetter interface {
	Set(string, interface{})
}

ParamsSetter is the interface which should be implemented by the params writer for `search` in order to store the found named path parameters, if any.

type RequestCtx

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

RequestCtx holds the context of an RPC handler

func (*RequestCtx) Cluster added in v0.2.10

func (ctx *RequestCtx) Cluster() rony.Cluster

func (*RequestCtx) ClusterEdges added in v0.9.0

func (ctx *RequestCtx) ClusterEdges(replicaSet uint64, edges *rony.Edges) (*rony.Edges, error)

func (*RequestCtx) Conn

func (ctx *RequestCtx) Conn() rony.Conn

func (*RequestCtx) ConnID

func (ctx *RequestCtx) ConnID() uint64

func (*RequestCtx) Get

func (ctx *RequestCtx) Get(key string) interface{}

func (*RequestCtx) GetBool

func (ctx *RequestCtx) GetBool(key string) bool

func (*RequestCtx) GetBytes

func (ctx *RequestCtx) GetBytes(key string, defaultValue []byte) []byte

func (*RequestCtx) GetInt64

func (ctx *RequestCtx) GetInt64(key string, defaultValue int64) int64

func (*RequestCtx) GetString

func (ctx *RequestCtx) GetString(key string, defaultValue string) string

func (*RequestCtx) Kind added in v0.1.4

func (ctx *RequestCtx) Kind() MessageKind

func (*RequestCtx) Log added in v0.3.18

func (ctx *RequestCtx) Log() log.Logger

func (*RequestCtx) NextCanGo added in v0.14.1

func (ctx *RequestCtx) NextCanGo()

NextCanGo is useful only if the main request is rony.MessageContainer with SyncRun flag set to TRUE. Then by calling this function it lets the next request (if any) executed concurrently.

func (*RequestCtx) PushCustomError

func (ctx *RequestCtx) PushCustomError(code, item string, desc string)

func (*RequestCtx) PushCustomMessage

func (ctx *RequestCtx) PushCustomMessage(requestID uint64, constructor uint64, message proto.Message, kvs ...*rony.KeyValue)

func (*RequestCtx) PushError

func (ctx *RequestCtx) PushError(err *rony.Error)

func (*RequestCtx) PushMessage

func (ctx *RequestCtx) PushMessage(constructor uint64, proto proto.Message)

func (*RequestCtx) PushRedirectRequest added in v0.2.10

func (ctx *RequestCtx) PushRedirectRequest(replicaSet uint64)

func (*RequestCtx) PushRedirectSession added in v0.2.10

func (ctx *RequestCtx) PushRedirectSession(replicaSet uint64)

func (*RequestCtx) ReplicaSet added in v0.5.7

func (ctx *RequestCtx) ReplicaSet() uint64

func (*RequestCtx) ReqID

func (ctx *RequestCtx) ReqID() uint64

func (*RequestCtx) Router added in v0.14.1

func (ctx *RequestCtx) Router() rony.Router

func (*RequestCtx) ServerID added in v0.1.4

func (ctx *RequestCtx) ServerID() string

func (*RequestCtx) Set

func (ctx *RequestCtx) Set(key string, v interface{})

func (*RequestCtx) StopExecution

func (ctx *RequestCtx) StopExecution()

func (*RequestCtx) Stopped

func (ctx *RequestCtx) Stopped() bool

func (*RequestCtx) Store added in v0.7.2

func (ctx *RequestCtx) Store() *store.Store

func (*RequestCtx) TryTunnelRequest added in v0.9.0

func (ctx *RequestCtx) TryTunnelRequest(attempts int, retryWait time.Duration, replicaSet uint64, req, res *rony.MessageEnvelope) error

func (*RequestCtx) TunnelRequest added in v0.9.0

func (ctx *RequestCtx) TunnelRequest(replicaSet uint64, req, res *rony.MessageEnvelope) error

type RestHandler added in v0.10.0

type RestHandler func(conn rony.RestConn, ctx *DispatchCtx) error

type RestProxy added in v0.10.0

type RestProxy interface {
	ClientMessage(conn rony.RestConn, ctx *DispatchCtx) error
	ServerMessage(conn rony.RestConn, ctx *DispatchCtx) error
}

type ScyllaRouterConfig added in v0.14.1

type ScyllaRouterConfig struct {
	DbSession gocqlx.Session
}

type Server

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

func NewServer

func NewServer(serverID string, opts ...Option) *Server

func (*Server) Cluster added in v0.3.16

func (edge *Server) Cluster() rony.Cluster

Cluster returns a reference to the underlying cluster of the Edge server

func (*Server) Gateway added in v0.5.18

func (edge *Server) Gateway() rony.Gateway

Gateway returns a reference to the underlying gateway of the Edge server

func (*Server) GetGatewayConn added in v0.0.6

func (edge *Server) GetGatewayConn(connID uint64) rony.Conn

GetGatewayConn return the gateway connection identified by connID or returns nil if not found.

func (*Server) GetHandler added in v0.5.7

func (edge *Server) GetHandler(constructor uint64) *HandlerOption

GetHandler returns the handlers of the constructor

func (*Server) GetServerID

func (edge *Server) GetServerID() string

GetServerID return this server id, which MUST be unique in the cluster otherwise the behaviour is unknown.

func (*Server) SetCustomDispatcher added in v0.14.11

func (edge *Server) SetCustomDispatcher(d Dispatcher)

SetCustomDispatcher replace the default dispatcher with your custom dispatcher. Usually you don't need to use custom dispatcher, but in some rare cases you can implement your own custom dispatcher

func (*Server) SetGlobalPostHandlers added in v0.3.8

func (edge *Server) SetGlobalPostHandlers(handlers ...Handler)

SetGlobalPostHandlers set the handler which will be called after executing any request. These pre handlers are like middlewares which will be automatically triggered for each request. If you want to set post handler for specific request the your must use SetHandlers, PrependHandlers or AppendHandlers

func (*Server) SetGlobalPreHandlers added in v0.3.8

func (edge *Server) SetGlobalPreHandlers(handlers ...Handler)

SetGlobalPreHandlers set the handler which will be called before executing any request. These pre handlers are like middlewares which will be automatically triggered for each request. If you want to set pre handler for specific request the your must use SetHandlers, PrependHandlers or AppendHandlers

func (*Server) SetHandler added in v0.5.7

func (edge *Server) SetHandler(ho *HandlerOption)

SetHandler set the handlers for the constructor.

func (*Server) SetRestProxy added in v0.10.0

func (edge *Server) SetRestProxy(method string, path string, p RestProxy)

SetRestProxy set a REST wrapper to expose RPCs in REST (Representational State Transfer) format

func (*Server) Shutdown

func (edge *Server) Shutdown()

Shutdown gracefully shutdown the services

func (*Server) ShutdownWithSignal

func (edge *Server) ShutdownWithSignal(signals ...os.Signal) error

ShutdownWithSignal blocks until any of the signals has been called

func (*Server) Start added in v0.1.9

func (edge *Server) Start()

Start is a helper function which tries to start all three parts of the edge server This function does not return any error, if you need to make sure all the parts are started with no error, then you must start each section separately. i.e. use StartGateway, StartCluster and StartTunnel functions.

func (*Server) StartCluster

func (edge *Server) StartCluster() (err error)

StartCluster is non-blocking function which runs the cluster component of the Edge server.

func (*Server) StartGateway

func (edge *Server) StartGateway() error

StartGateway is non-blocking function runs the gateway in background so we can accept clients requests

func (*Server) StartTunnel added in v0.1.9

func (edge *Server) StartTunnel() error

StartTunnel is non-blocking function runs the gateway in background so we can accept other servers requests

func (*Server) Stats

func (edge *Server) Stats() Stats

Stats exports some internal metrics data packed in 'Stats' struct

func (*Server) Store added in v0.7.2

func (edge *Server) Store() *store.Store

Store returns the store component of the Edge server.

func (*Server) TryTunnelRequest added in v0.9.0

func (edge *Server) TryTunnelRequest(attempts int, retryWait time.Duration, replicaSet uint64, req, res *rony.MessageEnvelope) error

func (*Server) Tunnel added in v0.9.0

func (edge *Server) Tunnel() rony.Tunnel

Tunnel returns a reference to the underlying tunnel of the Edge server

func (*Server) TunnelRequest added in v0.9.0

func (edge *Server) TunnelRequest(replicaSet uint64, req, res *rony.MessageEnvelope) error

TunnelRequest sends and receives a request through the Tunnel interface of the receiver Edge node.

func (*Server) WaitForSignal added in v0.12.15

func (edge *Server) WaitForSignal(signals ...os.Signal)

type SqlRouterConfig added in v0.14.6

type SqlRouterConfig struct {
	DB *gorm.DB
}

type Stats

type Stats struct {
	Address         string
	ReplicaSet      uint64
	Members         int
	MembershipScore int
	TunnelAddr      []string
	GatewayProtocol rony.GatewayProtocol
	GatewayAddr     []string
}

Stats exports some internal metrics data

type TcpGatewayConfig added in v0.1.8

type TcpGatewayConfig struct {
	Concurrency   int
	ListenAddress string
	MaxBodySize   int
	MaxIdleTime   time.Duration
	Protocol      rony.GatewayProtocol
	ExternalAddrs []string
}

type UdpTunnelConfig added in v0.1.8

type UdpTunnelConfig struct {
	ListenAddress string
	MaxBodySize   int
	ExternalAddrs []string
}

Jump to

Keyboard shortcuts

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