Qore Logger Module Reference 0.6
Loading...
Searching...
No Matches
Logger::LoggerAppenderQueueThreadPool Class Reference

Handles the processing for asynchronous appender events in multiple threads. More...

#include <Logger.qm.dox.h>

Inheritance diagram for Logger::LoggerAppenderQueueThreadPool:
[legend]

Public Member Methods

 constructor (ThreadPool tp, int max_threads=-1)
 Creates the object. More...
 
ThreadPool getThreadPool ()
 Returns the assigned ThreadPool.
 
 process (timeout ms=0)
 Processes queue events. More...
 
int size ()
 Gets number of pending events.
 
- Public Member Methods inherited from Logger::LoggerAppenderQueue
 process (timeout ms=0)
 Processes queued events. More...
 
bool push (LoggerAppender appender, int type, auto params)
 Adds appender event. More...
 
int size ()
 Returns the current number of events waiting in queue.
 

Private:Internal Member Methods

Queue finishedEvents ()
 queue of processed events in worker threads
 
Sequence lastId (0)
 internal unique counter
 
Mutex lock ()
 to protect process()
 
Counter runningCounter (0)
 number of running worker threads
 
 worker (string id, LoggerAppender appender, list< auto > events)
 Implements worker thread code. More...
 

Private:Internal Attributes

int maxThreads
 max.number of worker threads
 
hash< auto > pendingEvents
 events removed from queue but not passed to worker thread
 
hash< auto > processingEvents
 events paseed to worker thread
 
ThreadPool threadPool
 worker thread pool
 

Additional Inherited Members

- Private Member Methods inherited from Logger::LoggerAppenderQueue
*hash< auto > getEvent (timeout ms)
 Returns the next event from queue or NOTHING if there is no event available within the timeout period. More...
 

Detailed Description

Handles the processing for asynchronous appender events in multiple threads.

Async events are removed from the event queue in a single thread which balances processing in multiple worker threads via a ThreadPool. This class groups events by appender so that events related to a particular appender are always processed serially in the same thread. It is compatible with Qore's Qore::OutputStream implementation where all data submitted to the output stream must be submitted from the same thread.

Member Function Documentation

◆ constructor()

Logger::LoggerAppenderQueueThreadPool::constructor ( ThreadPool  tp,
int  max_threads = -1 
)

Creates the object.

Parameters
tpworker ThreadPool where loggging events are submitted
max_threadsmax.number of worker threads, default value is -1, i.e. unlimited

◆ process()

Logger::LoggerAppenderQueueThreadPool::process ( timeout  ms = 0)

Processes queue events.

Group logging events by appender and submit them to a worker thread to be processed in a thread pool so the particular thread will handle corresponding appender instance.

Parameters
msa timeout value to wait for data to become available on the queue; integers are interpreted as milliseconds; relative date/time values are interpreted literally with a maximum resolution of milliseconds. A value that converts to integer 0 causes the call to time out immediately if the call would otherwise block. If a positive timeout argument is passed, and no data is available in the timeout period then waits up to timeout value, If a negative timeout value is passed as the argument, then the call blocks until data is available on the queue. Default value is 0.

◆ worker()

Logger::LoggerAppenderQueueThreadPool::worker ( string  id,
LoggerAppender  appender,
list< auto >  events 
)
private:internal

Implements worker thread code.

Parameters
idunique identifier generated by internal Sequence
appenderLoggerAppender instance
eventslist of events