proxygen
wangle::CloseOnReleaseFilter< Req, Resp > Class Template Reference

#include <CloseOnReleaseFilter.h>

Inheritance diagram for wangle::CloseOnReleaseFilter< Req, Resp >:
wangle::ServiceFilter< Req, Resp > wangle::Service< Req, Resp >

Public Member Functions

 CloseOnReleaseFilter (std::shared_ptr< Service< Req, Resp >> service)
 
folly::Future< Resp > operator() (Req req) override
 
folly::Future< folly::Unitclose () override
 
- Public Member Functions inherited from wangle::ServiceFilter< Req, Resp >
 ServiceFilter (std::shared_ptr< Service< Req, Resp >> service)
 
 ~ServiceFilter () override=default
 
folly::Future< folly::Unitclose () override
 
bool isAvailable () override
 
- Public Member Functions inherited from wangle::Service< Req, Resp >
virtual ~Service ()=default
 

Private Attributes

std::atomic< bool > released {false}
 

Additional Inherited Members

- Protected Attributes inherited from wangle::ServiceFilter< Req, Resp >
std::shared_ptr< Service< Req, Resp > > service_
 

Detailed Description

template<typename Req, typename Resp = Req>
class wangle::CloseOnReleaseFilter< Req, Resp >

A service that rejects all requests after its 'close' method has been invoked.

Definition at line 28 of file CloseOnReleaseFilter.h.

Constructor & Destructor Documentation

template<typename Req , typename Resp = Req>
wangle::CloseOnReleaseFilter< Req, Resp >::CloseOnReleaseFilter ( std::shared_ptr< Service< Req, Resp >>  service)
inlineexplicit

Definition at line 30 of file CloseOnReleaseFilter.h.

31  : ServiceFilter<Req, Resp>(service) {}

Member Function Documentation

template<typename Req , typename Resp = Req>
folly::Future<folly::Unit> wangle::CloseOnReleaseFilter< Req, Resp >::close ( )
inlineoverridevirtual

Reimplemented from wangle::Service< Req, Resp >.

Definition at line 42 of file CloseOnReleaseFilter.h.

References folly::makeFuture(), wangle::CloseOnReleaseFilter< Req, Resp >::released, and wangle::ServiceFilter< Req, Resp >::service_.

42  {
43  if (!released.exchange(true)) {
44  return this->service_->close();
45  } else {
46  return folly::makeFuture();
47  }
48  }
std::shared_ptr< Service< Req, Resp > > service_
Definition: Service.h:82
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
template<typename Req , typename Resp = Req>
folly::Future<Resp> wangle::CloseOnReleaseFilter< Req, Resp >::operator() ( Req  req)
inlineoverridevirtual

Implements wangle::Service< Req, Resp >.

Definition at line 33 of file CloseOnReleaseFilter.h.

References folly::gen::move, wangle::CloseOnReleaseFilter< Req, Resp >::released, and wangle::ServiceFilter< Req, Resp >::service_.

33  {
34  if (!released ){
35  return (*this->service_)(std::move(req));
36  } else {
37  return folly::makeFuture<Resp>(
38  folly::make_exception_wrapper<std::runtime_error>("Service Closed"));
39  }
40  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< Service< Req, Resp > > service_
Definition: Service.h:82

Member Data Documentation

template<typename Req , typename Resp = Req>
std::atomic<bool> wangle::CloseOnReleaseFilter< Req, Resp >::released {false}
private

The documentation for this class was generated from the following file: