Kea 3.3.3
d2_queue_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 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>
16
17#include <cstdint>
18#include <deque>
19
20#include <boost/noncopyable.hpp>
21
22namespace isc {
23namespace d2 {
24
27typedef std::deque<dhcp_ddns::NameChangeRequestPtr> RequestQueue;
28
31public:
32 D2QueueMgrError(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) { }
34};
35
40public:
41 D2QueueMgrReceiveError(const char* file, size_t line, const char* what) :
42 isc::Exception(file, line, what) { }
43};
44
48public:
49 D2QueueMgrQueueFull(const char* file, size_t line, const char* what) :
50 isc::Exception(file, line, what) { }
51};
52
55public:
56 D2QueueMgrQueueEmpty(const char* file, size_t line, const char* what) :
57 isc::Exception(file, line, what) { }
58};
59
62public:
63 D2QueueMgrInvalidIndex(const char* file, size_t line, const char* what) :
64 isc::Exception(file, line, what) { }
65};
66
132 boost::noncopyable {
133public:
137 static const size_t MAX_QUEUE_DEFAULT = 1024;
138
149
155 static std::string const& stateToText(State const& state) {
156 static std::vector<std::string> const text_vector {
157 "NOT_INITTED",
158 "INITTED",
159 "RUNNING",
160 "STOPPING",
161 "STOPPED_QUEUE_FULL",
162 "STOPPED_RECV_ERROR",
163 "STOPPED",
164 };
165 static std::string const unknown("UNKNOWN");
166 return (state < text_vector.size() ? text_vector[state] : unknown);
167 }
168
182 const size_t max_queue_size = MAX_QUEUE_DEFAULT);
183
185 virtual ~D2QueueMgr();
186
198 void initUDPListener(const isc::asiolink::IOAddress& ip_address,
199 const uint32_t port,
200 const dhcp_ddns::NameChangeFormat format,
201 const bool reuse_address = false);
202
210 void startListening();
211
239 virtual void operator()(const dhcp_ddns::NameChangeListener::Result result,
241
254 void stopListening(const State target_stop_state = STOPPED);
255
263 void removeListener();
264
266 size_t getQueueSize() const {
267 return (ncr_queue_.size());
268 };
269
271 size_t getMaxQueueSize() const {
272 return (max_queue_size_);
273 }
274
282 void setMaxQueueSize(const size_t max_queue_size);
283
286 return (mgr_state_);
287 }
288
299
310 const dhcp_ddns::NameChangeRequestPtr& peekAt(const size_t index) const;
311
319 void dequeueAt(const size_t index);
320
324 void dequeue();
325
330
332 void clearQueue();
333
334 private:
339 void updateStopState();
340
342 asiolink::IOServicePtr io_service_;
343
345 size_t max_queue_size_;
346
348 RequestQueue ncr_queue_;
349
351 boost::shared_ptr<dhcp_ddns::NameChangeListener> listener_;
352
354 State mgr_state_;
355
357 State target_stop_state_;
358};
359
361typedef boost::shared_ptr<D2QueueMgr> D2QueueMgrPtr;
362
363} // namespace isc::d2
364} // namespace isc
365
366#endif
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
D2QueueMgrError(const char *file, size_t line, const char *what)
D2QueueMgrInvalidIndex(const char *file, size_t line, const char *what)
D2QueueMgrQueueEmpty(const char *file, size_t line, const char *what)
D2QueueMgrQueueFull(const char *file, size_t line, const char *what)
D2QueueMgrReceiveError(const char *file, size_t line, const char *what)
const dhcp_ddns::NameChangeRequestPtr & peek() const
Returns the entry at the front of the queue.
D2QueueMgr(asiolink::IOServicePtr &io_service, const size_t max_queue_size=MAX_QUEUE_DEFAULT)
Constructor.
State
Defines the list of possible states for D2QueueMgr.
virtual ~D2QueueMgr()
Destructor.
size_t getMaxQueueSize() const
Returns the maximum number of entries allowed in the queue.
State getMgrState() const
Returns the current state.
static const size_t MAX_QUEUE_DEFAULT
Maximum number of entries allowed in the request queue.
void dequeue()
Removes the entry at the front of the queue.
const dhcp_ddns::NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
static std::string const & stateToText(State const &state)
Convert enum to string.
void removeListener()
Deletes the current listener.
void enqueue(dhcp_ddns::NameChangeRequestPtr &ncr)
Adds a request to the end of the queue.
void startListening()
Starts actively listening for requests.
void setMaxQueueSize(const size_t max_queue_size)
Sets the maximum number of entries allowed in the queue.
size_t getQueueSize() const
Returns the number of entries in the queue.
virtual void operator()(const dhcp_ddns::NameChangeListener::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Function operator implementing the NCR receive callback.
void clearQueue()
Removes all entries from the queue.
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.
void dequeueAt(const size_t index)
Removes the entry at a given position in the queue.
void stopListening(const State target_stop_state=STOPPED)
Stops listening for requests.
Abstract class for defining application layer receive callbacks.
Definition ncr_io.h:184
Result
Defines the outcome of an asynchronous NCR receive.
Definition ncr_io.h:172
Defines a State within the State Model.
Definition state_model.h:64
std::deque< dhcp_ddns::NameChangeRequestPtr > RequestQueue
Defines a queue of requests.
boost::shared_ptr< D2QueueMgr > D2QueueMgrPtr
Defines a pointer for manager instances.
NameChangeFormat
Defines the list of data wire formats supported.
Definition ncr_msg.h:63
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:245
Defines the logger used by the top-level component of kea-lfc.
This file defines abstract classes for exchanging NameChangeRequests.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...