func (dt *DbTask) init(r router.Router, sn string, role ServantRole) { dt.rot = r dt.role = role dt.servName = sn dt.random = rand.New(rand.NewSource(time.Now().UnixNano())) dt.dbRespChans = make(map[string](chan string)) dt.dbReqChan = make(chan *DbReq) dt.sysCmdChan = make(chan string) //output_intf or send chans dt.FaultRaiser = router.NewFaultRaiser(router.StrID("/Fault/DB/Exception"), r, "DbTask") //input_intf or recv chans r.AttachRecvChan(router.StrID("/Sys/Command"), dt.sysCmdChan) //use a bindChan to keep dbReqChan open when all clients detach & exit bc := make(chan *router.BindEvent, 1) r.AttachRecvChan(router.StrID("/DB/Request"), dt.dbReqChan, bc) }
func (at *ServiceTask) init(r router.Router, sn string, n string, role ServantRole) { at.rot = r at.name = n at.servantName = sn at.role = role at.random = rand.New(rand.NewSource(time.Now().UnixNano())) at.svcRespChan = make(chan string) at.dbReqChan = make(chan *DbReq) at.svcReqChan = make(chan string) at.sysCmdChan = make(chan string) at.svcCmdChan = make(chan string) at.dbRespChan = make(chan string) svcname := "/App/" + at.name //output_intf or send chans at.FaultRaiser = router.NewFaultRaiser(router.StrID("/Fault/AppService/Exception"), at.rot, at.name) at.rot.AttachSendChan(router.StrID("/DB/Request"), at.dbReqChan) at.rot.AttachSendChan(router.StrID(svcname+"/Response"), at.svcRespChan) //input_intf or recv chans at.rot.AttachRecvChan(router.StrID("/Sys/Command"), at.sysCmdChan) at.rot.AttachRecvChan(router.StrID("/Fault/Command"+svcname), at.svcCmdChan) at.rot.AttachRecvChan(router.StrID("/DB/Response"+svcname), at.dbRespChan) at.rot.AttachRecvChan(router.StrID(svcname+"/Request"), at.svcReqChan) }