LogSerializer.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 _LOGSERIALIZER_HPP__
  14. #define _LOGSERIALIZER_HPP__
  15. #include "jlib.hpp"
  16. #include "jstring.hpp"
  17. #include "jutil.hpp" // for StringArray
  18. #include "jmutex.hpp"
  19. #include <map>
  20. #include <string>
  21. #include <set> //for GuidSet
  22. typedef std::set<std::string> GuidSet;//
  23. typedef std::map<std::string, std::string> GuidMap;
  24. class CLogSerializer : public CInterface
  25. {
  26. __int64 m_bytesWritten;
  27. unsigned long m_ItemCount;//
  28. CriticalSection crit;
  29. protected:
  30. IFile* m_file;
  31. IFileIO* m_fileio;
  32. StringBuffer m_FileName;
  33. StringBuffer m_FilePath;
  34. protected:
  35. __int64 WroteBytes();
  36. void Init();
  37. StringBuffer& GetRolloverFileName(StringBuffer& oldFile, StringBuffer& newfile, const char* newExtension);
  38. public:
  39. bool EnsureDirectory(StringBuffer& Dir);
  40. public:
  41. IMPLEMENT_IINTERFACE;
  42. CLogSerializer();
  43. CLogSerializer(const char* fileName);
  44. virtual ~CLogSerializer();
  45. void Open(const char* Directory,const char* NewFileName,const char* Prefix);
  46. void Close();
  47. void Remove();
  48. void Rollover(const char* ClosedPrefix);
  49. void Append(const char* GUID, const char* Data);
  50. void Remove(const char* GUID);
  51. virtual void SplitRecord(StringBuffer& FullStr, StringBuffer& GUID, StringBuffer& Cache){}
  52. static void splitLogRecord(MemoryBuffer& rawdata,StringBuffer& GUID, StringBuffer& data);//
  53. const char* queryFileName(){return m_FileName.str();};
  54. const char* queryFilePath(){return m_FilePath.str();};
  55. void SafeRollover(const char* Directory,const char* NewFileName,const char* Prefix, const char* ClosedPrefix);
  56. unsigned long getItemCount() const { return m_ItemCount; }//
  57. static StringBuffer& extractFileName(const char* fullName, StringBuffer& fileName);//
  58. virtual void loadSendLogs(GuidSet& ACKSet, GuidMap& MissedLogs, unsigned long& total_missed);//
  59. virtual void loadAckedLogs(GuidSet& ReceiveMap);//
  60. };
  61. class CSendLogSerializer : public CLogSerializer
  62. {
  63. public:
  64. IMPLEMENT_IINTERFACE;
  65. CSendLogSerializer();
  66. CSendLogSerializer(const char* fileName) : CLogSerializer(fileName) {};
  67. virtual void LoadDataMap(GuidMap& ACKMap,StringArray& MissedLogs);
  68. void LoadMap(MemoryBuffer& rawdata,StringBuffer& GUID, StringBuffer& data);
  69. };
  70. void SplitRecord(const char* FullStr, StringBuffer& GUID, StringBuffer& Cache);
  71. class CRecieveLogSerializer : public CLogSerializer
  72. {
  73. public:
  74. IMPLEMENT_IINTERFACE;
  75. CRecieveLogSerializer();
  76. CRecieveLogSerializer(const char* fileName) : CLogSerializer(fileName){}
  77. virtual void LoadDataMap(GuidMap& GUIDmap);
  78. void LoadMap(MemoryBuffer& data,GuidMap& GUIDmap, bool printTrace = false);
  79. };
  80. #endif // !LOGSERIALIZER