Scheduler< Impl, ImplPtr > Class Template Reference

#include <scheduler.h>

List of all members.


Detailed Description

template<typename Impl, typename ImplPtr = Impl*>
class Scheduler< Impl, ImplPtr >

Scheduler class, implementing second level of HydraNode Networking Scheduling API, abstracts away modules part of the sockets by generating a priority score (PS) for each of the pending requests.

All requests are received from the frontend, wrapped into generic containers, and buffered internally for later processing. No direct action shall be taken in the functions directly or indirectly called from frontend.

Parameters:
Impl Implemenetation class type
ImplPtr Pointer to implementation class

Definition at line 295 of file scheduler.h.


Public Types

typedef std::set< SSocketWrapper
>::iterator 
SIter
typedef std::map< ImplPtr,
SchedBase::ReqBase * >::iterator 
RIter

Static Public Member Functions

template<typename Module>
static void write (ImplPtr ptr, const std::string &data)
 Schedule outgoing data.
template<typename Module>
static void read (ImplPtr ptr, std::string *buf)
 Read data from socket.
template<typename Module>
static std::string getData (ImplPtr ptr)
 Faster version of read(), this returns the input buffer directly, performing two std::string copy operations (cheap on most impls), avoiding (possibly costly) std::string::append() call.
template<typename Module>
static AcceptTypeaccept (ImplPtr ptr)
 Accept a pending connection.
template<typename Module>
static void connect (ImplPtr ptr, IPV4Address addr, uint32_t timeout)
 Request an outgoing connection.
template<typename Module>
static void disconnect (ImplPtr ptr, bool lazy)
 Disconnect a connected socket.
template<typename Module>
static void addSocket (ImplPtr s, HandlerFunc h)
 Add a socket to the scheduler.
static void delSocket (ImplPtr s)
 Remove a socket from the scheduler.
static void invalidateReqs (ImplPtr ptr)
 Invalidate all requests related to a specific socket.

Static Public Attributes

static std::set< SSocketWrappers_sockets
 set of all scheduled sockets
static std::set< ImplPtr > s_toDisconnect
 Sockets to be disconnected as soon as all pending upstream data has been sent out.
Maps to keep pointers to all pending requests for all sockets.
The purpose of these maps is to keep backwards links to requests submitted to SchedBase in case we need to invalidate them or something.

Note that these maps only keep weak references to the requests. Elements of these maps should never be deleted directly. The elements are owned by SchedBase class.

To make things simpler and cleaner, the specific requests insert themselves to these maps on construction, and erase themselves on destruction.

static std::map< ImplPtr,
SchedBase::ReqBase * > 
s_upReqs
static std::map< ImplPtr,
SchedBase::ReqBase * > 
s_downReqs
static std::map< ImplPtr,
SchedBase::ReqBase * > 
s_connReqs
static std::map< ImplPtr,
SchedBase::ReqBase * > 
s_accReqs

Private Types

typedef boost::function< float(ImplPtr)> ScoreFunc
 Function object that can be used to retrieve a module's score.
typedef Impl::AcceptType AcceptType
 Accept type (saves some typing).
typedef Impl::EventType EventType
 Type of events emitted from Impl.
typedef boost::function< void(ImplPtr, EventType)> HandlerFunc
 Function prototype for events emitted from Impl.
typedef GetEventHandler< Impl,
Scheduler >::Handler 
EventHandler
 Event handler object.

Classes

class  AcceptReq
 Accept request indicates we wish to accept an incoming connection from one of the servers. More...
class  ConnReq
 Connection request indicates we wish to perform an outgoing connection. More...
class  DownloadReq
 Download request is an indication that we wish to receive data from a peer. More...
class  SSocketWrapper
 Wrapper object for scheduled socket, contains all the useful information we need, e.g. More...
class  UploadReq
 Upload request is a request that indicates we wish to send out data to a socket. More...

Member Typedef Documentation

template<typename Impl, typename ImplPtr = Impl*>
typedef Impl::AcceptType Scheduler< Impl, ImplPtr >::AcceptType [private]
 

Accept type (saves some typing).

Definition at line 299 of file scheduler.h.

template<typename Impl, typename ImplPtr = Impl*>
typedef GetEventHandler<Impl, Scheduler>::Handler Scheduler< Impl, ImplPtr >::EventHandler [private]
 

Event handler object.

Definition at line 305 of file scheduler.h.

template<typename Impl, typename ImplPtr = Impl*>
typedef Impl::EventType Scheduler< Impl, ImplPtr >::EventType [private]
 

Type of events emitted from Impl.

Definition at line 301 of file scheduler.h.

template<typename Impl, typename ImplPtr = Impl*>
typedef boost::function<void (ImplPtr, EventType)> Scheduler< Impl, ImplPtr >::HandlerFunc [private]
 

Function prototype for events emitted from Impl.

Definition at line 303 of file scheduler.h.

template<typename Impl, typename ImplPtr = Impl*>
typedef std::map< ImplPtr, SchedBase::ReqBase* >::iterator Scheduler< Impl, ImplPtr >::RIter
 

Definition at line 838 of file scheduler.h.

template<typename Impl, typename ImplPtr = Impl*>
typedef boost::function<float (ImplPtr)> Scheduler< Impl, ImplPtr >::ScoreFunc [private]
 

Function object that can be used to retrieve a module's score.

Definition at line 297 of file scheduler.h.

template<typename Impl, typename ImplPtr = Impl*>
typedef std::set<SSocketWrapper>::iterator Scheduler< Impl, ImplPtr >::SIter
 

Definition at line 810 of file scheduler.h.


Member Function Documentation

template<typename Impl, typename ImplPtr = Impl*>
template<typename Module>
static AcceptType* Scheduler< Impl, ImplPtr >::accept ImplPtr  ptr  )  [inline, static]
 

Accept a pending connection.

Parameters:
ptr Socket to accept the connection from
Returns:
A new socket, which is in connected state
The function searches the internal buffer for the socket designated to by ptr parameter, and returns the dynamically allocated connection to caller. If there are no pending accepted connections, exception is thrown.

Definition at line 397 of file scheduler.h.

References CHECK_FAIL, CHECK_THROW, and Scheduler< Impl, ImplPtr >::s_sockets.

template<typename Impl, typename ImplPtr = Impl*>
template<typename Module>
static void Scheduler< Impl, ImplPtr >::addSocket ImplPtr  s,
HandlerFunc  h
[inline, static]
 

Add a socket to the scheduler.

Parameters:
Module Module owning this socket
s Socket to be added
h Frontend event handler for notifications

Definition at line 454 of file scheduler.h.

References logTrace(), Scheduler< Impl, ImplPtr >::s_sockets, Scheduler< Impl, ImplPtr >::SSocketWrapper::setConn(), and TRACE_SCHED.

Here is the call graph for this function:

template<typename Impl, typename ImplPtr = Impl*>
template<typename Module>
static void Scheduler< Impl, ImplPtr >::connect ImplPtr  ptr,
IPV4Address  addr,
uint32_t  timeout
[inline, static]
 

Request an outgoing connection.

Parameters:
ptr Socket requesting the connection addr Address to connect to
timeout Milliseconds to try to connect before giving up

Definition at line 414 of file scheduler.h.

References SchedBase::addConnReq(), CHECK_FAIL, SchedBase::instance(), and Scheduler< Impl, ImplPtr >::s_sockets.

Here is the call graph for this function:

template<typename Impl, typename ImplPtr = Impl*>
static void Scheduler< Impl, ImplPtr >::delSocket ImplPtr  s  )  [inline, static]
 

Remove a socket from the scheduler.

Parameters:
s Socket to be removed
Note:
All pending data buffers will be cleared for this socket.

All pending requests related to this socket will be deleted.

Definition at line 476 of file scheduler.h.

References CHECK_FAIL, SchedBase::delConn(), Scheduler< Impl, ImplPtr >::SSocketWrapper::getConn(), Scheduler< Impl, ImplPtr >::SSocketWrapper::getSocket(), SchedBase::instance(), Scheduler< Impl, ImplPtr >::invalidateReqs(), logTrace(), Scheduler< Impl, ImplPtr >::s_sockets, and TRACE_SCHED.

Here is the call graph for this function:

template<typename Impl, typename ImplPtr = Impl*>
template<typename Module>
static void Scheduler< Impl, ImplPtr >::disconnect ImplPtr  ptr,
bool  lazy
[inline, static]
 

Disconnect a connected socket.

Parameters:
ptr Socket to be disconnected
lazy If true, the actual disconnection is delayed until all outgoing data is sent out.
Note that disconnecting a socket invalidates all pending requests for this socket, however does not clear already buffered data.

Definition at line 432 of file scheduler.h.

References CHECK_FAIL, SchedBase::delConn(), SchedBase::instance(), Scheduler< Impl, ImplPtr >::invalidateReqs(), Scheduler< Impl, ImplPtr >::s_sockets, and Scheduler< Impl, ImplPtr >::s_toDisconnect.

Here is the call graph for this function:

template<typename Impl, typename ImplPtr = Impl*>
template<typename Module>
static std::string Scheduler< Impl, ImplPtr >::getData ImplPtr  ptr  )  [inline, static]
 

Faster version of read(), this returns the input buffer directly, performing two std::string copy operations (cheap on most impls), avoiding (possibly costly) std::string::append() call.

Parameters:
ptr Pointer to socket to read data from
Returns:
The current input buffer
Note:
Just as with read() method, the scheduler's internal buffer is cleared with this call.

Definition at line 377 of file scheduler.h.

References CHECK_FAIL, and Scheduler< Impl, ImplPtr >::s_sockets.

template<typename Impl, typename ImplPtr = Impl*>
static void Scheduler< Impl, ImplPtr >::invalidateReqs ImplPtr  ptr  )  [inline, static]
 

Invalidate all requests related to a specific socket.

Parameters:
ptr Socket for which all requests should be invalidated

Definition at line 845 of file scheduler.h.

References logTrace(), Scheduler< Impl, ImplPtr >::s_accReqs, Scheduler< Impl, ImplPtr >::s_connReqs, Scheduler< Impl, ImplPtr >::s_downReqs, Scheduler< Impl, ImplPtr >::s_upReqs, and TRACE_SCHED.

Referenced by Scheduler< Impl, ImplPtr >::delSocket(), Scheduler< Impl, ImplPtr >::disconnect(), and SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleErr().

Here is the call graph for this function:

template<typename Impl, typename ImplPtr = Impl*>
template<typename Module>
static void Scheduler< Impl, ImplPtr >::read ImplPtr  ptr,
std::string *  buf
[inline, static]
 

Read data from socket.

Parameters:
ptr Socket to read data from
buf Buffer to append the retrieved data to
This function is only allowed to read data from previously allocated internal buffer. No additional network I/O may be performed. The internal buffer is located using the passed pointer, and the found data (if any) appeneded to the designated buffer. The internal buffer must then be deallocated.

Note:
It is not required that the designated socket is in connected state at the time of this call, since no actual networking I/O is performed.

Definition at line 358 of file scheduler.h.

References CHECK_FAIL, and Scheduler< Impl, ImplPtr >::s_sockets.

template<typename Impl, typename ImplPtr = Impl*>
template<typename Module>
static void Scheduler< Impl, ImplPtr >::write ImplPtr  ptr,
const std::string &  data
[inline, static]
 

Schedule outgoing data.

Parameters:
ptr Implementation pointer where to send this data
data Data buffer to be sent out
If there is existing outgoing data scheduled for this socket, the newly passed data must be appeneded to existing data buffer. Otherwise, a new data buffer is allocated for this socket, and the data copied into there. In the latter case, a new upload request is generated and submitted to SchedBase for processing.

Note:
The pointed socket is not required to be in connected state at the time of this call, since no actual I/O is performed here. In that case, the data will be sent as soon as the connection has been established.
Precondition:
ptr is previously added to scheduler using addSocket method

Definition at line 327 of file scheduler.h.

References SchedBase::addUploadReq(), CHECK_FAIL, SchedBase::instance(), Scheduler< Impl, ImplPtr >::s_sockets, and Scheduler< Impl, ImplPtr >::s_upReqs.

Here is the call graph for this function:


Member Data Documentation

template<typename Impl, typename ImplPtr = Impl*>
std::map< P2, SchedBase::ReqBase * > Scheduler< P1, P2 >::s_accReqs [static]
 

Definition at line 883 of file scheduler.h.

Referenced by Scheduler< Impl, ImplPtr >::AcceptReq::AcceptReq(), Scheduler< Impl, ImplPtr >::invalidateReqs(), and Scheduler< Impl, ImplPtr >::AcceptReq::~AcceptReq().

template<typename Impl, typename ImplPtr = Impl*>
std::map< P2, SchedBase::ReqBase * > Scheduler< P1, P2 >::s_connReqs [static]
 

Definition at line 886 of file scheduler.h.

Referenced by Scheduler< Impl, ImplPtr >::ConnReq::ConnReq(), Scheduler< Impl, ImplPtr >::invalidateReqs(), and Scheduler< Impl, ImplPtr >::ConnReq::~ConnReq().

template<typename Impl, typename ImplPtr = Impl*>
std::map< P2, SchedBase::ReqBase * > Scheduler< P1, P2 >::s_downReqs [static]
 

Definition at line 880 of file scheduler.h.

Referenced by Scheduler< Impl, ImplPtr >::DownloadReq::DownloadReq(), Scheduler< Impl, ImplPtr >::invalidateReqs(), and Scheduler< Impl, ImplPtr >::DownloadReq::~DownloadReq().

template<typename Impl, typename ImplPtr = Impl*>
std::set< typename Scheduler< P1, P2 >::SSocketWrapper > Scheduler< P1, P2 >::s_sockets [static]
 

set of all scheduled sockets

Definition at line 872 of file scheduler.h.

Referenced by Scheduler< Impl, ImplPtr >::accept(), Scheduler< Impl, ImplPtr >::addSocket(), Scheduler< Impl, ImplPtr >::connect(), Scheduler< Impl, ImplPtr >::delSocket(), Scheduler< Impl, ImplPtr >::disconnect(), Scheduler< Impl, ImplPtr >::getData(), Scheduler< Impl, ImplPtr >::read(), and Scheduler< Impl, ImplPtr >::write().

template<typename Impl, typename ImplPtr = Impl*>
std::set< P2 > Scheduler< P1, P2 >::s_toDisconnect [static]
 

Sockets to be disconnected as soon as all pending upstream data has been sent out.

Definition at line 874 of file scheduler.h.

Referenced by Scheduler< Impl, ImplPtr >::disconnect().

template<typename Impl, typename ImplPtr = Impl*>
std::map< P2, SchedBase::ReqBase * > Scheduler< P1, P2 >::s_upReqs [static]
 

Definition at line 877 of file scheduler.h.

Referenced by Scheduler< Impl, ImplPtr >::invalidateReqs(), Scheduler< Impl, ImplPtr >::UploadReq::UploadReq(), Scheduler< Impl, ImplPtr >::write(), and Scheduler< Impl, ImplPtr >::UploadReq::~UploadReq().


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