コード例 #1
0
ファイル: dbtask.go プロジェクト: niltonkummer/go-router
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.Seconds()))
	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)
}
コード例 #2
0
ファイル: svctask.go プロジェクト: niltonkummer/go-router
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.Seconds()))
	at.svcRespChan = make(chan string)
	at.dbReqChan = make(chan *DbReq)
	at.svcReqChan = make(chan string, router.DefDataChanBufSize)
	at.sysCmdChan = make(chan string)
	at.svcCmdChan = make(chan string)
	at.dbRespChan = make(chan string)
	at.bindChan = make(chan *router.BindEvent, 1)
	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(svcname+"/Command"), at.svcCmdChan)
	at.rot.AttachRecvChan(router.StrID(svcname+"/DB/Response"), at.dbRespChan)
	at.rot.AttachRecvChan(router.StrID(svcname+"/Request"), at.svcReqChan, at.bindChan)
}