udpmsgpk.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __UDPMSGPK__
  14. #define __UDPMSGPK__
  15. #include "roxiemem.hpp"
  16. #include <queue>
  17. class PackageSequencer;
  18. typedef unsigned __int64 PUID;
  19. typedef MapXToMyClass<PUID, PUID, PackageSequencer> msg_map;
  20. class CMessageCollator : public CInterfaceOf<IMessageCollator>
  21. {
  22. private:
  23. std::queue<PackageSequencer*> queue;
  24. msg_map mapping; // Note - only accessed from collator thread
  25. RelaxedAtomic<bool> activity;
  26. bool memLimitExceeded;
  27. bool encrypted;
  28. CriticalSection queueCrit;
  29. InterruptableSemaphore sem;
  30. Linked<roxiemem::IRowManager> rowMgr;
  31. ruid_t ruid;
  32. std::atomic<unsigned> totalBytesReceived = {0};
  33. std::atomic<unsigned> totalDuplicates = {0};
  34. std::atomic<unsigned> totalResends = {0};
  35. void collate(roxiemem::DataBuffer *dataBuff);
  36. public:
  37. CMessageCollator(roxiemem::IRowManager *_rowMgr, unsigned _ruid, bool encrypted);
  38. virtual ~CMessageCollator();
  39. virtual ruid_t queryRUID() const override
  40. {
  41. return ruid;
  42. }
  43. virtual unsigned queryBytesReceived() const override;
  44. virtual unsigned queryDuplicates() const override;
  45. virtual unsigned queryResends() const override;
  46. virtual IMessageResult *getNextResult(unsigned time_out, bool &anyActivity) override;
  47. virtual void interrupt(IException *E) override;
  48. bool attach_databuffer(roxiemem::DataBuffer *dataBuff);
  49. bool attach_data(const void *data, unsigned len);
  50. void noteDuplicate(bool isResend);
  51. };
  52. #endif // __UDPMSGPK__