Public Types | Public Member Functions | Static Public Attributes | List of all members
AzmqFlatbuffer Class Reference

sends and receives flatbuffer data via AZMQ implementation of ZeroMQ plus manages the relevant buffers More...

#include <AzmqFlatbuffer.hpp>

+ Inheritance diagram for AzmqFlatbuffer:
+ Collaboration diagram for AzmqFlatbuffer:

Public Types

typedef std::shared_ptr< boost::container::static_vector< uint8_t, 256 > > receive_buffer_type
 

Public Member Functions

void async_send_flatbuffer (std::shared_ptr< flatbuffers::FlatBufferBuilder > fbbP)
 
 AzmqFlatbuffer (azmq::socket socket)
 
void cancel ()
 
template<typename OutputIterator >
void get_all_receive_buffers_with_data (OutputIterator it)
 Get all buffers from the pool at once and put them in an OutputIterator. This reduces locking/unlocking substantially. More...
 
receive_buffer_type get_back_receive_buffer_with_data ()
 get the last, aka most chronologically recent, incoming buffer from the pool More...
 
receive_buffer_type get_front_receive_buffer_with_data ()
 get the first, aka the chronologically oldest, incoming buffer from the pool More...
 
std::shared_ptr< flatbuffers::FlatBufferBuilder > GetUnusedBufferBuilder ()
 get a google FlatBufferBuilder object from the pool of unused objects More...
 
template<typename T >
void insert_unused_receive_buffers (T &range)
 
void push_back_unused_receive_buffer (receive_buffer_type rb)
 Put an unused buffer, or one that is no longer needed, back into the pool. More...
 
std::size_t receive_buffers_capacity ()
 
bool receive_buffers_empty ()
 
std::size_t receive_buffers_size ()
 
void shutdown (azmq::socket::shutdown_type sd, boost::system::error_code &ec)
 
void start_async_receive_buffers ()
 
void stop_async_receive_buffers ()
 Stop receiving buffers. More...
 
 ~AzmqFlatbuffer ()
 

Static Public Attributes

static const int default_circular_buffer_size = 10
 

Detailed Description

sends and receives flatbuffer data via AZMQ implementation of ZeroMQ plus manages the relevant buffers

Sending: This class provides a mechanism to asynchronously send google flatbuffers. It also stores a pool of these buffers so that they don't need to be reallocated.

Rationale: FlatBufferBuilders are much faster if they are reused so we create a small pool of them that you can get from this object after you send a flat buffer, the builder is put into the pool

Todo:
the buffer pools may be a premature optimization. Evaluate this.

Definition at line 35 of file AzmqFlatbuffer.hpp.

Member Typedef Documentation

§ receive_buffer_type

typedef std::shared_ptr<boost::container::static_vector<uint8_t,256> > AzmqFlatbuffer::receive_buffer_type
Todo:
Consider making this a simple std::vector so it is runtime configurable

Definition at line 41 of file AzmqFlatbuffer.hpp.

Constructor & Destructor Documentation

§ AzmqFlatbuffer()

AzmqFlatbuffer::AzmqFlatbuffer ( azmq::socket  socket)
inlineexplicit

Initialize AzmqFlatbuffer with a socket. The socket should be fully configured and ready to use when it is passed to this object. We also recommend the user utilizes AzmqFlatbuffer(std::move(socket)) when calling this constructor.

See also
AzmqFlatbufferTest for an example of usage.
Todo:
consider making default_circular_buffer_size and receive_buffer_type configurable

Definition at line 51 of file AzmqFlatbuffer.hpp.

§ ~AzmqFlatbuffer()

AzmqFlatbuffer::~AzmqFlatbuffer ( )
inline

destructor

Todo:
maybe do something useful with the error code from shutting down the socket?

Definition at line 114 of file AzmqFlatbuffer.hpp.

Member Function Documentation

§ async_send_flatbuffer()

void AzmqFlatbuffer::async_send_flatbuffer ( std::shared_ptr< flatbuffers::FlatBufferBuilder >  fbbP)
inline

Send a FlatbufferBuilder to the destination specified in the socket.

Todo:
make it so FlatBufferBuilders can be used directly without shared_ptr overhead.
Precondition
there are no other instances of fbbP (reference count of the shared_ptr should be 1)
Note
the FlatBufferBuilder is automatically put back into the pool internal to this class after sending

Definition at line 71 of file AzmqFlatbuffer.hpp.

§ cancel()

void AzmqFlatbuffer::cancel ( )
inline

Definition at line 108 of file AzmqFlatbuffer.hpp.

§ get_all_receive_buffers_with_data()

template<typename OutputIterator >
void AzmqFlatbuffer::get_all_receive_buffers_with_data ( OutputIterator  it)
inline

Get all buffers from the pool at once and put them in an OutputIterator. This reduces locking/unlocking substantially.

Definition at line 257 of file AzmqFlatbuffer.hpp.

§ get_back_receive_buffer_with_data()

receive_buffer_type AzmqFlatbuffer::get_back_receive_buffer_with_data ( )
inline

get the last, aka most chronologically recent, incoming buffer from the pool

Definition at line 232 of file AzmqFlatbuffer.hpp.

§ get_front_receive_buffer_with_data()

receive_buffer_type AzmqFlatbuffer::get_front_receive_buffer_with_data ( )
inline

get the first, aka the chronologically oldest, incoming buffer from the pool

Definition at line 244 of file AzmqFlatbuffer.hpp.

§ GetUnusedBufferBuilder()

std::shared_ptr<flatbuffers::FlatBufferBuilder> AzmqFlatbuffer::GetUnusedBufferBuilder ( )
inline

get a google FlatBufferBuilder object from the pool of unused objects

Todo:
eliminate the need for this extra allocation, though this may be premature optimization

Definition at line 124 of file AzmqFlatbuffer.hpp.

§ insert_unused_receive_buffers()

template<typename T >
void AzmqFlatbuffer::insert_unused_receive_buffers ( T &  range)
inline

Inserts a range of values into the available receive buffers

Precondition
p must be a valid iterator of *this in range [begin(), end()].
distance(first, last) <= capacity()
Iterator must meet the ForwardTraversalIterator concept.

Definition at line 220 of file AzmqFlatbuffer.hpp.

§ push_back_unused_receive_buffer()

void AzmqFlatbuffer::push_back_unused_receive_buffer ( receive_buffer_type  rb)
inline

Put an unused buffer, or one that is no longer needed, back into the pool.

Definition at line 226 of file AzmqFlatbuffer.hpp.

§ receive_buffers_capacity()

std::size_t AzmqFlatbuffer::receive_buffers_capacity ( )
inline
Returns
The number of possible incoming buffers that can be stored

Definition at line 209 of file AzmqFlatbuffer.hpp.

§ receive_buffers_empty()

bool AzmqFlatbuffer::receive_buffers_empty ( )
inline
Returns
true if there are no buffers that have been received via the socket, false otherwise

Definition at line 197 of file AzmqFlatbuffer.hpp.

§ receive_buffers_size()

std::size_t AzmqFlatbuffer::receive_buffers_size ( )
inline
Returns
The number of incoming buffers stored

Definition at line 203 of file AzmqFlatbuffer.hpp.

§ shutdown()

void AzmqFlatbuffer::shutdown ( azmq::socket::shutdown_type  sd,
boost::system::error_code &  ec 
)
inline

Definition at line 104 of file AzmqFlatbuffer.hpp.

§ start_async_receive_buffers()

void AzmqFlatbuffer::start_async_receive_buffers ( )
inline

Initializes the process of receiving buffers from the source specified by the azmq::socket taht was provided. This initializes a loop that will continuously read data and fill out the internal ring buffer for users to extract. This allows this class to run asynchronously while interacting with synchronous users.

Definition at line 146 of file AzmqFlatbuffer.hpp.

§ stop_async_receive_buffers()

void AzmqFlatbuffer::stop_async_receive_buffers ( )
inline

Stop receiving buffers.

Definition at line 191 of file AzmqFlatbuffer.hpp.

Member Data Documentation

§ default_circular_buffer_size

const int AzmqFlatbuffer::default_circular_buffer_size = 10
static

Definition at line 39 of file AzmqFlatbuffer.hpp.


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