samplingmanager.go 12 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 sampling
  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 SamplingManager interface {
  14. // Parameters:
  15. // - ServiceName
  16. GetSamplingStrategy(serviceName string) (r *SamplingStrategyResponse, err error)
  17. }
  18. type SamplingManagerClient struct {
  19. Transport thrift.TTransport
  20. ProtocolFactory thrift.TProtocolFactory
  21. InputProtocol thrift.TProtocol
  22. OutputProtocol thrift.TProtocol
  23. SeqId int32
  24. }
  25. func NewSamplingManagerClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *SamplingManagerClient {
  26. return &SamplingManagerClient{Transport: t,
  27. ProtocolFactory: f,
  28. InputProtocol: f.GetProtocol(t),
  29. OutputProtocol: f.GetProtocol(t),
  30. SeqId: 0,
  31. }
  32. }
  33. func NewSamplingManagerClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *SamplingManagerClient {
  34. return &SamplingManagerClient{Transport: t,
  35. ProtocolFactory: nil,
  36. InputProtocol: iprot,
  37. OutputProtocol: oprot,
  38. SeqId: 0,
  39. }
  40. }
  41. // Parameters:
  42. // - ServiceName
  43. func (p *SamplingManagerClient) GetSamplingStrategy(serviceName string) (r *SamplingStrategyResponse, err error) {
  44. if err = p.sendGetSamplingStrategy(serviceName); err != nil {
  45. return
  46. }
  47. return p.recvGetSamplingStrategy()
  48. }
  49. func (p *SamplingManagerClient) sendGetSamplingStrategy(serviceName string) (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("getSamplingStrategy", thrift.CALL, p.SeqId); err != nil {
  57. return
  58. }
  59. args := SamplingManagerGetSamplingStrategyArgs{
  60. ServiceName: serviceName,
  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. func (p *SamplingManagerClient) recvGetSamplingStrategy() (value *SamplingStrategyResponse, err error) {
  71. iprot := p.InputProtocol
  72. if iprot == nil {
  73. iprot = p.ProtocolFactory.GetProtocol(p.Transport)
  74. p.InputProtocol = iprot
  75. }
  76. method, mTypeId, seqId, err := iprot.ReadMessageBegin()
  77. if err != nil {
  78. return
  79. }
  80. if method != "getSamplingStrategy" {
  81. err = thrift.NewTApplicationException(thrift.WRONG_METHOD_NAME, "getSamplingStrategy failed: wrong method name")
  82. return
  83. }
  84. if p.SeqId != seqId {
  85. err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getSamplingStrategy failed: out of sequence response")
  86. return
  87. }
  88. if mTypeId == thrift.EXCEPTION {
  89. error1 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception")
  90. var error2 error
  91. error2, err = error1.Read(iprot)
  92. if err != nil {
  93. return
  94. }
  95. if err = iprot.ReadMessageEnd(); err != nil {
  96. return
  97. }
  98. err = error2
  99. return
  100. }
  101. if mTypeId != thrift.REPLY {
  102. err = thrift.NewTApplicationException(thrift.INVALID_MESSAGE_TYPE_EXCEPTION, "getSamplingStrategy failed: invalid message type")
  103. return
  104. }
  105. result := SamplingManagerGetSamplingStrategyResult{}
  106. if err = result.Read(iprot); err != nil {
  107. return
  108. }
  109. if err = iprot.ReadMessageEnd(); err != nil {
  110. return
  111. }
  112. value = result.GetSuccess()
  113. return
  114. }
  115. type SamplingManagerProcessor struct {
  116. processorMap map[string]thrift.TProcessorFunction
  117. handler SamplingManager
  118. }
  119. func (p *SamplingManagerProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
  120. p.processorMap[key] = processor
  121. }
  122. func (p *SamplingManagerProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
  123. processor, ok = p.processorMap[key]
  124. return processor, ok
  125. }
  126. func (p *SamplingManagerProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
  127. return p.processorMap
  128. }
  129. func NewSamplingManagerProcessor(handler SamplingManager) *SamplingManagerProcessor {
  130. self3 := &SamplingManagerProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
  131. self3.processorMap["getSamplingStrategy"] = &samplingManagerProcessorGetSamplingStrategy{handler: handler}
  132. return self3
  133. }
  134. func (p *SamplingManagerProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  135. name, _, seqId, err := iprot.ReadMessageBegin()
  136. if err != nil {
  137. return false, err
  138. }
  139. if processor, ok := p.GetProcessorFunction(name); ok {
  140. return processor.Process(seqId, iprot, oprot)
  141. }
  142. iprot.Skip(thrift.STRUCT)
  143. iprot.ReadMessageEnd()
  144. x4 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
  145. oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
  146. x4.Write(oprot)
  147. oprot.WriteMessageEnd()
  148. oprot.Flush()
  149. return false, x4
  150. }
  151. type samplingManagerProcessorGetSamplingStrategy struct {
  152. handler SamplingManager
  153. }
  154. func (p *samplingManagerProcessorGetSamplingStrategy) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  155. args := SamplingManagerGetSamplingStrategyArgs{}
  156. if err = args.Read(iprot); err != nil {
  157. iprot.ReadMessageEnd()
  158. x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
  159. oprot.WriteMessageBegin("getSamplingStrategy", thrift.EXCEPTION, seqId)
  160. x.Write(oprot)
  161. oprot.WriteMessageEnd()
  162. oprot.Flush()
  163. return false, err
  164. }
  165. iprot.ReadMessageEnd()
  166. result := SamplingManagerGetSamplingStrategyResult{}
  167. var retval *SamplingStrategyResponse
  168. var err2 error
  169. if retval, err2 = p.handler.GetSamplingStrategy(args.ServiceName); err2 != nil {
  170. x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getSamplingStrategy: "+err2.Error())
  171. oprot.WriteMessageBegin("getSamplingStrategy", thrift.EXCEPTION, seqId)
  172. x.Write(oprot)
  173. oprot.WriteMessageEnd()
  174. oprot.Flush()
  175. return true, err2
  176. } else {
  177. result.Success = retval
  178. }
  179. if err2 = oprot.WriteMessageBegin("getSamplingStrategy", thrift.REPLY, seqId); err2 != nil {
  180. err = err2
  181. }
  182. if err2 = result.Write(oprot); err == nil && err2 != nil {
  183. err = err2
  184. }
  185. if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
  186. err = err2
  187. }
  188. if err2 = oprot.Flush(); err == nil && err2 != nil {
  189. err = err2
  190. }
  191. if err != nil {
  192. return
  193. }
  194. return true, err
  195. }
  196. // HELPER FUNCTIONS AND STRUCTURES
  197. // Attributes:
  198. // - ServiceName
  199. type SamplingManagerGetSamplingStrategyArgs struct {
  200. ServiceName string `thrift:"serviceName,1" json:"serviceName"`
  201. }
  202. func NewSamplingManagerGetSamplingStrategyArgs() *SamplingManagerGetSamplingStrategyArgs {
  203. return &SamplingManagerGetSamplingStrategyArgs{}
  204. }
  205. func (p *SamplingManagerGetSamplingStrategyArgs) GetServiceName() string {
  206. return p.ServiceName
  207. }
  208. func (p *SamplingManagerGetSamplingStrategyArgs) Read(iprot thrift.TProtocol) error {
  209. if _, err := iprot.ReadStructBegin(); err != nil {
  210. return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
  211. }
  212. for {
  213. _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
  214. if err != nil {
  215. return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
  216. }
  217. if fieldTypeId == thrift.STOP {
  218. break
  219. }
  220. switch fieldId {
  221. case 1:
  222. if err := p.readField1(iprot); err != nil {
  223. return err
  224. }
  225. default:
  226. if err := iprot.Skip(fieldTypeId); err != nil {
  227. return err
  228. }
  229. }
  230. if err := iprot.ReadFieldEnd(); err != nil {
  231. return err
  232. }
  233. }
  234. if err := iprot.ReadStructEnd(); err != nil {
  235. return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
  236. }
  237. return nil
  238. }
  239. func (p *SamplingManagerGetSamplingStrategyArgs) readField1(iprot thrift.TProtocol) error {
  240. if v, err := iprot.ReadString(); err != nil {
  241. return thrift.PrependError("error reading field 1: ", err)
  242. } else {
  243. p.ServiceName = v
  244. }
  245. return nil
  246. }
  247. func (p *SamplingManagerGetSamplingStrategyArgs) Write(oprot thrift.TProtocol) error {
  248. if err := oprot.WriteStructBegin("getSamplingStrategy_args"); err != nil {
  249. return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
  250. }
  251. if err := p.writeField1(oprot); err != nil {
  252. return err
  253. }
  254. if err := oprot.WriteFieldStop(); err != nil {
  255. return thrift.PrependError("write field stop error: ", err)
  256. }
  257. if err := oprot.WriteStructEnd(); err != nil {
  258. return thrift.PrependError("write struct stop error: ", err)
  259. }
  260. return nil
  261. }
  262. func (p *SamplingManagerGetSamplingStrategyArgs) writeField1(oprot thrift.TProtocol) (err error) {
  263. if err := oprot.WriteFieldBegin("serviceName", thrift.STRING, 1); err != nil {
  264. return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:serviceName: ", p), err)
  265. }
  266. if err := oprot.WriteString(string(p.ServiceName)); err != nil {
  267. return thrift.PrependError(fmt.Sprintf("%T.serviceName (1) field write error: ", p), err)
  268. }
  269. if err := oprot.WriteFieldEnd(); err != nil {
  270. return thrift.PrependError(fmt.Sprintf("%T write field end error 1:serviceName: ", p), err)
  271. }
  272. return err
  273. }
  274. func (p *SamplingManagerGetSamplingStrategyArgs) String() string {
  275. if p == nil {
  276. return "<nil>"
  277. }
  278. return fmt.Sprintf("SamplingManagerGetSamplingStrategyArgs(%+v)", *p)
  279. }
  280. // Attributes:
  281. // - Success
  282. type SamplingManagerGetSamplingStrategyResult struct {
  283. Success *SamplingStrategyResponse `thrift:"success,0" json:"success,omitempty"`
  284. }
  285. func NewSamplingManagerGetSamplingStrategyResult() *SamplingManagerGetSamplingStrategyResult {
  286. return &SamplingManagerGetSamplingStrategyResult{}
  287. }
  288. var SamplingManagerGetSamplingStrategyResult_Success_DEFAULT *SamplingStrategyResponse
  289. func (p *SamplingManagerGetSamplingStrategyResult) GetSuccess() *SamplingStrategyResponse {
  290. if !p.IsSetSuccess() {
  291. return SamplingManagerGetSamplingStrategyResult_Success_DEFAULT
  292. }
  293. return p.Success
  294. }
  295. func (p *SamplingManagerGetSamplingStrategyResult) IsSetSuccess() bool {
  296. return p.Success != nil
  297. }
  298. func (p *SamplingManagerGetSamplingStrategyResult) Read(iprot thrift.TProtocol) error {
  299. if _, err := iprot.ReadStructBegin(); err != nil {
  300. return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
  301. }
  302. for {
  303. _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
  304. if err != nil {
  305. return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
  306. }
  307. if fieldTypeId == thrift.STOP {
  308. break
  309. }
  310. switch fieldId {
  311. case 0:
  312. if err := p.readField0(iprot); err != nil {
  313. return err
  314. }
  315. default:
  316. if err := iprot.Skip(fieldTypeId); err != nil {
  317. return err
  318. }
  319. }
  320. if err := iprot.ReadFieldEnd(); err != nil {
  321. return err
  322. }
  323. }
  324. if err := iprot.ReadStructEnd(); err != nil {
  325. return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
  326. }
  327. return nil
  328. }
  329. func (p *SamplingManagerGetSamplingStrategyResult) readField0(iprot thrift.TProtocol) error {
  330. p.Success = &SamplingStrategyResponse{}
  331. if err := p.Success.Read(iprot); err != nil {
  332. return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err)
  333. }
  334. return nil
  335. }
  336. func (p *SamplingManagerGetSamplingStrategyResult) Write(oprot thrift.TProtocol) error {
  337. if err := oprot.WriteStructBegin("getSamplingStrategy_result"); err != nil {
  338. return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
  339. }
  340. if err := p.writeField0(oprot); err != nil {
  341. return err
  342. }
  343. if err := oprot.WriteFieldStop(); err != nil {
  344. return thrift.PrependError("write field stop error: ", err)
  345. }
  346. if err := oprot.WriteStructEnd(); err != nil {
  347. return thrift.PrependError("write struct stop error: ", err)
  348. }
  349. return nil
  350. }
  351. func (p *SamplingManagerGetSamplingStrategyResult) writeField0(oprot thrift.TProtocol) (err error) {
  352. if p.IsSetSuccess() {
  353. if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
  354. return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err)
  355. }
  356. if err := p.Success.Write(oprot); err != nil {
  357. return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err)
  358. }
  359. if err := oprot.WriteFieldEnd(); err != nil {
  360. return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err)
  361. }
  362. }
  363. return err
  364. }
  365. func (p *SamplingManagerGetSamplingStrategyResult) String() string {
  366. if p == nil {
  367. return "<nil>"
  368. }
  369. return fmt.Sprintf("SamplingManagerGetSamplingStrategyResult(%+v)", *p)
  370. }