1//
2// AsyncChannel.h
3//
4// Library: Foundation
5// Package: Logging
6// Module: AsyncChannel
7//
8// Definition of the AsyncChannel class.
9//
10// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_AsyncChannel_INCLUDED
18#define Foundation_AsyncChannel_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/Channel.h"
23#include "Poco/Thread.h"
24#include "Poco/Mutex.h"
25#include "Poco/Runnable.h"
26#include "Poco/NotificationQueue.h"
27
28
29namespace Poco {
30
31
32class Foundation_API AsyncChannel: public Channel, public Runnable
33 /// A channel uses a separate thread for logging.
34 ///
35 /// Using this channel can help to improve the performance of
36 /// applications that produce huge amounts of log messages or
37 /// that write log messages to multiple channels simultaneously.
38 ///
39 /// All log messages are put into a queue and this queue is
40 /// then processed by a separate thread.
41{
42public:
43 AsyncChannel(Channel* pChannel = 0, Thread::Priority prio = Thread::PRIO_NORMAL);
44 /// Creates the AsyncChannel and connects it to
45 /// the given channel.
46
47 void setChannel(Channel* pChannel);
48 /// Connects the AsyncChannel to the given target channel.
49 /// All messages will be forwarded to this channel.
50
51 Channel* getChannel() const;
52 /// Returns the target channel.
53
54 void open();
55 /// Opens the channel and creates the
56 /// background logging thread.
57
58 void close();
59 /// Closes the channel and stops the background
60 /// logging thread.
61
62 void log(const Message& msg);
63 /// Queues the message for processing by the
64 /// background thread.
65
66 void setProperty(const std::string& name, const std::string& value);
67 /// Sets or changes a configuration property.
68 ///
69 /// The "channel" property allows setting the target
70 /// channel via the LoggingRegistry.
71 /// The "channel" property is set-only.
72 ///
73 /// The "priority" property allows setting the thread
74 /// priority. The following values are supported:
75 /// * lowest
76 /// * low
77 /// * normal (default)
78 /// * high
79 /// * highest
80 ///
81 /// The "priority" property is set-only.
82
83protected:
84 ~AsyncChannel();
85 void run();
86 void setPriority(const std::string& value);
87
88private:
89 Channel* _pChannel;
90 Thread _thread;
91 FastMutex _threadMutex;
92 FastMutex _channelMutex;
93 NotificationQueue _queue;
94};
95
96
97} // namespace Poco
98
99
100#endif // Foundation_AsyncChannel_INCLUDED
101