Kea: d2_queue_mgr.h Source File

| Kea 3.2.0-git

d2_queue_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2013-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef D2_QUEUE_MGR_H
8#define D2_QUEUE_MGR_H
9
11
12#include <asiolink/io_service.h>
13#include <dhcp_ddns/ncr_io.h>
14#include <dhcp_ddns/ncr_msg.h>
15#include <exceptions/exceptions.h>
16
17#include <deque>
18
19#include <boost/noncopyable.hpp>
20
21namespace isc {
22namespace d2 {
23
26 typedef std::deque<dhcp_ddns::NameChangeRequestPtr> RequestQueue;
27
29 class D2QueueMgrError : public isc::Exception {
30public:
31 D2QueueMgrError(const char* file, size_t line, const char* what) :
32 isc::Exception(file, line, what) { }
33};
34
38 class D2QueueMgrReceiveError : public isc::Exception {
39public:
40 D2QueueMgrReceiveError(const char* file, size_t line, const char* what) :
41 isc::Exception(file, line, what) { }
42};
43
46 class D2QueueMgrQueueFull : public isc::Exception {
47public:
48 D2QueueMgrQueueFull(const char* file, size_t line, const char* what) :
49 isc::Exception(file, line, what) { }
50};
51
53 class D2QueueMgrQueueEmpty : public isc::Exception {
54public:
55 D2QueueMgrQueueEmpty(const char* file, size_t line, const char* what) :
56 isc::Exception(file, line, what) { }
57};
58
60 class D2QueueMgrInvalidIndex : public isc::Exception {
61public:
62 D2QueueMgrInvalidIndex(const char* file, size_t line, const char* what) :
63 isc::Exception(file, line, what) { }
64};
65
130 class D2QueueMgr : public dhcp_ddns::NameChangeListener::RequestReceiveHandler,
131 boost::noncopyable {
132public:
136 static const size_t MAX_QUEUE_DEFAULT = 1024;
137
139 enum State : uint16_t {
140 NOT_INITTED = 0,
141 INITTED = 1,
142 RUNNING = 2,
143 STOPPING = 3,
144 STOPPED_QUEUE_FULL = 4,
145 STOPPED_RECV_ERROR = 5,
146 STOPPED = 6,
147 };
148
154 static std::string const& stateToText(State const& state) {
155 static std::vector<std::string> const text_vector {
156 "NOT_INITTED",
157 "INITTED",
158 "RUNNING",
159 "STOPPING",
160 "STOPPED_QUEUE_FULL",
161 "STOPPED_RECV_ERROR",
162 "STOPPED",
163 };
164 static std::string const unknown("UNKNOWN");
165 return (state < text_vector.size() ? text_vector[state] : unknown);
166 }
167
180 D2QueueMgr(asiolink::IOServicePtr& io_service,
181 const size_t max_queue_size = MAX_QUEUE_DEFAULT);
182
184 virtual ~D2QueueMgr();
185
197 void initUDPListener(const isc::asiolink::IOAddress& ip_address,
198 const uint32_t port,
199 const dhcp_ddns::NameChangeFormat format,
200 const bool reuse_address = false);
201
209 void startListening();
210
238 virtual void operator()(const dhcp_ddns::NameChangeListener::Result result,
239 dhcp_ddns::NameChangeRequestPtr& ncr);
240
253 void stopListening(const State target_stop_state = STOPPED);
254
262 void removeListener();
263
265 size_t getQueueSize() const {
266 return (ncr_queue_.size());
267 };
268
270 size_t getMaxQueueSize() const {
271 return (max_queue_size_);
272 }
273
281 void setMaxQueueSize(const size_t max_queue_size);
282
284 State getMgrState() const {
285 return (mgr_state_);
286 }
287
297 const dhcp_ddns::NameChangeRequestPtr& peek() const;
298
309 const dhcp_ddns::NameChangeRequestPtr& peekAt(const size_t index) const;
310
318 void dequeueAt(const size_t index);
319
323 void dequeue();
324
328 void enqueue(dhcp_ddns::NameChangeRequestPtr& ncr);
329
331 void clearQueue();
332
333 private:
338 void updateStopState();
339
341 asiolink::IOServicePtr io_service_;
342
344 size_t max_queue_size_;
345
347 RequestQueue ncr_queue_;
348
350 boost::shared_ptr<dhcp_ddns::NameChangeListener> listener_;
351
353 State mgr_state_;
354
356 State target_stop_state_;
357};
358
360 typedef boost::shared_ptr<D2QueueMgr> D2QueueMgrPtr;
361
362} // namespace isc::d2
363} // namespace isc
364
365#endif
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition exceptions/exceptions.h:23
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::d2::D2QueueMgrError::D2QueueMgrError
D2QueueMgrError(const char *file, size_t line, const char *what)
Definition d2_queue_mgr.h:31
isc::d2::D2QueueMgrInvalidIndex::D2QueueMgrInvalidIndex
D2QueueMgrInvalidIndex(const char *file, size_t line, const char *what)
Definition d2_queue_mgr.h:62
isc::d2::D2QueueMgrQueueEmpty::D2QueueMgrQueueEmpty
D2QueueMgrQueueEmpty(const char *file, size_t line, const char *what)
Definition d2_queue_mgr.h:55
isc::d2::D2QueueMgrQueueFull::D2QueueMgrQueueFull
D2QueueMgrQueueFull(const char *file, size_t line, const char *what)
Definition d2_queue_mgr.h:48
isc::d2::D2QueueMgrReceiveError::D2QueueMgrReceiveError
D2QueueMgrReceiveError(const char *file, size_t line, const char *what)
Definition d2_queue_mgr.h:40
isc::d2::D2QueueMgr::peek
const dhcp_ddns::NameChangeRequestPtr & peek() const
Returns the entry at the front of the queue.
Definition d2_queue_mgr.cc:197
isc::d2::D2QueueMgr::D2QueueMgr
D2QueueMgr(asiolink::IOServicePtr &io_service, const size_t max_queue_size=MAX_QUEUE_DEFAULT)
Constructor.
Definition d2_queue_mgr.cc:21
isc::d2::D2QueueMgr::State
State
Defines the list of possible states for D2QueueMgr.
Definition d2_queue_mgr.h:139
isc::d2::D2QueueMgr::STOPPED_QUEUE_FULL
@ STOPPED_QUEUE_FULL
Definition d2_queue_mgr.h:144
isc::d2::D2QueueMgr::NOT_INITTED
@ NOT_INITTED
Definition d2_queue_mgr.h:140
isc::d2::D2QueueMgr::STOPPED_RECV_ERROR
@ STOPPED_RECV_ERROR
Definition d2_queue_mgr.h:145
isc::d2::D2QueueMgr::RUNNING
@ RUNNING
Definition d2_queue_mgr.h:142
isc::d2::D2QueueMgr::STOPPED
@ STOPPED
Definition d2_queue_mgr.h:146
isc::d2::D2QueueMgr::STOPPING
@ STOPPING
Definition d2_queue_mgr.h:143
isc::d2::D2QueueMgr::INITTED
@ INITTED
Definition d2_queue_mgr.h:141
isc::d2::D2QueueMgr::~D2QueueMgr
virtual ~D2QueueMgr()
Destructor.
Definition d2_queue_mgr.cc:32
isc::d2::D2QueueMgr::getMaxQueueSize
size_t getMaxQueueSize() const
Returns the maximum number of entries allowed in the queue.
Definition d2_queue_mgr.h:270
isc::d2::D2QueueMgr::getMgrState
State getMgrState() const
Returns the current state.
Definition d2_queue_mgr.h:284
isc::d2::D2QueueMgr::MAX_QUEUE_DEFAULT
static const size_t MAX_QUEUE_DEFAULT
Maximum number of entries allowed in the request queue.
Definition d2_queue_mgr.h:136
isc::d2::D2QueueMgr::dequeue
void dequeue()
Removes the entry at the front of the queue.
Definition d2_queue_mgr.cc:230
isc::d2::D2QueueMgr::peekAt
const dhcp_ddns::NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
Definition d2_queue_mgr.cc:207
isc::d2::D2QueueMgr::stateToText
static std::string const & stateToText(State const &state)
Convert enum to string.
Definition d2_queue_mgr.h:154
isc::d2::D2QueueMgr::removeListener
void removeListener()
Deletes the current listener.
Definition d2_queue_mgr.cc:185
isc::d2::D2QueueMgr::enqueue
void enqueue(dhcp_ddns::NameChangeRequestPtr &ncr)
Adds a request to the end of the queue.
Definition d2_queue_mgr.cc:240
isc::d2::D2QueueMgr::startListening
void startListening()
Starts actively listening for requests.
Definition d2_queue_mgr.cc:121
isc::d2::D2QueueMgr::setMaxQueueSize
void setMaxQueueSize(const size_t max_queue_size)
Sets the maximum number of entries allowed in the queue.
Definition d2_queue_mgr.cc:250
isc::d2::D2QueueMgr::getQueueSize
size_t getQueueSize() const
Returns the number of entries in the queue.
Definition d2_queue_mgr.h:265
isc::d2::D2QueueMgr::operator()
virtual void operator()(const dhcp_ddns::NameChangeListener::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Function operator implementing the NCR receive callback.
Definition d2_queue_mgr.cc:36
isc::d2::D2QueueMgr::clearQueue
void clearQueue()
Removes all entries from the queue.
Definition d2_queue_mgr.cc:245
isc::d2::D2QueueMgr::initUDPListener
void initUDPListener(const isc::asiolink::IOAddress &ip_address, const uint32_t port, const dhcp_ddns::NameChangeFormat format, const bool reuse_address=false)
Initializes the listener as a UDP listener.
Definition d2_queue_mgr.cc:103
isc::d2::D2QueueMgr::dequeueAt
void dequeueAt(const size_t index)
Removes the entry at a given position in the queue.
Definition d2_queue_mgr.cc:218
isc::d2::D2QueueMgr::stopListening
void stopListening(const State target_stop_state=STOPPED)
Stops listening for requests.
Definition d2_queue_mgr.cc:149
isc::dhcp_ddns::NameChangeListener::RequestReceiveHandler
Abstract class for defining application layer receive callbacks.
Definition ncr_io.h:183
isc::dhcp_ddns::NameChangeListener::Result
Result
Defines the outcome of an asynchronous NCR receive.
Definition ncr_io.h:171
isc::util::State
Defines a State within the State Model.
Definition state_model.h:61
exceptions.h
io_service.h
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:35
isc::d2
Definition check_exists_add.cc:19
isc::d2::RequestQueue
std::deque< dhcp_ddns::NameChangeRequestPtr > RequestQueue
Defines a queue of requests.
Definition d2_queue_mgr.h:26
isc::d2::D2QueueMgrPtr
boost::shared_ptr< D2QueueMgr > D2QueueMgrPtr
Defines a pointer for manager instances.
Definition d2_queue_mgr.h:360
isc::dhcp_ddns::NameChangeFormat
NameChangeFormat
Defines the list of data wire formats supported.
Definition ncr_msg.h:59
isc::dhcp_ddns::NameChangeRequestPtr
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:241
isc::util::file
Definition filesystem.cc:29
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
ncr_io.h
This file defines abstract classes for exchanging NameChangeRequests.
ncr_msg.h
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...