Vault
4.1
|
VMessageInputThread understands how to perform blocking input reads of VMessage objects (finding and calling a VMessageHandler) from its i/o stream. More...
#include <vmessageinputthread.h>
Public Member Functions | |
VMessageInputThread (const VString &threadBaseName, VSocket *socket, VListenerThread *ownerThread, VServer *server, const VMessageFactory *messageFactory) | |
Constructs the socket thread with the specified socket, owner thread, and server. | |
virtual | ~VMessageInputThread () |
Virtual destructor. | |
virtual void | run () |
Handles requests for the socket; returns only when the thread has been stopped, the socket is closed, or an exception is thrown that is not properly caught. | |
void | attachSession (VClientSessionPtr session) |
Attaches the thread to its session, so that message handlers on this thread can reference session state. | |
void | setHasOutputThread (bool hasOutputThread) |
Sets or clears the mHasOutputThread that controls whether this input thread must wait before returning from run(). | |
Protected Member Functions | |
virtual void | _processNextRequest () |
Pulls the next message from the socket (blocking until there is data), and then calls dispatchMessage() to handle the message. | |
virtual void | _dispatchMessage (VMessagePtr message) |
Handles the message by finding or creating a handler and calling it to process the message, returning when it's OK to read the next message. | |
virtual void | _handleNoMessageHandler (VMessagePtr) |
This method is called by _dispatchMessage if it cannot find the handler for the message being handled. | |
virtual void | _beforeProcessMessage (VMessageHandler *, VMessagePtr) |
This method is intended for use by loopback testing, where the test code can see (and potentially preprocess) a message that it sent that is about to be handled in the normal fashion. | |
virtual void | _callProcessMessage (VMessageHandler *handler) |
This method is where we actually call the message handler to process the message it was constructed with. | |
virtual void | _afterProcessMessage (VMessageHandler *) |
This method is intended for use by loopback testing, where the test code can see (and potentially post-process) a message that it sent that has just been handled in the normal fashion. | |
Protected Attributes | |
VSocketStream | mSocketStream |
The underlying raw stream from which data is read. | |
VBinaryIOStream | mInputStream |
The formatted stream from which data is directly read. | |
bool | mConnected |
True if the client has completed the connection sequence. | |
VClientSessionPtr | mSession |
The session object we are associated with. | |
VServer * | mServer |
The server object that owns us. | |
const VMessageFactory * | mMessageFactory |
Factory for instantiating new messages to read from input stream. | |
volatile bool | mHasOutputThread |
True if we are dependent on an output thread completion before returning from run(). (see run() code) |
VMessageInputThread understands how to perform blocking input reads of VMessage objects (finding and calling a VMessageHandler) from its i/o stream.
You can also write to its i/o stream, but if you are doing asynchronous i/o you'll instead post messages to a VMessageOutputThread.
Definition at line 31 of file vmessageinputthread.h.
VMessageInputThread::VMessageInputThread | ( | const VString & | threadBaseName, |
VSocket * | socket, | ||
VListenerThread * | ownerThread, | ||
VServer * | server, | ||
const VMessageFactory * | messageFactory | ||
) |
Constructs the socket thread with the specified socket, owner thread, and server.
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 we're running for |
messageFactory | a factory that instantiates messages suitable for this thread's input (The caller owns the factory.) |
Definition at line 19 of file vmessageinputthread.cpp.
void VMessageInputThread::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 106 of file vmessageinputthread.cpp.
References mSession.
void VMessageInputThread::setHasOutputThread | ( | bool | hasOutputThread | ) | [inline] |
Sets or clears the mHasOutputThread that controls whether this input thread must wait before returning from run().
This is used when separate in/out threads are handling i/o and the destruction sequence requires the input thread to wait for the output thread to die before dying itself.
Definition at line 72 of file vmessageinputthread.h.
References mHasOutputThread.
void VMessageInputThread::_dispatchMessage | ( | VMessagePtr | message | ) | [protected, virtual] |
Handles the message by finding or creating a handler and calling it to process the message, returning when it's OK to read the next message.
message | the message to handle |
Definition at line 135 of file vmessageinputthread.cpp.
References _afterProcessMessage(), _beforeProcessMessage(), _callProcessMessage(), _handleNoMessageHandler(), VString::chars(), VMessageHandler::get(), VException::getError(), VThread::mLoggerName, VThread::mName, mServer, mSession, NULL, and VException::what().
virtual void VMessageInputThread::_handleNoMessageHandler | ( | VMessagePtr | ) | [inline, protected, virtual] |
This method is called by _dispatchMessage if it cannot find the handler for the message being handled.
How to handle this is protocol-specific, but a subclass could send an error response back to the sender if the protocol allows that. The implementation must NOT release the message, and the message WILL be released by _dispatchMessage() upon return.
Reimplemented in VBentoMessageInputThread.
Definition at line 94 of file vmessageinputthread.h.
void VMessageInputThread::_callProcessMessage | ( | VMessageHandler * | handler | ) | [protected, virtual] |
This method is where we actually call the message handler to process the message it was constructed with.
A subclass might override this to wrap the call to super in a try/catch block if it wants to take action other than logging in response to an exception.
Reimplemented in VBentoMessageInputThread.
Definition at line 164 of file vmessageinputthread.cpp.
References VMessageHandler::logProcessMessageEnd(), VMessageHandler::logProcessMessageStart(), and VMessageHandler::processMessage().