proxygen
wangle::BroadcastPool< T, R, P > Class Template Reference

#include <BroadcastPool.h>

Classes

class  BroadcastManager
 

Public Member Functions

 BroadcastPool (std::shared_ptr< ServerPool< R, P >> serverPool, std::shared_ptr< BroadcastPipelineFactory< T, R >> pipelineFactory, std::shared_ptr< BaseClientBootstrapFactory<>> clientFactory=std::make_shared< ClientBootstrapFactory >())
 
virtual ~BroadcastPool ()
 
 BroadcastPool (const BroadcastPool &)=delete
 
BroadcastPooloperator= (const BroadcastPool &)=delete
 
 BroadcastPool (BroadcastPool &&)=default
 
BroadcastPooloperator= (BroadcastPool &&)=default
 
virtual folly::Future< BroadcastHandler< T, R > * > getHandler (const R &routingData)
 
bool isBroadcasting (const R &routingData)
 
virtual void deleteBroadcast (const R &routingData)
 

Private Attributes

std::shared_ptr< ServerPool< R, P > > serverPool_
 
std::shared_ptr< BroadcastPipelineFactory< T, R > > broadcastPipelineFactory_
 
std::shared_ptr< BaseClientBootstrapFactory<> > clientBootstrapFactory_
 
std::map< R, typename BroadcastManager::UniquePtrbroadcasts_
 

Detailed Description

template<typename T, typename R, typename P = DefaultPipeline>
class wangle::BroadcastPool< T, R, P >

A pool of upstream broadcast pipelines. There is atmost one broadcast for any unique routing data. Creates and maintains upstream connections and broadcast pipeliens as necessary.

Meant to be used as a thread-local instance.

Definition at line 50 of file BroadcastPool.h.

Constructor & Destructor Documentation

template<typename T, typename R, typename P = DefaultPipeline>
wangle::BroadcastPool< T, R, P >::BroadcastPool ( std::shared_ptr< ServerPool< R, P >>  serverPool,
std::shared_ptr< BroadcastPipelineFactory< T, R >>  pipelineFactory,
std::shared_ptr< BaseClientBootstrapFactory<>>  clientFactory = std::make_shared<ClientBootstrapFactory>() 
)
inline

Definition at line 91 of file BroadcastPool.h.

96  : serverPool_(serverPool),
97  broadcastPipelineFactory_(pipelineFactory),
98  clientBootstrapFactory_(clientFactory) {}
std::shared_ptr< BroadcastPipelineFactory< T, R > > broadcastPipelineFactory_
std::shared_ptr< BaseClientBootstrapFactory<> > clientBootstrapFactory_
std::shared_ptr< ServerPool< R, P > > serverPool_
template<typename T, typename R, typename P = DefaultPipeline>
virtual wangle::BroadcastPool< T, R, P >::~BroadcastPool ( )
inlinevirtual

Definition at line 100 of file BroadcastPool.h.

100 {}
template<typename T, typename R, typename P = DefaultPipeline>
wangle::BroadcastPool< T, R, P >::BroadcastPool ( const BroadcastPool< T, R, P > &  )
delete
template<typename T, typename R, typename P = DefaultPipeline>
wangle::BroadcastPool< T, R, P >::BroadcastPool ( BroadcastPool< T, R, P > &&  )
default

Member Function Documentation

template<typename T, typename R, typename P = DefaultPipeline>
virtual void wangle::BroadcastPool< T, R, P >::deleteBroadcast ( const R &  routingData)
inlinevirtual

Definition at line 135 of file BroadcastPool.h.

135  {
136  broadcasts_.erase(routingData);
137  }
std::map< R, typename BroadcastManager::UniquePtr > broadcasts_
template<typename T , typename R, typename P >
folly::Future< BroadcastHandler< T, R > * > wangle::BroadcastPool< T, R, P >::getHandler ( const R &  routingData)
virtual

Gets the BroadcastHandler, or creates one if it doesn't exist already, for the given routingData.

If a broadcast is already available for the given routingData, returns the BroadcastHandler from the pipeline. If not, an upstream connection is created and stored along with a new broadcast pipeline for this routingData, and its BroadcastHandler is returned.

Caller should immediately subscribe to the returned BroadcastHandler to prevent it from being garbage collected. Note that to ensure that this works correctly, the returned future completes on an InlineExecutor such that .then will be called inline with satisfaction of the underlying promise.

Reimplemented in wangle::MockBroadcastPool.

Definition at line 95 of file BroadcastPool-inl.h.

References wangle::BroadcastPool< T, R, P >::BroadcastManager::BroadcastManager(), wangle::BroadcastPool< T, R, P >::broadcasts_, and folly::gen::move.

96  {
97  const auto& iter = broadcasts_.find(routingData);
98  if (iter != broadcasts_.end()) {
99  return iter->second->getHandler();
100  }
101 
102  typename BroadcastManager::UniquePtr broadcast(
103  new BroadcastManager(this, routingData));
104 
105  auto broadcastPtr = broadcast.get();
106  broadcasts_.insert(std::make_pair(routingData, std::move(broadcast)));
107 
108  // The executor on this future is set to be an InlineExecutor to ensure that
109  // the continuation can be run inline and satisfy the lifetime requirement
110  // on the return value of this function.
111  return broadcastPtr->getHandler();
112 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::map< R, typename BroadcastManager::UniquePtr > broadcasts_
std::unique_ptr< BroadcastManager, folly::DelayedDestruction::Destructor > UniquePtr
Definition: BroadcastPool.h:56
template<typename T, typename R, typename P = DefaultPipeline>
bool wangle::BroadcastPool< T, R, P >::isBroadcasting ( const R &  routingData)
inline

Checks if a broadcast is available locally for the given routingData.

Definition at line 131 of file BroadcastPool.h.

Referenced by TEST_F().

131  {
132  return (broadcasts_.find(routingData) != broadcasts_.end());
133  }
std::map< R, typename BroadcastManager::UniquePtr > broadcasts_
template<typename T, typename R, typename P = DefaultPipeline>
BroadcastPool& wangle::BroadcastPool< T, R, P >::operator= ( const BroadcastPool< T, R, P > &  )
delete
template<typename T, typename R, typename P = DefaultPipeline>
BroadcastPool& wangle::BroadcastPool< T, R, P >::operator= ( BroadcastPool< T, R, P > &&  )
default

Member Data Documentation

template<typename T, typename R, typename P = DefaultPipeline>
std::shared_ptr<BroadcastPipelineFactory<T, R> > wangle::BroadcastPool< T, R, P >::broadcastPipelineFactory_
private

Definition at line 141 of file BroadcastPool.h.

template<typename T, typename R, typename P = DefaultPipeline>
std::map<R, typename BroadcastManager::UniquePtr> wangle::BroadcastPool< T, R, P >::broadcasts_
private

Definition at line 143 of file BroadcastPool.h.

Referenced by wangle::BroadcastPool< T, R, P >::getHandler().

template<typename T, typename R, typename P = DefaultPipeline>
std::shared_ptr<BaseClientBootstrapFactory<> > wangle::BroadcastPool< T, R, P >::clientBootstrapFactory_
private

Definition at line 142 of file BroadcastPool.h.

template<typename T, typename R, typename P = DefaultPipeline>
std::shared_ptr<ServerPool<R, P> > wangle::BroadcastPool< T, R, P >::serverPool_
private

Definition at line 140 of file BroadcastPool.h.


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