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

#include <ExpiringFilter.h>

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

Public Member Functions

 ExpiringFilter (std::shared_ptr< Service< Req, Resp >> service, std::chrono::milliseconds idleTimeoutTime=std::chrono::milliseconds(0), std::chrono::milliseconds maxTime=std::chrono::milliseconds(0), folly::Timekeeper *timekeeper=nullptr)
 
 ~ExpiringFilter () override
 
void startIdleTimer ()
 
folly::Future< Resp > operator() (Req req) 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

folly::Future< folly::UnitidleTimeout_
 
folly::Future< folly::UnitmaxTimeout_
 
std::chrono::milliseconds idleTimeoutTime_ {0}
 
std::chrono::milliseconds maxTime_ {0}
 
folly::Timekeepertimekeeper_
 
uint32_t requests_ {0}
 

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::ExpiringFilter< Req, Resp >

A service filter that expires the self service after a certain amount of idle time, or after a maximum amount of time total. Idle timeout is cancelled when any requests are outstanding.

Definition at line 28 of file ExpiringFilter.h.

Constructor & Destructor Documentation

template<typename Req, typename Resp = Req>
wangle::ExpiringFilter< Req, Resp >::ExpiringFilter ( std::shared_ptr< Service< Req, Resp >>  service,
std::chrono::milliseconds  idleTimeoutTime = std::chrono::milliseconds(0),
std::chrono::milliseconds  maxTime = std::chrono::milliseconds(0),
folly::Timekeeper timekeeper = nullptr 
)
inlineexplicit

Definition at line 30 of file ExpiringFilter.h.

References wangle::ServiceFilter< Req, Resp >::close(), wangle::ExpiringFilter< Req, Resp >::maxTime_, wangle::ExpiringFilter< Req, Resp >::maxTimeout_, folly::gen::move, folly::futures::sleep(), wangle::ExpiringFilter< Req, Resp >::startIdleTimer(), and wangle::ExpiringFilter< Req, Resp >::timekeeper_.

36  : ServiceFilter<Req, Resp>(service)
37  , idleTimeoutTime_(idleTimeoutTime)
38  , maxTime_(maxTime)
39  , timekeeper_(timekeeper) {
40 
41  if (maxTime_ > std::chrono::milliseconds(0)) {
43  std::move(maxTimeout_).thenValue([this](auto&&) { this->close(); });
44  }
46  }
folly::Future< folly::Unit > close() override
Definition: Service.h:73
std::chrono::milliseconds maxTime_
Future< Unit > sleep(Duration dur, Timekeeper *tk)
Definition: Future.cpp:42
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Timekeeper * timekeeper_
folly::Future< folly::Unit > maxTimeout_
std::chrono::milliseconds idleTimeoutTime_
template<typename Req, typename Resp = Req>
wangle::ExpiringFilter< Req, Resp >::~ExpiringFilter ( )
inlineoverride

Definition at line 48 of file ExpiringFilter.h.

References wangle::ExpiringFilter< Req, Resp >::idleTimeout_, and wangle::ExpiringFilter< Req, Resp >::maxTimeout_.

48  {
49  if (!idleTimeout_.isReady()) {
50  idleTimeout_.cancel();
51  }
52  if (!maxTimeout_.isReady()) {
53  maxTimeout_.cancel();
54  }
55  }
folly::Future< folly::Unit > idleTimeout_
folly::Future< folly::Unit > maxTimeout_

Member Function Documentation

template<typename Req, typename Resp = Req>
folly::Future<Resp> wangle::ExpiringFilter< Req, Resp >::operator() ( Req  req)
inlineoverridevirtual

Implements wangle::Service< Req, Resp >.

Definition at line 67 of file ExpiringFilter.h.

References wangle::ExpiringFilter< Req, Resp >::idleTimeout_, folly::gen::move, wangle::ExpiringFilter< Req, Resp >::requests_, wangle::ServiceFilter< Req, Resp >::service_, and wangle::ExpiringFilter< Req, Resp >::startIdleTimer().

67  {
68  if (!idleTimeout_.isReady()) {
69  idleTimeout_.cancel();
70  }
71  requests_++;
72  return (*this->service_)(std::move(req)).ensure([this](){
73  requests_--;
75  });
76  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Future< folly::Unit > idleTimeout_
std::shared_ptr< Service< Req, Resp > > service_
Definition: Service.h:82
template<typename Req, typename Resp = Req>
void wangle::ExpiringFilter< Req, Resp >::startIdleTimer ( )
inline

Definition at line 57 of file ExpiringFilter.h.

References wangle::ServiceFilter< Req, Resp >::close(), wangle::ExpiringFilter< Req, Resp >::idleTimeout_, wangle::ExpiringFilter< Req, Resp >::idleTimeoutTime_, folly::gen::move, wangle::ExpiringFilter< Req, Resp >::requests_, folly::futures::sleep(), and wangle::ExpiringFilter< Req, Resp >::timekeeper_.

Referenced by wangle::ExpiringFilter< Req, Resp >::ExpiringFilter(), and wangle::ExpiringFilter< Req, Resp >::operator()().

57  {
58  if (requests_ != 0) {
59  return;
60  }
61  if (idleTimeoutTime_ > std::chrono::milliseconds(0)) {
63  std::move(idleTimeout_).thenValue([this](auto&&) { this->close(); });
64  }
65  }
folly::Future< folly::Unit > close() override
Definition: Service.h:73
Future< Unit > sleep(Duration dur, Timekeeper *tk)
Definition: Future.cpp:42
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Future< folly::Unit > idleTimeout_
folly::Timekeeper * timekeeper_
std::chrono::milliseconds idleTimeoutTime_

Member Data Documentation

template<typename Req, typename Resp = Req>
std::chrono::milliseconds wangle::ExpiringFilter< Req, Resp >::idleTimeoutTime_ {0}
private
template<typename Req, typename Resp = Req>
std::chrono::milliseconds wangle::ExpiringFilter< Req, Resp >::maxTime_ {0}
private
template<typename Req, typename Resp = Req>
folly::Future<folly::Unit> wangle::ExpiringFilter< Req, Resp >::maxTimeout_
private
template<typename Req, typename Resp = Req>
uint32_t wangle::ExpiringFilter< Req, Resp >::requests_ {0}
private
template<typename Req, typename Resp = Req>
folly::Timekeeper* wangle::ExpiringFilter< Req, Resp >::timekeeper_
private

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