Documentation ¶
Index ¶
- Constants
- Variables
- type ActorState
- type AsyncCallBack
- type Context
- type IActor
- type IActorContainer
- type IComponent
- type IComponentPool
- type IConfig
- type IConn
- type IContext
- type IEntity
- type IEntityNetClient
- type IModel
- type IModule
- type IModuleCtor
- type INetClient
- type IProcess
- type IProcessConfig
- type IProxy
- type IRegistry
- type IReqContext
- type IRouter
- type IRuntime
- type ISession
- type ISessionManager
- type ITestCase
- type Key
- type LongPacketCreator
- type LongPacketPicker
- type Server
- type Service
- type ServiceType
Constants ¶
const ( DEFAULT_PACKET_LEN = 2048 * 4 DEFAULT_ACTOR_TTL = 15 )
Variables ¶
var (
ErrDataNil = errors.New("data nil")
)
Functions ¶
This section is empty.
Types ¶
type ActorState ¶
type ActorState int //Actor health state
const ( ACTOR_STARTING ActorState = iota + 1 ACTOR_HEALTHY ACTOR_UNHEALTHY ACTOR_ERRORED ACTOR_STOPPED )
type AsyncCallBack ¶
type AsyncCallBack func(context IReqContext)
type Context ¶
type Context struct { SessionCreator func(conn IConn) ISession Splitter bufio.SplitFunc // packet splitter IPChecker func(ip string) bool // check if an accepted connection is allowed IdleTimeAfterOpen time.Duration // idle time when open, conn will be closed if not activated after this time ReadBufferSize int // buffer size for reading WriteBufferSize int // buffer size for writing UseNoneBlockingChan bool // use none blocking chan ChanSize int // chan size for bufferring MaxMessageSize int // max message size for a single packet MergedWriteBufferSize int // buffer size for merged write DisableMergedWrite bool // disable merge multiple message to a single net.Write EnableStatistics bool // enable statistics of packets send and recv Extra interface{} // used for special cases when custom data is needed LongPacketPicker LongPacketPicker // check and pick long packet when recv LongPacketCreator LongPacketCreator // create long packet for send MaxPacketWriteLen int // data size for long packet }
Content context for create a dialer or a listener
type IActor ¶
type IActor interface { IEntity IProxy IModule GetLeaseId() (clientv3.LeaseID, bool, error) Update(dt time.Duration, now time.Time) }
IActor standard interface for actor
type IActorContainer ¶
type IComponent ¶
type IComponent interface { protocol.ISerializable GetEntity() IEntity SetDirty(d bool) SetRuntime(engine IRuntime) GetRuntime() IRuntime SetEntity(e IEntity) OnAdd(e IEntity, r IRuntime) OnRemove(e IEntity, r IRuntime) OnCreate(r IRuntime) OnDestroy(r IRuntime) GetSibling(t protocol.BINARY_TAG) IComponent }
type IComponentPool ¶
type IComponentPool interface { Recycle(comp IComponent) Get() IComponent Create(args ...interface{}) IComponent Destroy() }
type IConfig ¶
type IConfig interface { Save() error Load() error LoadFromRemote() error SetRemoteConfig(p string, etcd string) Set(key string, value interface{}) Get(key string) interface{} Sub(key string) IConfig GetBool(key string) bool GetFloat64(key string) float64 GetInt(key string) int GetString(key string) string GetStringMap(key string) map[string]interface{} GetStringMapString(key string) map[string]string GetStringMapStringSlice(key string) map[string][]string GetIntSlice(key string) []int GetSizeInBytes(key string) uint GetStringSlice(key string) []string GetTime(key string) time.Time GetDuration(key string) time.Duration IsSet(key string) bool AllSettings() map[string]interface{} }
type IConn ¶
type IConn interface { net.Conn SetUserData(userData interface{}) // set application layer reference data GetUserData() interface{} // get application layer reference data GetSession() ISession // get the bound session GetConnTime() time.Time // get connection init time Activate() // activate the conn, used with idle check // GraceClose() error // gracefully close the connection, after all the pending packets sent to the peer Wait() // wait for close }
IConn interface for a connection, either a client connection or server accepted connection
type IContext ¶
type IContext interface { Get(key string) interface{} GetIdType(key string) util.ID GetProcessIdType(key string) util.ProcessId GetString(key string) string Set(key string, value interface{}) }
IContext context interface
type IEntity ¶
type IEntity interface { Dirty() bool SetDirty(bool) Get(t protocol.BINARY_TAG) IComponent GetOrCreate(t protocol.BINARY_TAG) IComponent Add(c IComponent) Remove(t protocol.BINARY_TAG) IComponent RemoveAll() SetId(id util.ID) GetId() util.ID Components() map[protocol.BINARY_TAG]IComponent }
type IEntityNetClient ¶ added in v0.0.8
type IEntityNetClient interface { IEntity INetClient }
type IModule ¶
type IModule interface { Type() string Load(conf IConfig) error Unload() error GetProcess() IProcess SetProcess(IProcess) Start() *promise.Promise Stop() *promise.Promise OnStart() error OnStop() error }
IModule module interface
type IModuleCtor ¶
IModuleCtor module export interface
type INetClient ¶
type INetClient interface { events.EventEmmiter Connect(addr string) *promise.Promise Disconnect(bool) *promise.Promise Request(req interface{}) *promise.Promise Connected() bool OnRecvCmd(cmdId protocol.BINARY_TAG, time time.Duration) *promise.Promise OnRecv(conn IConn, data []byte) }
INetClient interface for client
type IProcess ¶
type IProcess interface { IRegistry IActorContainer IRouter Add(modules IModule) IModule //add a module RegisterModule(ctor IModuleCtor) //register a module ctor LoadAllModule(IProcessConfig) error //load all module from config LoadMod(name string, conf IConfig) error //load a module with config UnloadMod(name string) error //unload a module Get(name string) IModule //get a module Load(IProcessConfig) error //load config Start() error //start process Stop() error //stop process Id() util.ProcessId //ProcessId GenId() util.ID //gen snowflake Id,goroutine safe GetLogger() *log.ComposeLogger //get process logger GetMongo() *qmgo.Database //get mongo client GetRedis() *redisclient.Client //get redis client GetEtcd() *etcdclient.Client //get etcd client GlobalMutex(key string, ttl int) (*etcdclient.Mutex, error) //create a distributed global mutex based on etcd Config() IConfig //get config GameId() string //get game id ServerId() int32 //get server id GameServerId() string //get game and server id Version() string //get version }
IProcess the interface for application entry
type IProcessConfig ¶
type IProxy ¶
type IProxy interface { ReceiveMessage(msg *protocol.RouteMessage) OnMessage(msg *protocol.RouteMessage) SendMessage(actorId util.ID, transId uint32, msg protocol.ISerializable) error Call(actorId util.ID, req protocol.ISerializable) (protocol.ISerializable, error) }
IProxy universal module interface for connection
type IRegistry ¶
type IRegistry interface { RegisterProcessInfo() error GetProcessIdByActor(actorId util.ID) (util.ProcessId, error) RegisterActors() error RegisterActorRemote(actor IActor) error UnregisterActorRemote(actor IActor) error RegisterServiceRemote(service *Service) error UnregisterServiceRemote(service *Service) error RegisterActorLocal(actor IActor) error UnregisterActorLocal(actor IActor) error RegisterServiceLocal(service *Service) error UnregisterServiceLocal(service *Service) error GetActorIdsByTypeAndServerId(serverId int32, typ string) []util.ID }
type IReqContext ¶
type IReqContext interface { context.Context IContext GetTransId() uint32 GetResp() interface{} SetResp(interface{}) SetCallback(cb AsyncCallBack) GetCallback() AsyncCallBack Cancel(err error) Finish() }
type IRouter ¶
type IRouter interface {
RouteMsg(msg *protocol.RouteMessage)
}
IRouter interface for router
type IRuntime ¶
type IRuntime interface { Init(updateTime int64, timeScale float32, server bool) GetContext(name string) interface{} SetContext(name string, value interface{}) GetEntity(util.ID) IEntity CurrentTick() int64 Start() Stop() RunningTime() int64 GetTimeScale() float32 SetTimeScale(scale float32) RegisterComponent(name string, c IComponent) RegisterSingleton(name string, c IComponent) GetComponentType(name string) reflect.Type IsSyncAble(compName string) bool CreateEntity() IEntity IsServer() bool //private MarkDirtyEntity(e IEntity) }
type ISession ¶
type ISession interface { GetId() util.ID GetConn() IConn // get corresponding IConn OnOpen(conn IConn) // called when IConn is opened OnClose(conn IConn) // called when IConn is closed OnRecv(conn IConn, data []byte) // called when IConn receives data, ATTENTION: data is a slice and must be consumed immediately }
ISession connection session interface
type ISessionManager ¶
type LongPacketCreator ¶
create long packet args: data:binary to create idx: long packet index return: 1.long packet
type LongPacketPicker ¶
pick long packet from binary args: data:binary return: 1.is long packet 2.long packet index, if index = 0 is the last long packet 3.if is long packet return real packet binary else return nil
type Server ¶
type Server interface { Start(addr string) error //start server Stop() //stop server Broadcast(sessionIds []util.ID, data []byte) // broadcast data to all connected sessions GetActiveConnNum() int // get current count of connections }
Server the interface for wsserver and tcpserver
type Service ¶
type Service struct { Id protocol.BINARY_TAG //service Id ProcessId util.ProcessId //server Id ActorId util.ID //actor Id Type ServiceType //rpc pub/sub stateless }
Service the registry for service details
type ServiceType ¶
type ServiceType int
const ( //rpc have a actorId<util.Id> to route message //SERVICE_RPC ServiceType = iota + 1 //subscribe have a actorId<util.Id> to pub message SERVICE_SUB ServiceType = iota + 1 //stateless do not have local state SERVICE_STATELESS SERVICE_SERVER )