kernel

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 22 Imported by: 0

README

Kernel

go 版本otp,提供一个简单的supervisor && gen_server的模型

Documentation

Index

Constants

View Source
const (
	ExitReasonNormal = "normal"
	ExitReasonError  = "error"
)
View Source
const (
	SupChildTypeWorker = iota
	SupChildTypeSup
)
View Source
const (
	TimerTypeForever timerType = 1 << iota
	TimerTypeOnce
)
View Source
const (
	CallErrorTypeTimeOut callErrorType = iota + 1
	CallErrorTypeNoProc
	CallErrorTypeNodeNotConnect
)
View Source
const (
	APP_BOOT_TYPE_START = iota + 1
	APP_BOOT_TYPE_RESTART
)
View Source
const (
	APP_STOP_TYPE_NORMAL = iota + 1
	APP_STOP_TYPE_RESTART
)
View Source
const (
	Millisecond int64 = 1000
)

Variables

View Source
var Env = &env{
	WriteLogStd:        true,
	LogPath:            "",
	ActorChanCacheSize: 100,
	timerMinTick:       100,
	TimerProcNum:       3,
}
View Source
var ErrAppAlreadyStarted = errors.New("app already started ")
View Source
var ErrAppNotStart = errors.New("app not Start ")
View Source
var ErrAppStart = errors.New("app start catch error ")

Functions

func ActorOpt

func ActorOpt(opt ...interface{}) []interface{}

func AppRestart

func AppRestart(name string) (err error)

func AppStart

func AppStart(app Application) (err error)

func AppStop

func AppStop(name string)

func Call

func Call(pid *Pid, request interface{}) (bool, interface{})

func CallName

func CallName(name string, request interface{}) (bool, interface{})

func CallNameNode

func CallNameNode(name string, node interface{}, request interface{}) (bool, interface{})

func CallTimeOut

func CallTimeOut(pid *Pid, request interface{}, timeOut time.Duration) (bool, interface{})

func Cast

func Cast(pid *Pid, msg interface{})

func CastName

func CastName(name string, msg interface{})

func CastNameNode

func CastNameNode(name string, node interface{}, msg interface{})

func CatchFun

func CatchFun(f func())

func ConsoleArg

func ConsoleArg(example string) consoleArg

func ConsoleCommit

func ConsoleCommit(commit string) consoleCommit

func ConsoleConfirm

func ConsoleConfirm(confirm string) consoleConfirm

func ConsoleHandler

func ConsoleHandler(command string, handler consoleHandler, opt ...interface{}) *chandler

func DayNum

func DayNum(t time.Time) int64

获取当前时间距离目标时间的天数

func DayNumFromUnix

func DayNumFromUnix(now int64) int64

根据时间戳,获取距离1970.1.1 的天数

func DebugLog

func DebugLog(format string, args ...interface{})

func DeepCopy

func DeepCopy(src interface{}) interface{}

func ErrorLog

func ErrorLog(format string, args ...interface{})

func GetMainRoot

func GetMainRoot() string

获取二进制执行文件所在目录

func InitStop

func InitStop()

停止整个服务

func IsNodeConnect

func IsNodeConnect(nodeName string) bool

func KernelStart

func KernelStart(start func(), stop func())
func Link(srcPid, destPid *Pid)

func LoggerWriter

func LoggerWriter() io.Writer

func MakeArgs

func MakeArgs(args ...interface{}) []interface{}

return args in slice

func Midnight

func Midnight() int64

0点的时间戳

func NodeDisconnect

func NodeDisconnect(node *Node)

func Now

func Now() int64

unix时间戳

func Now2

func Now2() int64

毫秒unix时间戳

func NowToTime

func NowToTime(now int64) time.Time

func NowToTimeString

func NowToTimeString(now int64) string

func Register

func Register(name string, pid *Pid)

func RegisterNotExist

func RegisterNotExist(name string, pid *Pid)

func Reply

func Reply(recCh chan interface{}, callID int64, result interface{})

func SendAfter

func SendAfter(timerType timerType, pid *Pid, inv int64, msg interface{})

func SendAfterForever

func SendAfterForever(pid *Pid, inv int64, msg interface{})

func SetLogLevel

func SetLogLevel(lv LogLevel)

func SetLoggerOut

func SetLoggerOut(writer io.Writer)

func SetNodeNetWork

func SetNodeNetWork(node *Node, pid *Pid)

func SetSelfNodeName

func SetSelfNodeName(name string)

func StartConsole

func StartConsole(handlers ...*chandler)

func SupStop

func SupStop(sup interface{})

func TimeString

func TimeString(t time.Time) string

func TryGetName

func TryGetName(pid *Pid) string

func UnHandleMsg

func UnHandleMsg(msg interface{})

func UnRegister

func UnRegister(name string)

func WeekDay

func WeekDay() int64

func WeekDayFromUnix

func WeekDayFromUnix(now int64) int64

func WeekOneMidnight

func WeekOneMidnight() int64

本周1的0点时间戳

Types

type Actor

type Actor struct {
	// 初始化回调
	Init InitFunc
	// 接收消息
	HandleCast HandleCastFunc
	// 接受同步调用
	HandleCall HandleCallFunc
	// actor退出回调
	// 非必要实现函数
	Terminate TerminateFunc
	// 当发生catch错误时调用,如果返回false,那么进程将会退出
	// 非必要实现函数
	ErrorHandler ErrorHandleFunc
}

func DefaultActor

func DefaultActor() *Actor

纯粹方便测试用,不用每次编写一堆相同代码

func NewActor

func NewActor(funList ...interface{}) *Actor

减少代码规模,但是不应该用在需要高性能的地方

type ActorChanCacheSize

type ActorChanCacheSize int

type AppBootType

type AppBootType int

type AppStopType

type AppStopType int

type Application

type Application interface {
	Name() string
	Start(bootType AppBootType) *Pid // return the supervisor pid
	Stop(stopType AppStopType)
	SetEnv(Key string, value interface{})
	GetEnv(key string) interface{}
}

func AppInfo

func AppInfo(name string) Application

type CallError

type CallError struct {
	ErrType callErrorType
	// contains filtered or unexported fields
}

type CallInfo

type CallInfo struct {
	RecCh   chan interface{}
	CallID  int64
	Request interface{}
}

type CallResult

type CallResult struct {
	ID     int64
	Result interface{}
}

type ConsoleCommand

type ConsoleCommand struct {
	RecvPid *Pid
	CType   int32
	Command string
}

type Context

type Context struct {
	State interface{}
	// contains filtered or unexported fields
}

func (*Context) Call

func (c *Context) Call(pid *Pid, request interface{}) (bool, interface{})

func (*Context) CallName

func (c *Context) CallName(name string, request interface{}) (bool, interface{})

func (*Context) CallNameNode

func (c *Context) CallNameNode(name string, node interface{}, request interface{}) (bool, interface{})

func (*Context) Cast

func (c *Context) Cast(pid *Pid, msg interface{})

func (*Context) CastName

func (c *Context) CastName(name string, msg interface{})

func (*Context) CastNameNode

func (c *Context) CastNameNode(name string, node interface{}, msg interface{})

func (*Context) CastSelf

func (c *Context) CastSelf(msg interface{})

func (*Context) ChangeCallMode

func (c *Context) ChangeCallMode()

func (*Context) Exit

func (c *Context) Exit(reason string)
func (c *Context) Link(pid *Pid)

func (*Context) Name

func (c *Context) Name() string

如果自身注册了名字,返回

func (*Context) Self

func (c *Context) Self() *Pid
func (c *Context) StartLink(newActor *Actor, args ...interface{}) (*Pid, interface{})

func (*Context) StartLinkOpt

func (c *Context) StartLinkOpt(newActor *Actor, opt []interface{}, args ...interface{}) (*Pid, interface{})
func (c *Context) StartNameLink(name string, newActor *Actor, args ...interface{}) (*Pid, interface{})

type Empty

type Empty struct{}

type ErrorHandleFunc

type ErrorHandleFunc func(ctx *Context, err interface{}) bool

type HandleCallFunc

type HandleCallFunc func(ctx *Context, request interface{}) interface{}

type HandleCastFunc

type HandleCastFunc func(ctx *Context, msg interface{})

type InitFunc

type InitFunc func(ctx *Context, pid *Pid, args ...interface{}) interface{}

type KMsg

type KMsg struct {
	ModID int32
	Msg   interface{}
}

type LogLevel

type LogLevel int

type Loop

type Loop struct{}

type Node

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

func GetNode

func GetNode(nodeName string) *Node

func Nodes

func Nodes() []*Node

func SelfNode

func SelfNode() *Node

func (*Node) Equal

func (n *Node) Equal(node *Node) bool

判断节点相等

func (*Node) Name

func (n *Node) Name() string

type NodeCall

type NodeCall struct {
	Dest   *Pid
	Req    interface{}
	CallID int64
	Ch     chan interface{}
}

type NodeCallName

type NodeCallName struct {
	Dest   string
	Req    interface{}
	CallID int64
	Ch     chan interface{}
}

type NodeMsg

type NodeMsg struct {
	Dest *Pid
	Msg  interface{}
}

type NodeMsgName

type NodeMsgName struct {
	Dest string
	Msg  interface{}
}

type Pid

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

func DecodePid

func DecodePid(buf []byte, index int) (int, *Pid)

func GetNodeNetWork

func GetNodeNetWork(node *Node) (*Pid, bool)

func LocalPid

func LocalPid(id int64) *Pid

func Start

func Start(newActor *Actor, args ...interface{}) (*Pid, interface{})

func StartName

func StartName(name string, newActor *Actor, args ...interface{}) (*Pid, interface{})

func StartNameOpt

func StartNameOpt(name string, newActor *Actor, opt []interface{}, args ...interface{}) (*Pid, interface{})

func StartOpt

func StartOpt(actor *Actor, opt []interface{}, args ...interface{}) (*Pid, interface{})

func SupStart

func SupStart(name string, initChild ...*SupChild) *Pid

func SupStartChild

func SupStartChild(sup interface{}, child *SupChild) (interface{}, *Pid)

func WhereIs

func WhereIs(name string) *Pid

func (*Pid) Cast

func (p *Pid) Cast(msg interface{})

func (*Pid) GetChannel

func (p *Pid) GetChannel() chan interface{}

func (*Pid) GetID

func (p *Pid) GetID() int64

func (*Pid) IsAlive

func (p *Pid) IsAlive() bool

func (*Pid) Node

func (p *Pid) Node() *Node

func (*Pid) SetDie

func (p *Pid) SetDie()

在一些阻塞的进程里,可以设置为消亡,这样停服就不会卡主

func (*Pid) String

func (p *Pid) String() string

func (*Pid) ToBytes

func (p *Pid) ToBytes(buf []byte) []byte

type PidExit

type PidExit struct {
	Pid    *Pid
	Reason *Terminate
}

type SupChild

type SupChild struct {
	ChildType int
	ReStart   bool
	Name      string
	Svr       *Actor
	InitOpt   []interface{}
	InitArgs  []interface{}
}

type SupChildInfo

type SupChildInfo struct {
	*SupChild
	Pid *Pid
}

func SupWhichChild

func SupWhichChild(sup interface{}) []*SupChildInfo

type Terminate

type Terminate struct {
	Reason string
}

type TerminateFunc

type TerminateFunc func(ctx *Context, reason *Terminate)

type TimerChan

type TimerChan chan *actorTimer

func TimerStartHandler

func TimerStartHandler(GName string, minInv int64, handlerProcNum int, chanSize int) TimerChan

单独开启一个timer组

func (TimerChan) SendAfter

func (r TimerChan) SendAfter(timerType timerType, pid *Pid, inv int64, msg interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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