Kea  1.9.9-git
d2_queue_mgr.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2015,2017,2021 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 <exceptions/exceptions.h>
14 #include <dhcp_ddns/ncr_msg.h>
15 #include <dhcp_ddns/ncr_io.h>
16 
17 #include <boost/noncopyable.hpp>
18 #include <deque>
19 
20 namespace isc {
21 namespace d2 {
22 
25 typedef std::deque<dhcp_ddns::NameChangeRequestPtr> RequestQueue;
26 
29 public:
30  D2QueueMgrError(const char* file, size_t line, const char* what) :
31  isc::Exception(file, line, what) { };
32 };
33 
38 public:
39  D2QueueMgrReceiveError(const char* file, size_t line, const char* what) :
40  isc::Exception(file, line, what) { };
41 };
42 
43 
47 public:
48  D2QueueMgrQueueFull(const char* file, size_t line, const char* what) :
49  isc::Exception(file, line, what) { };
50 };
51 
54 public:
55  D2QueueMgrQueueEmpty(const char* file, size_t line, const char* what) :
56  isc::Exception(file, line, what) { };
57 };
58 
61 public:
62  D2QueueMgrInvalidIndex(const char* file, size_t line, const char* what) :
63  isc::Exception(file, line, what) { };
64 };
65 
66 
132  boost::noncopyable {
133 public:
137  static const size_t MAX_QUEUE_DEFAULT = 1024;
138 
140  enum State {
148  };
149 
163  const size_t max_queue_size = MAX_QUEUE_DEFAULT);
164 
166  virtual ~D2QueueMgr();
167 
179  void initUDPListener(const isc::asiolink::IOAddress& ip_address,
180  const uint32_t port,
182  const bool reuse_address = false);
183 
191  void startListening();
192 
220  virtual void operator ()(const dhcp_ddns::NameChangeListener::Result result,
222 
235  void stopListening(const State target_stop_state = STOPPED);
236 
237 
245  void removeListener();
246 
248  size_t getQueueSize() const {
249  return (ncr_queue_.size());
250  };
251 
253  size_t getMaxQueueSize() const {
254  return (max_queue_size_);
255  }
256 
264  void setMaxQueueSize(const size_t max_queue_size);
265 
267  State getMgrState() const {
268  return (mgr_state_);
269  }
270 
280  const dhcp_ddns::NameChangeRequestPtr& peek() const;
281 
292  const dhcp_ddns::NameChangeRequestPtr& peekAt(const size_t index) const;
293 
301  void dequeueAt(const size_t index);
302 
306  void dequeue();
307 
312 
314  void clearQueue();
315 
316  private:
321  void updateStopState();
322 
324  asiolink::IOServicePtr io_service_;
325 
327  size_t max_queue_size_;
328 
330  RequestQueue ncr_queue_;
331 
333  boost::shared_ptr<dhcp_ddns::NameChangeListener> listener_;
334 
336  State mgr_state_;
337 
339  State target_stop_state_;
340 };
341 
343 typedef boost::shared_ptr<D2QueueMgr> D2QueueMgrPtr;
344 
345 } // namespace isc::d2
346 } // namespace isc
347 
348 #endif
size_t getMaxQueueSize() const
Returns the maximum number of entries allowed in the queue.
Definition: d2_queue_mgr.h:253
State
Defines the list of possible states for D2QueueMgr.
Definition: d2_queue_mgr.h:140
void dequeue()
Removes the entry at the front of the queue.
State getMgrState() const
Returns the current state.
Definition: d2_queue_mgr.h:267
D2QueueMgrError(const char *file, size_t line, const char *what)
Definition: d2_queue_mgr.h:30
static const size_t MAX_QUEUE_DEFAULT
Maximum number of entries allowed in the request queue.
Definition: d2_queue_mgr.h:137
Thrown if the request queue empty and a read is attempted.
Definition: d2_queue_mgr.h:53
This file defines abstract classes for exchanging NameChangeRequests.
D2QueueMgr creates and manages a queue of DNS update requests.
Definition: d2_queue_mgr.h:131
D2QueueMgrQueueFull(const char *file, size_t line, const char *what)
Definition: d2_queue_mgr.h:48
NameChangeFormat
Defines the list of data wire formats supported.
Definition: ncr_msg.h:60
void dequeueAt(const size_t index)
Removes the entry at a given position in the queue.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
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:33
void startListening()
Starts actively listening for requests.
void stopListening(const State target_stop_state=STOPPED)
Stops listening for requests.
D2QueueMgr(asiolink::IOServicePtr &io_service, const size_t max_queue_size=MAX_QUEUE_DEFAULT)
Constructor.
Definition: d2_queue_mgr.cc:18
D2QueueMgrQueueEmpty(const char *file, size_t line, const char *what)
Definition: d2_queue_mgr.h:55
boost::shared_ptr< D2QueueMgr > D2QueueMgrPtr
Defines a pointer for manager instances.
Definition: d2_queue_mgr.h:343
const dhcp_ddns::NameChangeRequestPtr & peekAt(const size_t index) const
Returns the entry at a given position in the queue.
void clearQueue()
Removes all entries from the queue.
void enqueue(dhcp_ddns::NameChangeRequestPtr &ncr)
Adds a request to the end of the queue.
D2QueueMgrReceiveError(const char *file, size_t line, const char *what)
Definition: d2_queue_mgr.h:39
size_t getQueueSize() const
Returns the number of entries in the queue.
Definition: d2_queue_mgr.h:248
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Defines a State within the State Model.
Definition: state_model.h:61
std::deque< dhcp_ddns::NameChangeRequestPtr > RequestQueue
Defines a queue of requests.
Definition: d2_queue_mgr.h:25
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Thrown if the queue manager encounters a general error.
Definition: d2_queue_mgr.h:28
Thrown if the request queue is full when an enqueue is attempted.
Definition: d2_queue_mgr.h:46
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:99
void setMaxQueueSize(const size_t max_queue_size)
Sets the maximum number of entries allowed in the queue.
Thrown if the queue manager's receive handler is passed a failure result.
Definition: d2_queue_mgr.h:37
D2QueueMgrInvalidIndex(const char *file, size_t line, const char *what)
Definition: d2_queue_mgr.h:62
virtual ~D2QueueMgr()
Destructor.
Definition: d2_queue_mgr.cc:29
const dhcp_ddns::NameChangeRequestPtr & peek() const
Returns the entry at the front of the queue.
void removeListener()
Deletes the current listener.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
Thrown if a queue index is beyond the end of the queue.
Definition: d2_queue_mgr.h:60
Abstract class for defining application layer receive callbacks.
Definition: ncr_io.h:183
Result
Defines the outcome of an asynchronous NCR receive.
Definition: ncr_io.h:171
std::string format(const std::string &format, const std::vector< std::string > &args)
Apply Formatting.
Definition: strutil.cc:157