agent.go 11 KB

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