rocksdb/thrift/lib/cpp/async/TSyncToAsyncProcessor.h
Dhruba Borthakur 80c663882a Create leveldb server via Thrift.
Summary:
First draft.
Unit tests pass.

Test Plan: unit tests attached

Reviewers: heyongqiang

Reviewed By: heyongqiang

Differential Revision: https://reviews.facebook.net/D3969
2012-07-07 09:42:39 -07:00

43 lines
1.3 KiB
C++

// Copyright (c) 2006- Facebook
// Distributed under the Thrift Software License
//
// See accompanying file LICENSE or visit the Thrift site at:
// http://developers.facebook.com/thrift/
#ifndef _THRIFT_TSYNCTOASYNCPROCESSOR_H_
#define _THRIFT_TSYNCTOASYNCPROCESSOR_H_ 1
#include <tr1/functional>
#include <boost/shared_ptr.hpp>
#include "thrift/lib/cpp/TProcessor.h"
#include "thrift/lib/cpp/async/TAsyncProcessor.h"
namespace apache { namespace thrift { namespace async {
/**
* Adapter to allow a TProcessor to be used as a TAsyncProcessor.
*
* Note that this should only be used for handlers that return quickly without
* blocking, since async servers can be stalled by a single blocking operation.
*/
class TSyncToAsyncProcessor : public TAsyncProcessor {
public:
TSyncToAsyncProcessor(boost::shared_ptr<TProcessor> processor)
: processor_(processor)
{}
virtual void process(std::tr1::function<void(bool success)> _return,
boost::shared_ptr<protocol::TProtocol> in,
boost::shared_ptr<protocol::TProtocol> out,
TConnectionContext* context) {
return _return(processor_->process(in, out, context));
}
private:
boost::shared_ptr<TProcessor> processor_;
};
}}} // apache::thrift::async
#endif // #ifndef _THRIFT_TSYNCTOASYNCPROCESSOR_H_