18#include <boost/pointer_cast.hpp>
30 const uint16_t thread_pool_size ,
32 : address_(address), port_(port), thread_io_service_(), http_listener_(),
33 thread_pool_size_(thread_pool_size), thread_pool_(),
34 tls_context_(context) {
46 " when multi-threading is disabled");
56 thread_io_service_.reset(
new IOService());
65 http_listener_.reset(
new HttpListener(thread_io_service_, address_,
66 port_, tls_context_, rcf,
72 http_listener_->start();
79 .arg(thread_pool_size_)
82 .arg(tls_context_ ?
"true" :
"false");
83 }
catch (
const std::exception& ex) {
91 http_listener_->stop();
94 if (thread_io_service_) {
95 thread_io_service_->stopAndPoll();
96 thread_io_service_->stop();
100 thread_pool_.reset();
103 http_listener_.reset();
106 thread_io_service_.reset();
115 thread_pool_->checkPausePermissions();
122 thread_pool_->pause();
136 if (!thread_io_service_) {
145 thread_pool_->stop();
148 http_listener_->stop();
150 thread_io_service_->stopAndPoll();
151 thread_io_service_->stop();
154 thread_pool_.reset();
157 http_listener_.reset();
160 thread_io_service_.reset();
170 return (thread_pool_->isRunning());
179 return (thread_pool_->isStopped());
188 return (thread_pool_->isPaused());
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
The IOService class is a wrapper for the ASIO io_service class.
Implements a pausable pool of IOService driven threads.
void checkPermissions()
Check if the current thread can perform thread pool state transition.
void start()
Starts running the listener's thread pool.
virtual ~CmdHttpListener()
Destructor.
bool isPaused()
Indicates if the thread pool is paused.
CmdHttpListener(const asiolink::IOAddress &address, const uint16_t port, const uint16_t thread_pool_size=1, asiolink::TlsContextPtr context=asiolink::TlsContextPtr())
Constructor.
void pause()
Pauses the listener's thread pool.
void resume()
Resumes running the listener's thread pool.
bool isRunning()
Indicates if the thread pool is running.
void stop()
Stops the listener's thread pool.
bool isStopped()
Indicates if the thread pool is stopped.
HTTP response creator factory for an API listener.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
constexpr long TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT
Timeout for the idle connection to be closed.
const isc::log::MessageID COMMAND_HTTP_LISTENER_STARTED
const isc::log::MessageID COMMAND_HTTP_LISTENER_STOPPED
const isc::log::MessageID COMMAND_HTTP_LISTENER_STOPPING
isc::log::Logger command_logger("commands")
Command processing Logger.
constexpr long TIMEOUT_AGENT_RECEIVE_COMMAND
Timeout for the Control Agent to receive command over the RESTful interface.
boost::shared_ptr< HttpResponseCreatorFactory > HttpResponseCreatorFactoryPtr
Pointer to the HttpResponseCreatorFactory.
Defines the logger used by the top-level component of kea-lfc.
HTTP request timeout value.