agent.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. // Autogenerated by Thrift Compiler (0.9.3)
  2. // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  3. package agent
  4. import (
  5. "bytes"
  6. "fmt"
  7. "github.com/uber/jaeger-client-go/thrift"
  8. "github.com/uber/jaeger-client-go/thrift-gen/jaeger"
  9. "github.com/uber/jaeger-client-go/thrift-gen/zipkincore"
  10. )
  11. // (needed to ensure safety because of naive import list construction.)
  12. var _ = thrift.ZERO
  13. var _ = fmt.Printf
  14. var _ = bytes.Equal
  15. var _ = jaeger.GoUnusedProtection__
  16. var _ = zipkincore.GoUnusedProtection__
  17. type Agent interface {
  18. // Parameters:
  19. // - Spans
  20. EmitZipkinBatch(spans []*zipkincore.Span) (err error)
  21. // Parameters:
  22. // - Batch
  23. EmitBatch(batch *jaeger.Batch) (err error)
  24. }
  25. type AgentClient struct {
  26. Transport thrift.TTransport
  27. ProtocolFactory thrift.TProtocolFactory
  28. InputProtocol thrift.TProtocol
  29. OutputProtocol thrift.TProtocol
  30. SeqId int32
  31. }
  32. func NewAgentClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AgentClient {
  33. return &AgentClient{Transport: t,
  34. ProtocolFactory: f,
  35. InputProtocol: f.GetProtocol(t),
  36. OutputProtocol: f.GetProtocol(t),
  37. SeqId: 0,
  38. }
  39. }
  40. func NewAgentClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AgentClient {
  41. return &AgentClient{Transport: t,
  42. ProtocolFactory: nil,
  43. InputProtocol: iprot,
  44. OutputProtocol: oprot,
  45. SeqId: 0,
  46. }
  47. }
  48. // Parameters:
  49. // - Spans
  50. func (p *AgentClient) EmitZipkinBatch(spans []*zipkincore.Span) (err error) {
  51. if err = p.sendEmitZipkinBatch(spans); err != nil {
  52. return
  53. }
  54. return
  55. }
  56. func (p *AgentClient) sendEmitZipkinBatch(spans []*zipkincore.Span) (err error) {
  57. oprot := p.OutputProtocol
  58. if oprot == nil {
  59. oprot = p.ProtocolFactory.GetProtocol(p.Transport)
  60. p.OutputProtocol = oprot
  61. }
  62. p.SeqId++
  63. if err = oprot.WriteMessageBegin("emitZipkinBatch", thrift.ONEWAY, p.SeqId); err != nil {
  64. return
  65. }
  66. args := AgentEmitZipkinBatchArgs{
  67. Spans: spans,
  68. }
  69. if err = args.Write(oprot); err != nil {
  70. return
  71. }
  72. if err = oprot.WriteMessageEnd(); err != nil {
  73. return
  74. }
  75. return oprot.Flush()
  76. }
  77. // Parameters:
  78. // - Batch
  79. func (p *AgentClient) EmitBatch(batch *jaeger.Batch) (err error) {
  80. if err = p.sendEmitBatch(batch); err != nil {
  81. return
  82. }
  83. return
  84. }
  85. func (p *AgentClient) sendEmitBatch(batch *jaeger.Batch) (err error) {
  86. oprot := p.OutputProtocol
  87. if oprot == nil {
  88. oprot = p.ProtocolFactory.GetProtocol(p.Transport)
  89. p.OutputProtocol = oprot
  90. }
  91. p.SeqId++
  92. if err = oprot.WriteMessageBegin("emitBatch", thrift.ONEWAY, p.SeqId); err != nil {
  93. return
  94. }
  95. args := AgentEmitBatchArgs{
  96. Batch: batch,
  97. }
  98. if err = args.Write(oprot); err != nil {
  99. return
  100. }
  101. if err = oprot.WriteMessageEnd(); err != nil {
  102. return
  103. }
  104. return oprot.Flush()
  105. }
  106. type AgentProcessor struct {
  107. processorMap map[string]thrift.TProcessorFunction
  108. handler Agent
  109. }
  110. func (p *AgentProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
  111. p.processorMap[key] = processor
  112. }
  113. func (p *AgentProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
  114. processor, ok = p.processorMap[key]
  115. return processor, ok
  116. }
  117. func (p *AgentProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
  118. return p.processorMap
  119. }
  120. func NewAgentProcessor(handler Agent) *AgentProcessor {
  121. self0 := &AgentProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
  122. self0.processorMap["emitZipkinBatch"] = &agentProcessorEmitZipkinBatch{handler: handler}
  123. self0.processorMap["emitBatch"] = &agentProcessorEmitBatch{handler: handler}
  124. return self0
  125. }
  126. func (p *AgentProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  127. name, _, seqId, err := iprot.ReadMessageBegin()
  128. if err != nil {
  129. return false, err
  130. }
  131. if processor, ok := p.GetProcessorFunction(name); ok {
  132. return processor.Process(seqId, iprot, oprot)
  133. }
  134. iprot.Skip(thrift.STRUCT)
  135. iprot.ReadMessageEnd()
  136. x1 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
  137. oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
  138. x1.Write(oprot)
  139. oprot.WriteMessageEnd()
  140. oprot.Flush()
  141. return false, x1
  142. }
  143. type agentProcessorEmitZipkinBatch struct {
  144. handler Agent
  145. }
  146. func (p *agentProcessorEmitZipkinBatch) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  147. args := AgentEmitZipkinBatchArgs{}
  148. if err = args.Read(iprot); err != nil {
  149. iprot.ReadMessageEnd()
  150. return false, err
  151. }
  152. iprot.ReadMessageEnd()
  153. var err2 error
  154. if err2 = p.handler.EmitZipkinBatch(args.Spans); err2 != nil {
  155. return true, err2
  156. }
  157. return true, nil
  158. }
  159. type agentProcessorEmitBatch struct {
  160. handler Agent
  161. }
  162. func (p *agentProcessorEmitBatch) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  163. args := AgentEmitBatchArgs{}
  164. if err = args.Read(iprot); err != nil {
  165. iprot.ReadMessageEnd()
  166. return false, err
  167. }
  168. iprot.ReadMessageEnd()
  169. var err2 error
  170. if err2 = p.handler.EmitBatch(args.Batch); err2 != nil {
  171. return true, err2
  172. }
  173. return true, nil
  174. }
  175. // HELPER FUNCTIONS AND STRUCTURES
  176. // Attributes:
  177. // - Spans
  178. type AgentEmitZipkinBatchArgs struct {
  179. Spans []*zipkincore.Span `thrift:"spans,1" json:"spans"`
  180. }
  181. func NewAgentEmitZipkinBatchArgs() *AgentEmitZipkinBatchArgs {
  182. return &AgentEmitZipkinBatchArgs{}
  183. }
  184. func (p *AgentEmitZipkinBatchArgs) GetSpans() []*zipkincore.Span {
  185. return p.Spans
  186. }
  187. func (p *AgentEmitZipkinBatchArgs) Read(iprot thrift.TProtocol) error {
  188. if _, err := iprot.ReadStructBegin(); err != nil {
  189. return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
  190. }
  191. for {
  192. _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
  193. if err != nil {
  194. return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
  195. }
  196. if fieldTypeId == thrift.STOP {
  197. break
  198. }
  199. switch fieldId {
  200. case 1:
  201. if err := p.readField1(iprot); err != nil {
  202. return err
  203. }
  204. default:
  205. if err := iprot.Skip(fieldTypeId); err != nil {
  206. return err
  207. }
  208. }
  209. if err := iprot.ReadFieldEnd(); err != nil {
  210. return err
  211. }
  212. }
  213. if err := iprot.ReadStructEnd(); err != nil {
  214. return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
  215. }
  216. return nil
  217. }
  218. func (p *AgentEmitZipkinBatchArgs) readField1(iprot thrift.TProtocol) error {
  219. _, size, err := iprot.ReadListBegin()
  220. if err != nil {
  221. return thrift.PrependError("error reading list begin: ", err)
  222. }
  223. tSlice := make([]*zipkincore.Span, 0, size)
  224. p.Spans = tSlice
  225. for i := 0; i < size; i++ {
  226. _elem2 := &zipkincore.Span{}
  227. if err := _elem2.Read(iprot); err != nil {
  228. return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem2), err)
  229. }
  230. p.Spans = append(p.Spans, _elem2)
  231. }
  232. if err := iprot.ReadListEnd(); err != nil {
  233. return thrift.PrependError("error reading list end: ", err)
  234. }
  235. return nil
  236. }
  237. func (p *AgentEmitZipkinBatchArgs) Write(oprot thrift.TProtocol) error {
  238. if err := oprot.WriteStructBegin("emitZipkinBatch_args"); err != nil {
  239. return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
  240. }
  241. if err := p.writeField1(oprot); err != nil {
  242. return err
  243. }
  244. if err := oprot.WriteFieldStop(); err != nil {
  245. return thrift.PrependError("write field stop error: ", err)
  246. }
  247. if err := oprot.WriteStructEnd(); err != nil {
  248. return thrift.PrependError("write struct stop error: ", err)
  249. }
  250. return nil
  251. }
  252. func (p *AgentEmitZipkinBatchArgs) writeField1(oprot thrift.TProtocol) (err error) {
  253. if err := oprot.WriteFieldBegin("spans", thrift.LIST, 1); err != nil {
  254. return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:spans: ", p), err)
  255. }
  256. if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Spans)); err != nil {
  257. return thrift.PrependError("error writing list begin: ", err)
  258. }
  259. for _, v := range p.Spans {
  260. if err := v.Write(oprot); err != nil {
  261. return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
  262. }
  263. }
  264. if err := oprot.WriteListEnd(); err != nil {
  265. return thrift.PrependError("error writing list end: ", err)
  266. }
  267. if err := oprot.WriteFieldEnd(); err != nil {
  268. return thrift.PrependError(fmt.Sprintf("%T write field end error 1:spans: ", p), err)
  269. }
  270. return err
  271. }
  272. func (p *AgentEmitZipkinBatchArgs) String() string {
  273. if p == nil {
  274. return "<nil>"
  275. }
  276. return fmt.Sprintf("AgentEmitZipkinBatchArgs(%+v)", *p)
  277. }
  278. // Attributes:
  279. // - Batch
  280. type AgentEmitBatchArgs struct {
  281. Batch *jaeger.Batch `thrift:"batch,1" json:"batch"`
  282. }
  283. func NewAgentEmitBatchArgs() *AgentEmitBatchArgs {
  284. return &AgentEmitBatchArgs{}
  285. }
  286. var AgentEmitBatchArgs_Batch_DEFAULT *jaeger.Batch
  287. func (p *AgentEmitBatchArgs) GetBatch() *jaeger.Batch {
  288. if !p.IsSetBatch() {
  289. return AgentEmitBatchArgs_Batch_DEFAULT
  290. }
  291. return p.Batch
  292. }
  293. func (p *AgentEmitBatchArgs) IsSetBatch() bool {
  294. return p.Batch != nil
  295. }
  296. func (p *AgentEmitBatchArgs) Read(iprot thrift.TProtocol) error {
  297. if _, err := iprot.ReadStructBegin(); err != nil {
  298. return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
  299. }
  300. for {
  301. _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
  302. if err != nil {
  303. return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
  304. }
  305. if fieldTypeId == thrift.STOP {
  306. break
  307. }
  308. switch fieldId {
  309. case 1:
  310. if err := p.readField1(iprot); err != nil {
  311. return err
  312. }
  313. default:
  314. if err := iprot.Skip(fieldTypeId); err != nil {
  315. return err
  316. }
  317. }
  318. if err := iprot.ReadFieldEnd(); err != nil {
  319. return err
  320. }
  321. }
  322. if err := iprot.ReadStructEnd(); err != nil {
  323. return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
  324. }
  325. return nil
  326. }
  327. func (p *AgentEmitBatchArgs) readField1(iprot thrift.TProtocol) error {
  328. p.Batch = &jaeger.Batch{}
  329. if err := p.Batch.Read(iprot); err != nil {
  330. return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Batch), err)
  331. }
  332. return nil
  333. }
  334. func (p *AgentEmitBatchArgs) Write(oprot thrift.TProtocol) error {
  335. if err := oprot.WriteStructBegin("emitBatch_args"); err != nil {
  336. return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
  337. }
  338. if err := p.writeField1(oprot); err != nil {
  339. return err
  340. }
  341. if err := oprot.WriteFieldStop(); err != nil {
  342. return thrift.PrependError("write field stop error: ", err)
  343. }
  344. if err := oprot.WriteStructEnd(); err != nil {
  345. return thrift.PrependError("write struct stop error: ", err)
  346. }
  347. return nil
  348. }
  349. func (p *AgentEmitBatchArgs) writeField1(oprot thrift.TProtocol) (err error) {
  350. if err := oprot.WriteFieldBegin("batch", thrift.STRUCT, 1); err != nil {
  351. return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:batch: ", p), err)
  352. }
  353. if err := p.Batch.Write(oprot); err != nil {
  354. return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Batch), err)
  355. }
  356. if err := oprot.WriteFieldEnd(); err != nil {
  357. return thrift.PrependError(fmt.Sprintf("%T write field end error 1:batch: ", p), err)
  358. }
  359. return err
  360. }
  361. func (p *AgentEmitBatchArgs) String() string {
  362. if p == nil {
  363. return "<nil>"
  364. }
  365. return fmt.Sprintf("AgentEmitBatchArgs(%+v)", *p)
  366. }