zone_writer.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef MEM_ZONE_WRITER_H
  15. #define MEM_ZONE_WRITER_H
  16. #include "load_action.h"
  17. namespace isc {
  18. namespace datasrc {
  19. namespace memory {
  20. /// \brief Does an update to a zone.
  21. ///
  22. /// This abstract base class represents the work of a reload of a zone.
  23. /// The work is divided into three stages -- load(), install() and cleanup().
  24. /// They should be called in this order for the effect to take place.
  25. ///
  26. /// We divide them so the update of zone data can be done asynchronously,
  27. /// in a different thread. The install() operation is the only one that needs
  28. /// to be done in a critical section.
  29. ///
  30. /// Each derived class implementation must provide the strong exception
  31. /// guarantee for each public method. That is, when any of the methods
  32. /// throws, the entire state should stay the same as before the call
  33. /// (how to achieve that may be implementation dependant).
  34. class ZoneWriter {
  35. public:
  36. /// \brief Virtual destructor.
  37. virtual ~ZoneWriter() {};
  38. /// \brief Get the zone data into memory.
  39. ///
  40. /// This is the part that does the time-consuming loading into the memory.
  41. /// This can be run in a separate thread, for example. It has no effect on
  42. /// the data actually served, it only prepares them for future use.
  43. ///
  44. /// This is the first method you should call on the object. Never call it
  45. /// multiple times.
  46. ///
  47. /// \note As this contains reading of files or other data sources, or with
  48. /// some other source of the data to load, it may throw quite anything.
  49. /// If it throws, do not call any other methods on the object and
  50. /// discard it.
  51. /// \note After successful load(), you have to call cleanup() some time
  52. /// later.
  53. /// \throw isc::InvalidOperation if called second time.
  54. virtual void load() = 0;
  55. /// \brief Put the changes to effect.
  56. ///
  57. /// This replaces the old version of zone with the one previously prepared
  58. /// by load(). It takes ownership of the old zone data, if any.
  59. ///
  60. /// You may call it only after successful load() and at most once.
  61. ///
  62. /// The operation is expected to be fast and is meant to be used inside
  63. /// a critical section.
  64. ///
  65. /// This may throw in rare cases, depending on the concrete implementation.
  66. /// If it throws, you still need to call cleanup().
  67. ///
  68. /// \throw isc::InvalidOperation if called without previous load() or for
  69. /// the second time or cleanup() was called already.
  70. virtual void install() = 0;
  71. /// \brief Clean up resources.
  72. ///
  73. /// This releases all resources held by owned zone data. That means the
  74. /// one loaded by load() in case install() was not called or was not
  75. /// successful, or the one replaced in install().
  76. ///
  77. /// Generally, this should never throw.
  78. virtual void cleanup() = 0;
  79. };
  80. }
  81. }
  82. }
  83. #endif