worker

package
v1.5.15 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIN_DATA_SIZE = 12
	UINT32_SIZE   = 4
	QUEUE_SIZE    = 64
	BUFFER_SIZE   = 512
	PARAMS_SCOPE  = 0x3A

	//package data type
	PDT_OK            = 1
	PDT_ERROR         = 2
	PDT_CAN_DO        = 3
	PDT_CANT_DO       = 4
	PDT_NO_JOB        = 5
	PDT_HAVE_JOB      = 6
	PDT_TOSLEEP       = 7
	PDT_WAKEUP        = 8
	PDT_WAKEUPED      = 9
	PDT_S_GET_DATA    = 10
	PDT_S_RETURN_DATA = 11
	PDT_W_GRAB_JOB    = 12
	PDT_W_ADD_FUNC    = 13
	PDT_W_DEL_FUNC    = 14
	PDT_W_RETURN_DATA = 15
	PDT_C_DO_JOB      = 16
	PDT_C_GET_DATA    = 17
)
View Source
const (
	CONN_TYPE_INIT   = 0
	CONN_TYPE_SERVER = 1
	CONN_TYPE_WORKER = 2
	CONN_TYPE_CLIENT = 3
	PARAMS_TYPE_ONE  = 4
	PARAMS_TYPE_MUL  = 5
	JOB_STATUS_INIT  = 6
	JOB_STATUS_DOING = 7
	JOB_STATUS_DONE  = 8
)

Variables

This section is empty.

Functions

func GetBuffer

func GetBuffer(n int) (buf []byte)

func GetStrParamsArr

func GetStrParamsArr(params []byte) []string

Types

type Agent

type Agent struct {
	sync.Mutex

	Worker *Worker
	Req    *Request
	Res    *Response
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(net, adrr string, w *Worker) *Agent

func (*Agent) Close

func (a *Agent) Close()

func (*Agent) Connect

func (a *Agent) Connect() (err error)

func (*Agent) Grab

func (a *Agent) Grab()

func (*Agent) ReConnect

func (a *Agent) ReConnect() error

func (*Agent) Read

func (a *Agent) Read() (data []byte, err error)

func (*Agent) Wakeup

func (a *Agent) Wakeup()

func (*Agent) Work

func (a *Agent) Work()

func (*Agent) Write

func (a *Agent) Write() (err error)

type Config

type Config struct {
	Worker *Worker
	Name   string
	Listen []string
}

Config ...

func (*Config) Build

func (config *Config) Build() *Server

Build create server instance, then initialize it with necessary interceptor

type Function

type Function struct {
	Func     JobFunc
	FuncName string
}

func NewFunction

func NewFunction(jf JobFunc, fname string) *Function

type Job

type Job interface {
	GetResponse() *Response
	ParseParams(params []byte)
	GetParams() []byte
	GetStrParams() []string
}

type JobFunc

type JobFunc func(Job) ([]byte, error)

type Request

type Request struct {
	DataType   uint32
	Data       []byte
	DataLen    uint32
	Handle     string
	HandleLen  uint32
	ParamsType uint32
	ParamsLen  uint32
	Params     []byte
	Ret        []byte
	RetLen     uint32
}

func NewReq

func NewReq() (req *Request)

func (*Request) AddFunctionPack

func (req *Request) AddFunctionPack(funcName string) (content []byte, err error)

打包内容-添加方法

func (*Request) DelFunctionPack

func (req *Request) DelFunctionPack(funcName string) (content []byte, err error)

打包内容-删除方法

func (*Request) EncodePack

func (req *Request) EncodePack() (data []byte)

打包

func (*Request) GrabDataPack

func (req *Request) GrabDataPack() (content []byte, err error)

打包内容-抓取任务

func (*Request) RetPack

func (req *Request) RetPack(ret []byte) (content []byte, err error)

打包内容-返回结果

func (*Request) WakeupPack

func (req *Request) WakeupPack()

打包内容-唤醒

type Response

type Response struct {
	DataType   uint32
	Data       []byte
	DataLen    uint32
	Handle     string
	HandleLen  uint32
	ParamsType uint32
	ParamsNum  uint32
	ParamsLen  uint32
	Params     []byte
	StrParams  []string
	Ret        []byte
	RetLen     uint32
	Agent      *Agent
}

func DecodePack

func DecodePack(data []byte) (resp *Response, resLen int, err error)

解包

func NewRes

func NewRes() (res *Response)

func (*Response) GetParams

func (resp *Response) GetParams() []byte

func (*Response) GetResponse

func (resp *Response) GetResponse() *Response

func (*Response) GetStrParams

func (resp *Response) GetStrParams() []string

func (*Response) ParseParams

func (resp *Response) ParseParams(params []byte)

type RetStruct

type RetStruct struct {
	Code int
	Msg  string
	Data []byte
}

func GetRetStruct

func GetRetStruct() *RetStruct

type Server

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

Server ...

func (*Server) GracefulStop

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

GracefulStop ..

func (*Server) Info

func (s *Server) Info() *server.ServiceInfo

Info ..

func (*Server) Serve

func (s *Server) Serve() error

Serve ..

func (*Server) Stop

func (s *Server) Stop() error

Stop ..

type Worker

type Worker struct {
	sync.Mutex

	Agents   []*Agent
	Funcs    map[string]*Function
	FuncsNum int
	Resps    chan *Response
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker() *Worker

func (*Worker) AddFunction

func (w *Worker) AddFunction(funcName string, jobFunc JobFunc) (err error)

func (*Worker) AddServer

func (w *Worker) AddServer(net, addr string) (err error)

func (*Worker) DelFunction

func (w *Worker) DelFunction(funcName string) (err error)

func (*Worker) DoFunction

func (w *Worker) DoFunction(resp *Response) (err error)

func (*Worker) FuncBroadcast

func (w *Worker) FuncBroadcast(funcName string, flag int)

func (*Worker) GetFunction

func (w *Worker) GetFunction(funcName string) (function *Function, err error)

func (*Worker) WorkerClose

func (w *Worker) WorkerClose() error

func (*Worker) WorkerDo

func (w *Worker) WorkerDo()

func (*Worker) WorkerReady

func (w *Worker) WorkerReady() (err error)

Jump to

Keyboard shortcuts

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