storage.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include "message_ptr_and_header.h"
  3. #include "moved.h"
  4. #include "ybus.h"
  5. #include <contrib/libs/sparsehash/src/sparsehash/dense_hash_map>
  6. #include <util/generic/deque.h>
  7. #include <util/generic/noncopyable.h>
  8. #include <util/generic/utility.h>
  9. namespace NBus {
  10. namespace NPrivate {
  11. typedef TVector<TBusMessage*> TMessagesPtrs;
  12. class TTimedMessages {
  13. public:
  14. TTimedMessages();
  15. ~TTimedMessages();
  16. struct TItem {
  17. THolder<TBusMessage> Message;
  18. void Swap(TItem& that) {
  19. DoSwap(Message, that.Message);
  20. }
  21. };
  22. typedef TDeque<TMoved<TItem>> TItems;
  23. void PushBack(TNonDestroyingAutoPtr<TBusMessage> m);
  24. TNonDestroyingAutoPtr<TBusMessage> PopFront();
  25. bool Empty() const;
  26. size_t Size() const;
  27. void Timeout(TInstant before, TMessagesPtrs* r);
  28. void Clear(TMessagesPtrs* r);
  29. private:
  30. TItems Items;
  31. };
  32. class TSyncAckMessages : TNonCopyable {
  33. public:
  34. TSyncAckMessages();
  35. ~TSyncAckMessages();
  36. void Push(TBusMessagePtrAndHeader& m);
  37. TBusMessage* Pop(TBusKey id);
  38. void Timeout(TInstant before, TMessagesPtrs* r);
  39. void Clear(TMessagesPtrs* r);
  40. size_t Size() const {
  41. return KeyToMessage.size();
  42. }
  43. void RemoveAll(const TMessagesPtrs&);
  44. void Gc();
  45. void DumpState();
  46. private:
  47. struct TTimedItem {
  48. TBusKey Key;
  49. TBusInstant SendTime;
  50. };
  51. typedef TDeque<TTimedItem> TTimedItems;
  52. typedef TDeque<TTimedItem>::iterator TTimedIterator;
  53. TTimedItems TimedItems;
  54. struct TValue {
  55. TBusMessage* Message;
  56. };
  57. // keys are already random, no need to hash them further
  58. struct TIdHash {
  59. size_t operator()(TBusKey value) const {
  60. return value;
  61. }
  62. };
  63. typedef google::dense_hash_map<TBusKey, TValue, TIdHash> TKeyToMessage;
  64. TKeyToMessage KeyToMessage;
  65. };
  66. }
  67. }