khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame^] | 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 | |
| 20 | package thrift |
| 21 | |
| 22 | import "context" |
| 23 | |
| 24 | // A processor is a generic object which operates upon an input stream and |
| 25 | // writes to some output stream. |
| 26 | type TProcessor interface { |
| 27 | Process(ctx context.Context, in, out TProtocol) (bool, TException) |
| 28 | |
| 29 | // ProcessorMap returns a map of thrift method names to TProcessorFunctions. |
| 30 | ProcessorMap() map[string]TProcessorFunction |
| 31 | |
| 32 | // AddToProcessorMap adds the given TProcessorFunction to the internal |
| 33 | // processor map at the given key. |
| 34 | // |
| 35 | // If one is already set at the given key, it will be replaced with the new |
| 36 | // TProcessorFunction. |
| 37 | AddToProcessorMap(string, TProcessorFunction) |
| 38 | } |
| 39 | |
| 40 | type TProcessorFunction interface { |
| 41 | Process(ctx context.Context, seqId int32, in, out TProtocol) (bool, TException) |
| 42 | } |
| 43 | |
| 44 | // The default processor factory just returns a singleton |
| 45 | // instance. |
| 46 | type TProcessorFactory interface { |
| 47 | GetProcessor(trans TTransport) TProcessor |
| 48 | } |
| 49 | |
| 50 | type tProcessorFactory struct { |
| 51 | processor TProcessor |
| 52 | } |
| 53 | |
| 54 | func NewTProcessorFactory(p TProcessor) TProcessorFactory { |
| 55 | return &tProcessorFactory{processor: p} |
| 56 | } |
| 57 | |
| 58 | func (p *tProcessorFactory) GetProcessor(trans TTransport) TProcessor { |
| 59 | return p.processor |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * The default processor factory just returns a singleton |
| 64 | * instance. |
| 65 | */ |
| 66 | type TProcessorFunctionFactory interface { |
| 67 | GetProcessorFunction(trans TTransport) TProcessorFunction |
| 68 | } |
| 69 | |
| 70 | type tProcessorFunctionFactory struct { |
| 71 | processor TProcessorFunction |
| 72 | } |
| 73 | |
| 74 | func NewTProcessorFunctionFactory(p TProcessorFunction) TProcessorFunctionFactory { |
| 75 | return &tProcessorFunctionFactory{processor: p} |
| 76 | } |
| 77 | |
| 78 | func (p *tProcessorFunctionFactory) GetProcessorFunction(trans TTransport) TProcessorFunction { |
| 79 | return p.processor |
| 80 | } |