![]() |
Vault
4.1
|
VMessageOutputThread understands how to maintain and monitor a message output queue, waking up when a new message has been posted to the queue, and writing it to the output stream. More...
#include <vmessageoutputthread.h>
Public Member Functions | |
VMessageOutputThread (const VString &threadBaseName, VSocket *socket, VListenerThread *ownerThread, VServer *server, VClientSessionPtr session, VMessageInputThread *dependentInputThread, int maxQueueSize=0, Vs64 maxQueueDataSize=0, const VDuration &maxQueueGracePeriod=VDuration::ZERO()) | |
Constructs the output thread. | |
virtual | ~VMessageOutputThread () |
Virtual destructor. | |
virtual void | run () |
Handles requests and responses for the socket. | |
virtual void | stop () |
Stops the thread; for VMessageOutputThread this calls inherited and then wakes up the message queue in case it is blocked. | |
void | attachSession (VClientSessionPtr session) |
Attaches the thread to its session, so that message handlers on this thread can reference session state. | |
bool | postOutputMessage (VMessagePtr message, bool respectQueueLimits=true) |
Posts a message to the output thread's output queue; the output thread will send the message in order of posting. | |
void | releaseAllQueuedMessages () |
Releases/destroys all queued messages. | |
int | getOutputQueueSize () const |
Returns the number of messages that are sitting on the output queue that have yet to be sent. | |
bool | isOutputQueueOverLimit (int ¤tQueueSize, Vs64 ¤tQueueDataSize) const |
Returns true if the output queue has exceeded its limits, and returns in the input parameters the current queue size information. |
VMessageOutputThread understands how to maintain and monitor a message output queue, waking up when a new message has been posted to the queue, and writing it to the output stream.
Definition at line 31 of file vmessageoutputthread.h.
VMessageOutputThread::VMessageOutputThread | ( | const VString & | threadBaseName, |
VSocket * | socket, | ||
VListenerThread * | ownerThread, | ||
VServer * | server, | ||
VClientSessionPtr | session, | ||
VMessageInputThread * | dependentInputThread, | ||
int | maxQueueSize = 0 , |
||
Vs64 | maxQueueDataSize = 0 , |
||
const VDuration & | maxQueueGracePeriod = VDuration::ZERO() |
||
) |
Constructs the output thread.
The supplied message queue, server, and session are still owned by the caller; this class does not delete them in its destructor.
threadBaseName | a distinguishing base name for the thread, useful for debugging purposes; the thread name will be composed of this and the socket's IP address and port |
socket | the socket this thread is managing |
ownerThread | the thread that created this one |
server | the server object |
session | the session object |
dependentInputThread | if non-null, the VMessageInputThread that is dependent upon this output thread, and which we must notify before we return from our run() method |
maxQueueSize | if non-zero, the max number of queued messages allowed; if a call to postOutputMessage() occurs when the limit has been exceeded, the call will just close the socket and return |
maxQueueDataSize | if non-zero, the max data size of queued messages allowed; if a call to postOutputMessage() occurs when the limit has been exceeded, the call will just close the socket and return |
maxQueueGracePeriod | how long the maxQueueSize and maxQueueDataSize limits may be exceeded before the socket is closed upon next posted message |
Definition at line 18 of file vmessageoutputthread.cpp.
References NULL, and VMessageInputThread::setHasOutputThread().
void VMessageOutputThread::attachSession | ( | VClientSessionPtr | session | ) |
Attaches the thread to its session, so that message handlers on this thread can reference session state.
session | the session on whose behalf we are running |
Definition at line 98 of file vmessageoutputthread.cpp.
bool VMessageOutputThread::postOutputMessage | ( | VMessagePtr | message, |
bool | respectQueueLimits = true |
||
) |
Posts a message to the output thread's output queue; the output thread will send the message in order of posting.
If the output thread is blocked when the message is posted, the posting causes the output thread to wake up. If the mMaxQueueSize or mMaxQueueDataSize has already been exceeded, this method causes the socket to be closed and does not post the message.
message | the message to post (and send) |
respectQueueLimits | normally true, can be set false to bypass the checks on the queue limits |
Definition at line 102 of file vmessageoutputthread.cpp.
References VString::chars(), VDuration::getDurationSeconds(), isOutputQueueOverLimit(), VThread::isRunning(), VDuration::MINUTE(), VThread::mLoggerName, VThread::mName, VMessageQueue::postMessage(), stop(), and VDuration::ZERO().
void VMessageOutputThread::releaseAllQueuedMessages | ( | ) |
Releases/destroys all queued messages.
This is called when the session shuts down. That is, any messages sitting on the output queue at the time the session shuts down are not sent.
Definition at line 159 of file vmessageoutputthread.cpp.
References VMessageQueue::releaseAllMessages().
bool VMessageOutputThread::isOutputQueueOverLimit | ( | int & | currentQueueSize, |
Vs64 & | currentQueueDataSize | ||
) | const |
Returns true if the output queue has exceeded its limits, and returns in the input parameters the current queue size information.
currentQueueSize | regardless of result, the current queue size is returned here |
currentQueueDataSize | regardless of result, the current queue data size is returned here |
Definition at line 167 of file vmessageoutputthread.cpp.
References VMessageQueue::getQueueDataSize(), and VMessageQueue::getQueueSize().