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
10
* http://www.apache.org/licenses/LICENSE-2.0
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
20
#ifndef _THRIFT_TASYNCPROCESSOR_H_
21
#define _THRIFT_TASYNCPROCESSOR_H_ 1
23
#include <tr1/functional>
24
#include <boost/shared_ptr.hpp>
25
#include <protocol/TProtocol.h>
26
#include <TProcessor.h>
28
namespace apache { namespace thrift { namespace async {
31
* Async version of a TProcessor. It is not expected to complete by the time
32
* the call to process returns. Instead, it calls a cob to signal completion.
35
class TEventServer; // forward declaration
37
class TAsyncProcessor {
39
virtual ~TAsyncProcessor() {}
41
virtual void process(std::tr1::function<void(bool success)> _return,
42
boost::shared_ptr<protocol::TProtocol> in,
43
boost::shared_ptr<protocol::TProtocol> out) = 0;
45
void process(std::tr1::function<void(bool success)> _return,
46
boost::shared_ptr<apache::thrift::protocol::TProtocol> io) {
47
return process(_return, io, io);
50
boost::shared_ptr<TProcessorEventHandler> getEventHandler() {
54
void setEventHandler(boost::shared_ptr<TProcessorEventHandler> eventHandler) {
55
eventHandler_ = eventHandler;
58
const TEventServer* getAsyncServer() {
64
boost::shared_ptr<TProcessorEventHandler> eventHandler_;
65
const TEventServer* asyncServer_;
67
friend class TEventServer;
68
void setAsyncServer(const TEventServer* server) {
69
asyncServer_ = server;
73
class TAsyncProcessorFactory {
75
virtual ~TAsyncProcessorFactory() {}
78
* Get the TAsyncProcessor to use for a particular connection.
80
* This method is always invoked in the same thread that the connection was
81
* accepted on. This generally means that this call does not need to be
82
* thread safe, as it will always be invoked from a single thread.
84
virtual boost::shared_ptr<TAsyncProcessor> getProcessor(
85
const TConnectionInfo& connInfo) = 0;
90
}}} // apache::thrift::async
92
// XXX I'm lazy for now
93
namespace apache { namespace thrift {
94
using apache::thrift::async::TAsyncProcessor;
97
#endif // #ifndef _THRIFT_TASYNCPROCESSOR_H_