Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:01

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
0018  */
0019 
0020 #ifndef _THRIFT_TASYNCPROCESSOR_H_
0021 #define _THRIFT_TASYNCPROCESSOR_H_ 1
0022 
0023 #include <functional>
0024 #include <memory>
0025 
0026 #include <thrift/TProcessor.h>
0027 #include <thrift/protocol/TProtocol.h>
0028 
0029 namespace apache {
0030 namespace thrift {
0031 namespace async {
0032 
0033 /**
0034  * Async version of a TProcessor.  It is not expected to complete by the time
0035  * the call to process returns.  Instead, it calls a cob to signal completion.
0036  */
0037 
0038 class TAsyncProcessor {
0039 public:
0040   virtual ~TAsyncProcessor() = default;
0041 
0042   virtual void process(std::function<void(bool success)> _return,
0043                        std::shared_ptr<protocol::TProtocol> in,
0044                        std::shared_ptr<protocol::TProtocol> out) = 0;
0045 
0046   void process(std::function<void(bool success)> _return,
0047                std::shared_ptr<protocol::TProtocol> io) {
0048     return process(_return, io, io);
0049   }
0050 
0051   std::shared_ptr<TProcessorEventHandler> getEventHandler() const { return eventHandler_; }
0052 
0053   void setEventHandler(std::shared_ptr<TProcessorEventHandler> eventHandler) {
0054     eventHandler_ = eventHandler;
0055   }
0056 
0057 protected:
0058   TAsyncProcessor() = default;
0059 
0060   std::shared_ptr<TProcessorEventHandler> eventHandler_;
0061 };
0062 
0063 class TAsyncProcessorFactory {
0064 public:
0065   virtual ~TAsyncProcessorFactory() = default;
0066 
0067   /**
0068    * Get the TAsyncProcessor to use for a particular connection.
0069    *
0070    * This method is always invoked in the same thread that the connection was
0071    * accepted on.  This generally means that this call does not need to be
0072    * thread safe, as it will always be invoked from a single thread.
0073    */
0074   virtual std::shared_ptr<TAsyncProcessor> getProcessor(const TConnectionInfo& connInfo) = 0;
0075 };
0076 }
0077 }
0078 } // apache::thrift::async
0079 
0080 namespace apache {
0081 namespace thrift {
0082   using apache::thrift::async::TAsyncProcessor;
0083 }
0084 }
0085 
0086 #endif // #ifndef _THRIFT_TASYNCPROCESSOR_H_