本文整理汇总了Golang中github.com/SoftwareDefinedBuildings/btrdb.Quasar.QueryValuesStream方法的典型用法代码示例。如果您正苦于以下问题:Golang Quasar.QueryValuesStream方法的具体用法?Golang Quasar.QueryValuesStream怎么用?Golang Quasar.QueryValuesStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/SoftwareDefinedBuildings/btrdb.Quasar
的用法示例。
在下文中一共展示了Quasar.QueryValuesStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dispatchCommands
func (c *CPInterface) dispatchCommands(q *btrdb.Quasar, conn net.Conn) {
//This governs the stream
rmtx := sync.Mutex{}
wmtx := sync.Mutex{}
log.Info("cpnp connection")
for !c.isShuttingDown {
rmtx.Lock()
seg, err := capn.ReadFromStream(conn, nil)
if err != nil {
log.Warning("ERR (%v) :: %v", conn.RemoteAddr(), err)
conn.Close()
break
}
rmtx.Unlock()
go func() {
seg := seg
req := ReadRootRequest(seg)
mkresp := func() (Response, *capn.Segment) {
rvseg := capn.NewBuffer(nil)
resp := NewRootResponse(rvseg)
resp.SetEchoTag(req.EchoTag())
return resp, rvseg
}
sendresp := func(seg *capn.Segment) {
wmtx.Lock()
seg.WriteTo(conn)
wmtx.Unlock()
}
switch req.Which() {
case REQUEST_QUERYSTANDARDVALUES:
//log.Info("QSV\n")
st := req.QueryStandardValues().StartTime()
et := req.QueryStandardValues().EndTime()
uuid := uuid.UUID(req.QueryStandardValues().Uuid())
ver := req.QueryStandardValues().Version()
//log.Info("[REQ=QsV] st=%v, et=%v, uuid=%v, gen=%v", st, et, uuid, ver)
if ver == 0 {
ver = btrdb.LatestGeneration
}
recordc, errorc, gen := q.QueryValuesStream(uuid, st, et, ver)
if recordc == nil {
log.Warning("RESPONDING ERR: %v", err)
resp, rvseg := mkresp()
resp.SetStatusCode(STATUSCODE_INTERNALERROR)
resp.SetFinal(true)
sendresp(rvseg)
return
} else {
bufarr := make([]qtree.Record, 0, 4096)
for {
resp, rvseg := mkresp()
fail := false
fin := false
for {
select {
case _, ok := <-errorc:
if ok {
fin = true
fail = true
goto donestandard
}
case r, ok := <-recordc:
if !ok {
fin = true
goto donestandard
}
bufarr = append(bufarr, r)
if len(bufarr) == cap(bufarr) {
goto donestandard
}
}
}
donestandard:
if fail {
resp.SetStatusCode(STATUSCODE_INTERNALERROR)
resp.SetFinal(true)
//consume channels
go func() {
for _ = range recordc {
}
}()
go func() {
for _ = range errorc {
}
}()
sendresp(rvseg)
return
}
records := NewRecords(rvseg)
rl := NewRecordList(rvseg, len(bufarr))
rla := rl.ToArray()
for i, v := range bufarr {
rla[i].SetTime(v.Time)
rla[i].SetValue(v.Val)
}
records.SetVersion(gen)
records.SetValues(rl)
resp.SetRecords(records)
resp.SetStatusCode(STATUSCODE_OK)
if fin {
//.........这里部分代码省略.........