processor_factory.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package thrift
  20. import "context"
  21. // A processor is a generic object which operates upon an input stream and
  22. // writes to some output stream.
  23. type TProcessor interface {
  24. Process(ctx context.Context, in, out TProtocol) (bool, TException)
  25. // ProcessorMap returns a map of thrift method names to TProcessorFunctions.
  26. ProcessorMap() map[string]TProcessorFunction
  27. // AddToProcessorMap adds the given TProcessorFunction to the internal
  28. // processor map at the given key.
  29. //
  30. // If one is already set at the given key, it will be replaced with the new
  31. // TProcessorFunction.
  32. AddToProcessorMap(string, TProcessorFunction)
  33. }
  34. type TProcessorFunction interface {
  35. Process(ctx context.Context, seqId int32, in, out TProtocol) (bool, TException)
  36. }
  37. // The default processor factory just returns a singleton
  38. // instance.
  39. type TProcessorFactory interface {
  40. GetProcessor(trans TTransport) TProcessor
  41. }
  42. type tProcessorFactory struct {
  43. processor TProcessor
  44. }
  45. func NewTProcessorFactory(p TProcessor) TProcessorFactory {
  46. return &tProcessorFactory{processor: p}
  47. }
  48. func (p *tProcessorFactory) GetProcessor(trans TTransport) TProcessor {
  49. return p.processor
  50. }
  51. /**
  52. * The default processor factory just returns a singleton
  53. * instance.
  54. */
  55. type TProcessorFunctionFactory interface {
  56. GetProcessorFunction(trans TTransport) TProcessorFunction
  57. }
  58. type tProcessorFunctionFactory struct {
  59. processor TProcessorFunction
  60. }
  61. func NewTProcessorFunctionFactory(p TProcessorFunction) TProcessorFunctionFactory {
  62. return &tProcessorFunctionFactory{processor: p}
  63. }
  64. func (p *tProcessorFunctionFactory) GetProcessorFunction(trans TTransport) TProcessorFunction {
  65. return p.processor
  66. }