Vault  4.1
Public Member Functions
VMessageOutputThread Class Reference

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>

Inheritance diagram for VMessageOutputThread:
VSocketThread VThread

List of all members.

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 &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.

Detailed Description

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.


Constructor & Destructor Documentation

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.

Parameters:
threadBaseNamea 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
socketthe socket this thread is managing
ownerThreadthe thread that created this one
serverthe server object
sessionthe session object
dependentInputThreadif non-null, the VMessageInputThread that is dependent upon this output thread, and which we must notify before we return from our run() method
maxQueueSizeif 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
maxQueueDataSizeif 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
maxQueueGracePeriodhow 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().


Member Function Documentation

void VMessageOutputThread::attachSession ( VClientSessionPtr  session)

Attaches the thread to its session, so that message handlers on this thread can reference session state.

Parameters:
sessionthe 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.

Parameters:
messagethe message to post (and send)
respectQueueLimitsnormally true, can be set false to bypass the checks on the queue limits
Returns:
true if the message was successfully posted; false means it was not, so caller needs to free the message

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.

Parameters:
currentQueueSizeregardless of result, the current queue size is returned here
currentQueueDataSizeregardless of result, the current queue data size is returned here
Returns:
true if the queue is currently over the queue size limits

Definition at line 167 of file vmessageoutputthread.cpp.

References VMessageQueue::getQueueDataSize(), and VMessageQueue::getQueueSize().


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.