agent.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 jaeger
  4. import (
  5. "bytes"
  6. "fmt"
  7. "github.com/uber/jaeger-client-go/thrift"
  8. )
  9. // (needed to ensure safety because of naive import list construction.)
  10. var _ = thrift.ZERO
  11. var _ = fmt.Printf
  12. var _ = bytes.Equal
  13. type Agent interface {
  14. // Parameters:
  15. // - Batch
  16. EmitBatch(batch *Batch) (err error)
  17. }
  18. type AgentClient struct {
  19. Transport thrift.TTransport
  20. ProtocolFactory thrift.TProtocolFactory
  21. InputProtocol thrift.TProtocol
  22. OutputProtocol thrift.TProtocol
  23. SeqId int32
  24. }
  25. func NewAgentClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AgentClient {
  26. return &AgentClient{Transport: t,
  27. ProtocolFactory: f,
  28. InputProtocol: f.GetProtocol(t),
  29. OutputProtocol: f.GetProtocol(t),
  30. SeqId: 0,
  31. }
  32. }
  33. func NewAgentClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AgentClient {
  34. return &AgentClient{Transport: t,
  35. ProtocolFactory: nil,
  36. InputProtocol: iprot,
  37. OutputProtocol: oprot,
  38. SeqId: 0,
  39. }
  40. }
  41. // Parameters:
  42. // - Batch
  43. func (p *AgentClient) EmitBatch(batch *Batch) (err error) {
  44. if err = p.sendEmitBatch(batch); err != nil {
  45. return
  46. }
  47. return
  48. }
  49. func (p *AgentClient) sendEmitBatch(batch *Batch) (err error) {
  50. oprot := p.OutputProtocol
  51. if oprot == nil {
  52. oprot = p.ProtocolFactory.GetProtocol(p.Transport)
  53. p.OutputProtocol = oprot
  54. }
  55. p.SeqId++
  56. if err = oprot.WriteMessageBegin("emitBatch", thrift.ONEWAY, p.SeqId); err != nil {
  57. return
  58. }
  59. args := AgentEmitBatchArgs{
  60. Batch: batch,
  61. }
  62. if err = args.Write(oprot); err != nil {
  63. return
  64. }
  65. if err = oprot.WriteMessageEnd(); err != nil {
  66. return
  67. }
  68. return oprot.Flush()
  69. }
  70. type AgentProcessor struct {
  71. processorMap map[string]thrift.TProcessorFunction
  72. handler Agent
  73. }
  74. func (p *AgentProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
  75. p.processorMap[key] = processor
  76. }
  77. func (p *AgentProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
  78. processor, ok = p.processorMap[key]
  79. return processor, ok
  80. }
  81. func (p *AgentProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
  82. return p.processorMap
  83. }
  84. func NewAgentProcessor(handler Agent) *AgentProcessor {
  85. self6 := &AgentProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
  86. self6.processorMap["emitBatch"] = &agentProcessorEmitBatch{handler: handler}
  87. return self6
  88. }
  89. func (p *AgentProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  90. name, _, seqId, err := iprot.ReadMessageBegin()
  91. if err != nil {
  92. return false, err
  93. }
  94. if processor, ok := p.GetProcessorFunction(name); ok {
  95. return processor.Process(seqId, iprot, oprot)
  96. }
  97. iprot.Skip(thrift.STRUCT)
  98. iprot.ReadMessageEnd()
  99. x7 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
  100. oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
  101. x7.Write(oprot)
  102. oprot.WriteMessageEnd()
  103. oprot.Flush()
  104. return false, x7
  105. }
  106. type agentProcessorEmitBatch struct {
  107. handler Agent
  108. }
  109. func (p *agentProcessorEmitBatch) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  110. args := AgentEmitBatchArgs{}
  111. if err = args.Read(iprot); err != nil {
  112. iprot.ReadMessageEnd()
  113. return false, err
  114. }
  115. iprot.ReadMessageEnd()
  116. var err2 error
  117. if err2 = p.handler.EmitBatch(args.Batch); err2 != nil {
  118. return true, err2
  119. }
  120. return true, nil
  121. }
  122. // HELPER FUNCTIONS AND STRUCTURES
  123. // Attributes:
  124. // - Batch
  125. type AgentEmitBatchArgs struct {
  126. Batch *Batch `thrift:"batch,1" json:"batch"`
  127. }
  128. func NewAgentEmitBatchArgs() *AgentEmitBatchArgs {
  129. return &AgentEmitBatchArgs{}
  130. }
  131. var AgentEmitBatchArgs_Batch_DEFAULT *Batch
  132. func (p *AgentEmitBatchArgs) GetBatch() *Batch {
  133. if !p.IsSetBatch() {
  134. return AgentEmitBatchArgs_Batch_DEFAULT
  135. }
  136. return p.Batch
  137. }
  138. func (p *AgentEmitBatchArgs) IsSetBatch() bool {
  139. return p.Batch != nil
  140. }
  141. func (p *AgentEmitBatchArgs) Read(iprot thrift.TProtocol) error {
  142. if _, err := iprot.ReadStructBegin(); err != nil {
  143. return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
  144. }
  145. for {
  146. _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
  147. if err != nil {
  148. return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
  149. }
  150. if fieldTypeId == thrift.STOP {
  151. break
  152. }
  153. switch fieldId {
  154. case 1:
  155. if err := p.readField1(iprot); err != nil {
  156. return err
  157. }
  158. default:
  159. if err := iprot.Skip(fieldTypeId); err != nil {
  160. return err
  161. }
  162. }
  163. if err := iprot.ReadFieldEnd(); err != nil {
  164. return err
  165. }
  166. }
  167. if err := iprot.ReadStructEnd(); err != nil {
  168. return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
  169. }
  170. return nil
  171. }
  172. func (p *AgentEmitBatchArgs) readField1(iprot thrift.TProtocol) error {
  173. p.Batch = &Batch{}
  174. if err := p.Batch.Read(iprot); err != nil {
  175. return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Batch), err)
  176. }
  177. return nil
  178. }
  179. func (p *AgentEmitBatchArgs) Write(oprot thrift.TProtocol) error {
  180. if err := oprot.WriteStructBegin("emitBatch_args"); err != nil {
  181. return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
  182. }
  183. if err := p.writeField1(oprot); err != nil {
  184. return err
  185. }
  186. if err := oprot.WriteFieldStop(); err != nil {
  187. return thrift.PrependError("write field stop error: ", err)
  188. }
  189. if err := oprot.WriteStructEnd(); err != nil {
  190. return thrift.PrependError("write struct stop error: ", err)
  191. }
  192. return nil
  193. }
  194. func (p *AgentEmitBatchArgs) writeField1(oprot thrift.TProtocol) (err error) {
  195. if err := oprot.WriteFieldBegin("batch", thrift.STRUCT, 1); err != nil {
  196. return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:batch: ", p), err)
  197. }
  198. if err := p.Batch.Write(oprot); err != nil {
  199. return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Batch), err)
  200. }
  201. if err := oprot.WriteFieldEnd(); err != nil {
  202. return thrift.PrependError(fmt.Sprintf("%T write field end error 1:batch: ", p), err)
  203. }
  204. return err
  205. }
  206. func (p *AgentEmitBatchArgs) String() string {
  207. if p == nil {
  208. return "<nil>"
  209. }
  210. return fmt.Sprintf("AgentEmitBatchArgs(%+v)", *p)
  211. }