]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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 | #ifndef _THRIFT_TASYNCPROCESSOR_H_ | |
21 | #define _THRIFT_TASYNCPROCESSOR_H_ 1 | |
22 | ||
23 | #include <thrift/protocol/TProtocol.h> | |
24 | #include <memory> | |
25 | #include <thrift/TProcessor.h> | |
26 | ||
27 | namespace apache { | |
28 | namespace thrift { | |
29 | namespace async { | |
30 | ||
31 | /** | |
32 | * Async version of a TProcessor. It is not expected to complete by the time | |
33 | * the call to process returns. Instead, it calls a cob to signal completion. | |
34 | */ | |
35 | ||
36 | class TAsyncProcessor { | |
37 | public: | |
38 | virtual ~TAsyncProcessor() = default; | |
39 | ||
40 | virtual void process(std::function<void(bool success)> _return, | |
41 | std::shared_ptr<protocol::TProtocol> in, | |
42 | std::shared_ptr<protocol::TProtocol> out) = 0; | |
43 | ||
44 | void process(std::function<void(bool success)> _return, | |
45 | std::shared_ptr<protocol::TProtocol> io) { | |
46 | return process(_return, io, io); | |
47 | } | |
48 | ||
49 | std::shared_ptr<TProcessorEventHandler> getEventHandler() const { return eventHandler_; } | |
50 | ||
51 | void setEventHandler(std::shared_ptr<TProcessorEventHandler> eventHandler) { | |
52 | eventHandler_ = eventHandler; | |
53 | } | |
54 | ||
55 | protected: | |
56 | TAsyncProcessor() = default; | |
57 | ||
58 | std::shared_ptr<TProcessorEventHandler> eventHandler_; | |
59 | }; | |
60 | ||
61 | class TAsyncProcessorFactory { | |
62 | public: | |
63 | virtual ~TAsyncProcessorFactory() = default; | |
64 | ||
65 | /** | |
66 | * Get the TAsyncProcessor to use for a particular connection. | |
67 | * | |
68 | * This method is always invoked in the same thread that the connection was | |
69 | * accepted on. This generally means that this call does not need to be | |
70 | * thread safe, as it will always be invoked from a single thread. | |
71 | */ | |
72 | virtual std::shared_ptr<TAsyncProcessor> getProcessor(const TConnectionInfo& connInfo) = 0; | |
73 | }; | |
74 | } | |
75 | } | |
76 | } // apache::thrift::async | |
77 | ||
78 | namespace apache { | |
79 | namespace thrift { | |
80 | using apache::thrift::async::TAsyncProcessor; | |
81 | } | |
82 | } | |
83 | ||
84 | #endif // #ifndef _THRIFT_TASYNCPROCESSOR_H_ |