本文整理匯總了Golang中github.com/Wikia/influxdb/protocol.Request.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Id方法的具體用法?Golang Request.Id怎麽用?Golang Request.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Wikia/influxdb/protocol.Request
的用法示例。
在下文中一共展示了Request.Id方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MakeRequest
// Makes a request to the server. If the responseStream chan is not nil it will expect a response from the server
// with a matching request.Id. The REQUEST_RETRY_ATTEMPTS constant of 3 and the RECONNECT_RETRY_WAIT of 100ms means
// that an attempt to make a request to a downed server will take 300ms to time out.
func (self *ProtobufClient) MakeRequest(request *protocol.Request, r cluster.ResponseChannel) error {
if request.Id == nil {
id := atomic.AddUint32(&self.lastRequestId, uint32(1))
request.Id = &id
}
if r != nil {
self.requestBufferLock.Lock()
// this should actually never happen. The sweeper should clear out dead requests
// before the uint32 ids roll over.
if oldReq, alreadyHasRequestById := self.requestBuffer[*request.Id]; alreadyHasRequestById {
message := "already has a request with this id, must have timed out"
log.Error(message)
oldReq.r.Yield(&protocol.Response{
Type: protocol.Response_ERROR.Enum(),
ErrorMessage: &message,
})
}
self.requestBuffer[*request.Id] = &runningRequest{timeMade: time.Now(), r: r, request: request}
self.requestBufferLock.Unlock()
}
data, err := request.Encode()
if err != nil {
return err
}
conn := self.getConnection()
if conn == nil {
conn = self.reconnect()
if conn == nil {
return fmt.Errorf("Failed to connect to server %s", self.hostAndPort)
}
}
if self.writeTimeout > 0 {
conn.SetWriteDeadline(time.Now().Add(self.writeTimeout))
}
buff := bytes.NewBuffer(make([]byte, 0, len(data)+8))
binary.Write(buff, binary.LittleEndian, uint32(len(data)))
buff.Write(data)
_, err = conn.Write(buff.Bytes())
if err == nil {
return nil
}
// if we got here it errored out, clear out the request
self.requestBufferLock.Lock()
delete(self.requestBuffer, *request.Id)
self.requestBufferLock.Unlock()
self.reconnect()
return err
}
示例2: forwardRequest
func (self *ShardData) forwardRequest(request *p.Request) ([]<-chan *p.Response, []uint32, error) {
ids := []uint32{}
responses := []<-chan *p.Response{}
for _, server := range self.clusterServers {
responseChan := make(chan *p.Response, 1)
// do this so that a new id will get assigned
request.Id = nil
log.Debug("Forwarding request %s to %d", request.GetDescription(), server.Id)
server.MakeRequest(request, responseChan)
responses = append(responses, responseChan)
ids = append(ids, server.Id)
}
return responses, ids, nil
}