blob: 245a3ccfc986837a11afbf98bd5e6b95e0c2fb29 [file] [log] [blame]
David K. Bainbridgebd6b2882021-08-26 13:31:02 +00001/*
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
20package thrift
21
22import "context"
23
24// A processor is a generic object which operates upon an input stream and
25// writes to some output stream.
26type 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
40type 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.
46type TProcessorFactory interface {
47 GetProcessor(trans TTransport) TProcessor
48}
49
50type tProcessorFactory struct {
51 processor TProcessor
52}
53
54func NewTProcessorFactory(p TProcessor) TProcessorFactory {
55 return &tProcessorFactory{processor: p}
56}
57
58func (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 */
66type TProcessorFunctionFactory interface {
67 GetProcessorFunction(trans TTransport) TProcessorFunction
68}
69
70type tProcessorFunctionFactory struct {
71 processor TProcessorFunction
72}
73
74func NewTProcessorFunctionFactory(p TProcessorFunction) TProcessorFunctionFactory {
75 return &tProcessorFunctionFactory{processor: p}
76}
77
78func (p *tProcessorFunctionFactory) GetProcessorFunction(trans TTransport) TProcessorFunction {
79 return p.processor
80}