func (tm *TimerMgr) Start() { logger.Trace("Timer Start") defer logger.Trace("Timer Start [ok]") tm.Object = basic.NewObject(core.ObjId_TimerId, "timer", Config.Options, tm) tm.UserData = tm core.LaunchChild(TimerModule.Object) }
func (this *ModuleMgr) init() { logger.Trace("Start Initialize Modules") defer logger.Trace("Start Initialize Modules [ok]") for e := this.modules.Front(); e != nil; e = e.Next() { if me, ok := e.Value.(*ModuleEntity); ok && !me.quited { logger.Trace(me.module.ModuleName(), " Init...") me.module.Init() logger.Trace(me.module.ModuleName(), " Init [ok]") } } this.state = ModuleStateRun }
func (s *TcpSession) sendRoutine() { defer func() { if err := recover(); err != nil { logger.Trace(s.Id, " ->close: Session.procSend err: ", err) } s.sc.encoder.FinishEncode(&s.Session) s.shutWrite() s.shutRead() s.Close() }() s.waitor.Add(1) defer s.waitor.Done() var ( err error data []byte ) for !s.quit || len(s.sendBuffer) != 0 { select { case msg, ok := <-s.sendBuffer: if !ok { panic("[comm expt]sendBuffer chan closed") } if msg == nil { panic("[comm expt]normal close send") } if s.sc.IsInnerLink { var timeZero time.Time s.conn.SetWriteDeadline(timeZero) } else { if s.sc.WriteTimeout != 0 { s.conn.SetWriteDeadline(time.Now().Add(s.sc.WriteTimeout)) } } data, err = s.sc.encoder.Encode(&s.Session, msg, s.conn) if err != nil { logger.Trace("s.sc.encoder.Encode err", err) if s.sc.IsInnerLink == false { panic(err) } } s.FirePacketSent(data) s.lastSndTime = time.Now() } } }
func (e *Executor) Start() { logger.Trace("Executor Start") defer logger.Trace("Executor Start [ok]") e.Object = basic.NewObject(core.ObjId_ExecutorId, "executor", Config.Options, nil) e.c.NumberOfReplicas = WorkerVirtualNum e.UserData = e e.AddWorker(Config.Worker.WorkerCnt) core.LaunchChild(TaskExecutor.Object) }
func (tcs *TxCommSkeleton) SendTransStart(parent, me *transact.TransNodeParam, ud interface{}) bool { logger.Trace("TxCommSkeleton.SendTransStart") p := action.ContructTxStartPacket(parent, me, ud) if p == nil { return false } s := ServerSessionMgrSington.GetSession(me.AreaID, int(me.Ot), me.Oid) if s == nil { logger.Trace("TxCommSkeleton.SendTransStart s=nil") return false } s.Send(p) return true }
func (tcs *TxCommSkeleton) SendTransResult(parent, me *transact.TransNodeParam, tr *transact.TransResult) bool { logger.Trace("TxCommSkeleton.SendTransResult") p := action.ContructTxResultPacket(parent, me, tr) if p == nil { return false } s := ServerSessionMgrSington.GetSession(parent.AreaID, int(parent.Ot), parent.Oid) if s == nil { logger.Trace("TxCommSkeleton.SendTransResult s=nil") return false } s.Send(p) return true }
func (tcs *TxCommSkeleton) SendCmdToTransNode(tnp *transact.TransNodeParam, c transact.TransCmd) bool { logger.Trace("TxCommSkeleton.SendCmdToTransNode") p := action.ConstructTxCmdPacket(tnp, c) if p == nil { return false } s := ServerSessionMgrSington.GetSession(tnp.AreaID, int(tnp.Ot), tnp.Oid) if s == nil { logger.Trace("TxCommSkeleton.SendCmdToTransNode s=nil") return false } s.Send(p) return true }
func (this *serviceMgr) OnRegiste(s *netlib.Session) { if this == nil || s == nil { return } if s.GetAttribute(SessionAttributeServiceFlag) == nil { return } attr := s.GetAttribute(SessionAttributeServerInfo) if attr != nil { if srvInfo, ok := attr.(*protocol.SSSrvRegiste); ok && srvInfo != nil { services := GetCareServicesBySession(srvInfo.GetType()) for _, v1 := range services { if v2, has := this.servicesPool[v1]; has { for _, v3 := range v2 { func(si *protocol.ServiceInfo, sInfo *protocol.SSSrvRegiste) { pack := &protocol.SSServiceInfo{} proto.SetDefaults(pack) pack.Service = si logger.Trace("serviceMgr.OnRegiste Server Type=", sInfo.GetType(), " Id=", sInfo.GetId(), " Name=", sInfo.GetName(), " careful => Service=", si) s.Send(pack) }(v3, srvInfo) } } } } } }
func init() { netlib.RegisterFactory(int(protocol.MmoPacketID_PACKET_SC_GATEINFO), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.SCGateInfo{} })) netlib.RegisterHandler(int(protocol.MmoPacketID_PACKET_SC_GATEINFO), netlib.HandlerWrapper(func(s *netlib.Session, pack interface{}) error { logger.Trace("receive gateinfo==", pack) if sr, ok := pack.(*protocol.SCGateInfo); ok { sc := &netlib.SessionConfig{ Id: int(sr.GetSrvId()), Type: int(sr.GetSrvType()), Ip: sr.GetIp(), Port: int(sr.GetPort()), AuthKey: sr.GetAuthKey(), WriteTimeout: 30, ReadTimeout: 30, IdleTimeout: 30, MaxDone: 20, MaxPend: 20, MaxPacket: 1024, RcvBuff: 1024, SndBuff: 1024, IsClient: true, NoDelay: true, FilterChain: []string{"session-filter-trace", "session-filter-auth"}, } sc.Init() err := netlib.Connect(core.CoreObject(), sc) if err != nil { logger.Warn("connect server failed err:", err) } } return nil })) }
func RegisteHandler(tt TransType, th TransHandler) { if _, exist := transactionHandlerPool[tt]; exist { panic(fmt.Sprintf("TransHandlerFactory repeate registe handler, type=%v", tt)) return } logger.Trace("transact.RegisteHandler:", tt) transactionHandlerPool[tt] = th }
func (this *traceTransHandler) OnExcute(tNode *transact.TransNode, ud interface{}) transact.TransExeResult { logger.Trace("traceTransHandler.OnExcute ") userData := &protocol.StructA{} err := netlib.UnmarshalPacketNoPackId(ud.([]byte), userData) if err == nil { logger.Tracef("==========%#v", userData) } return transact.TransExeResult_Success }
func (this *TxCtrlCmdHandler) Process(session *netlib.Session, data interface{}) error { logger.Trace("TxCtrlCmdHandler.Process") if txcmd, ok := data.(*protocol.TransactCtrlCmd); ok { if !transact.ProcessTransCmd(transact.TransNodeID(txcmd.GetTId()), transact.TransCmd(txcmd.GetCmd())) { return errors.New("TxCtrlCmdHandler error, tid=" + strconv.FormatInt(txcmd.GetTId(), 16) + " cmd=" + strconv.Itoa(int(txcmd.GetCmd()))) } } return nil }
func (this *TxResultHandler) Process(session *netlib.Session, data interface{}) error { logger.Trace("TxResultHandler.Process") if tr, ok := data.(*protocol.TransactResult); ok { if !transact.ProcessTransResult(transact.TransNodeID(tr.GetMyTId()), transact.TransNodeID(tr.GetChildTId()), int(tr.GetRetCode()), tr.GetCustomData()) { return errors.New("TxResultHandler error, tid=" + strconv.FormatInt(tr.GetMyTId(), 16)) } } return nil }
func (s *TcpSession) shutRead() { if s.shutRecv { return } logger.Trace(s.Id, " shutRead") s.shutRecv = true if tcpconn, ok := s.conn.(*net.TCPConn); ok { tcpconn.CloseRead() } }
func (this *PacketTransitHandler) Process(s *netlib.Session, data interface{}) error { logger.Trace("PacketTransitHandler.Process") if pr, ok := data.(*protocol.SSPacketTransit); ok { targetS := srvlib.ServerSessionMgrSington.GetSession(int(pr.GetSArea()), int(pr.GetSType()), int(pr.GetSId())) if targetS != nil { targetS.Send(pr.GetData()) } } return nil }
func (s *WsSession) shutRead() { if s.shutRecv { return } logger.Trace(s.Id, " shutRead") s.shutRecv = true if s.conn != nil { s.conn.Close() s.conn = nil } }
func (this *ModuleMgr) Start() *utils.Waitor { logger.Trace("Startup PreloadModules") for e := this.preloadModule.Front(); e != nil; e = e.Next() { if me, ok := e.Value.(*PreloadModuleEntity); ok { me.module.Start() } } logger.Trace("Startup PreloadModules [ok]") this.Object = basic.NewObject(core.ObjId_CoreId, "core", Config.Options, this) this.UserData = this core.LaunchChild(this.Object) this.state = ModuleStateInit //给模块预留调度的空间,防止主线程直接跑过去 select { case <-time.After(time.Second): } return this.Object.Waitor }
func (mssrl *MyServerSessionRegisteListener) OnRegiste(*netlib.Session) { logger.Trace("MyServerSessionRegisteListener.OnRegiste") tnp := &transact.TransNodeParam{ Tt: protocol.TxTrace, Ot: transact.TransOwnerType(2), Oid: 202, AreaID: 1, } tNode := transact.DTCModule.StartTrans(tnp, nil, transact.DefaultTransactTimeout) if tNode != nil { tNode.Go(core.CoreObject()) } }
func (this *traceTransHandler) OnExcute(tNode *transact.TransNode, ud interface{}) transact.TransExeResult { logger.Trace("traceTransHandler.OnExcute ") tnp := &transact.TransNodeParam{ Tt: protocol.TxTrace, Ot: transact.TransOwnerType(2), Oid: 201, AreaID: 1, Tct: transact.TransactCommitPolicy_TwoPhase, } p := new(int) *p = -2 userData := protocol.StructA{X: 10, Y: -1, Z: 65535, P: p, Desc: "welcome!"} tNode.StartChildTrans(tnp, userData, transact.DefaultTransactTimeout) return transact.TransExeResult_Success }
func (s *TcpSession) shutWrite() { if s.shutSend { return } logger.Trace(s.Id, " shutWrite") rest := len(s.sendBuffer) for rest > 0 { <-s.sendBuffer rest-- } s.shutSend = true if tcpconn, ok := s.conn.(*net.TCPConn); ok { tcpconn.CloseWrite() } }
func (s *WsSession) shutWrite() { if s.shutSend { return } logger.Trace(s.Id, " shutWrite") rest := len(s.sendBuffer) for rest > 0 { <-s.sendBuffer rest-- } s.shutSend = true if s.conn != nil { s.conn.Close() s.conn = nil } }
func (this *PacketRedirectHandler) Process(s *netlib.Session, data interface{}) error { logger.Trace("PacketRedirectHandler.Process") if pr, ok := data.(*protocol.SSPacketRedirect); ok { packid, pack, err := netlib.UnmarshalPacket(pr.GetData()) if err != nil { return err } h := srvlib.GetHandler(packid) if h != nil { return h.Process(s, pack, pr.GetClientSid(), pr.GetSrvRoutes()) } else { nh := netlib.GetHandler(packid) if nh != nil { return nh.Process(s, pack) } } } return nil }
func (this *ModuleMgr) checkShutdown() bool { select { case param := <-this.waitShutAct: logger.Trace(param, " shutdowned") if name, ok := param.(string); ok { me := this.getModuleEntityByName(name) if me != nil && !me.quited { me.quited = true this.waitShutCnt-- } } default: } if this.waitShutCnt == 0 { this.state = ModuleStateFini return true } this.update() return false }
func init() { netlib.RegisteSessionHandlerCreator(SessionHandlerClientBalanceName, func() netlib.SessionHandler { return SessionHandlerClientBalanceMgr }) netlib.RegisterFactory(int(protocol.MmoPacketID_PACKET_GB_CUR_LOAD), netlib.PacketFactoryWrapper(func() interface{} { return &protocol.ServerLoad{} })) netlib.RegisterHandler(int(protocol.MmoPacketID_PACKET_GB_CUR_LOAD), netlib.HandlerWrapper(func(s *netlib.Session, pack interface{}) error { logger.Trace("receive gate load info==", pack) if sr, ok := pack.(*protocol.ServerLoad); ok { srvid := sr.GetSrvId() if v, has := SessionHandlerClientBalanceMgr.gates[srvid]; has { v.load = int(sr.GetCurLoad()) } } return nil })) }
func (this *TxStartHandler) Process(session *netlib.Session, data interface{}) error { logger.Trace("TxStartHandler.Process") if ts, ok := data.(*protocol.TransactStart); ok { netptnp := ts.GetParenTNP() if netptnp == nil { return nil } netmtnp := ts.GetMyTNP() if netmtnp == nil { return nil } ptnp := &transact.TransNodeParam{ TId: transact.TransNodeID(netptnp.GetTransNodeID()), Tt: transact.TransType(netptnp.GetTransType()), Ot: transact.TransOwnerType(netptnp.GetOwnerType()), Tct: transact.TransactCommitPolicy(netptnp.GetTransCommitType()), Oid: int(netptnp.GetOwnerID()), SkeletonID: int(netptnp.GetSkeletonID()), LevelNo: int(netptnp.GetLevelNo()), AreaID: int(netptnp.GetAreaID()), TimeOut: time.Duration(netptnp.GetTimeOut()), } mtnp := &transact.TransNodeParam{ TId: transact.TransNodeID(netmtnp.GetTransNodeID()), Tt: transact.TransType(netmtnp.GetTransType()), Ot: transact.TransOwnerType(netmtnp.GetOwnerType()), Tct: transact.TransactCommitPolicy(netmtnp.GetTransCommitType()), Oid: int(netmtnp.GetOwnerID()), SkeletonID: int(netmtnp.GetSkeletonID()), LevelNo: int(netmtnp.GetLevelNo()), AreaID: int(netmtnp.GetAreaID()), TimeOut: time.Duration(netmtnp.GetTimeOut()), } if !transact.ProcessTransStart(ptnp, mtnp, ts.GetCustomData(), mtnp.TimeOut) { return errors.New("TxStartHandler error, tid=" + strconv.FormatInt(netmtnp.GetTransNodeID(), 16)) } } return nil }
func (sfcb *SessionHandlerClientBalance) OnSessionOpened(s *netlib.Session) { logger.Trace("SessionHandlerClientBalance.OnSessionOpened") services := srvlib.ServiceMgr.GetServices(srvlib.ClientServiceType) if services != nil { /*清理掉线的gate*/ for k, _ := range sfcb.gates { if _, has := services[k]; !has { delete(sfcb.gates, k) } } /*补充新上线的gate*/ for k, v := range services { if _, has := sfcb.gates[k]; !has { sfcb.gates[k] = &gateService{ServiceInfo: v, active: true} } } } /*查找最小负载的gate*/ var mls *libproto.ServiceInfo var min = 100000 for _, v := range sfcb.gates { if v.active && v.load < min { mls = v.ServiceInfo } } pack := &protocol.SCGateInfo{} if mls != nil { pack.SrvType = proto.Int32(mls.GetSrvType()) pack.SrvId = proto.Int32(mls.GetSrvId()) pack.AuthKey = proto.String(mls.GetAuthKey()) pack.Ip = proto.String(mls.GetIp()) pack.Port = proto.Int32(mls.GetPort()) } proto.SetDefaults(pack) s.Send(pack) time.AfterFunc(time.Second*5, func() { s.Close() }) }
func (mssrl *MyServerSessionRegisteListener) OnUnregiste(*netlib.Session) { logger.Trace("MyServerSessionRegisteListener.OnUnregiste") }
func (this *traceTransHandler) OnChildTransRep(tNode *transact.TransNode, hChild transact.TransNodeID, retCode int, ud interface{}) transact.TransExeResult { logger.Trace("traceTransHandler.OnChildTransRep ") return transact.TransExeResult_Success }
func (this *traceTransHandler) OnRollBack(tNode *transact.TransNode) transact.TransExeResult { logger.Trace("traceTransHandler.OnRollBack ") return transact.TransExeResult_Success }
func (this *traceTransHandler) OnCommit(tNode *transact.TransNode) transact.TransExeResult { logger.Trace("traceTransHandler.OnCommit ") return transact.TransExeResult_Success }