logthread.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 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 _LOGTHREAD_HPP__
  14. #define _LOGTHREAD_HPP__
  15. #include "jthread.hpp"
  16. #include "jqueue.tpp"
  17. #include "loggingagentbase.hpp"
  18. #include "LogFailSafe.hpp"
  19. interface IUpdateLogThread : extends IInterface
  20. {
  21. virtual int run() = 0;
  22. virtual void start() = 0;
  23. virtual void stop() = 0;
  24. virtual IEspLogAgent* getLogAgent() = 0;
  25. virtual bool hasService(LOGServiceType service) = 0;
  26. virtual bool queueLog(IEspUpdateLogRequest* logRequest) = 0;
  27. virtual bool queueLog(IEspUpdateLogRequestWrap* logRequest) = 0;
  28. virtual void sendLog() = 0;
  29. };
  30. class CLogThread : public Thread , implements IUpdateLogThread
  31. {
  32. bool stopping;
  33. StringAttr agentName;
  34. int maxLogQueueLength;
  35. int signalGrowingQueueAt;
  36. unsigned maxLogRetries; // Max. # of attempts to send log message
  37. Owned<IEspLogAgent> logAgent;
  38. LOGServiceType services[MAXLOGSERVICES];
  39. QueueOf<IInterface, false> logQueue;
  40. CriticalSection logQueueCrit;
  41. Semaphore m_sem;
  42. bool ensureFailSafe;
  43. Owned<ILogFailSafe> logFailSafe;
  44. struct tm m_startTime;
  45. unsigned serializeLogRequestContent(IEspUpdateLogRequestWrap* request, StringBuffer& logData);
  46. IEspUpdateLogRequestWrap* unserializeLogRequestContent(const char* logData);
  47. bool enqueue(IEspUpdateLogRequestWrap* logRequest);
  48. void writeJobQueue(IEspUpdateLogRequestWrap* jobToWrite);
  49. IEspUpdateLogRequestWrap* readJobQueue();
  50. public:
  51. IMPLEMENT_IINTERFACE;
  52. CLogThread();
  53. CLogThread(IPropertyTree* _agentConfig, const char* _service, const char* _agentName, IEspLogAgent* _logAgent = NULL);
  54. virtual ~CLogThread();
  55. IEspLogAgent* getLogAgent() {return logAgent;};
  56. bool hasService(LOGServiceType service)
  57. {
  58. unsigned int i = 0;
  59. while (services[i] != LGSTterm)
  60. {
  61. if (services[i] == service)
  62. return true;
  63. i++;
  64. }
  65. return false;
  66. }
  67. void addService(LOGServiceType service)
  68. {
  69. unsigned i=0;
  70. while (services[i] != LGSTterm) i++;
  71. services[i] = service;
  72. };
  73. int run();
  74. void start();
  75. void stop();
  76. bool queueLog(IEspUpdateLogRequest* logRequest);
  77. bool queueLog(IEspUpdateLogRequestWrap* logRequest);
  78. void sendLog();
  79. void checkPendingLogs(bool oneRecordOnly=false);
  80. void checkRollOver();
  81. };
  82. extern LOGGINGCOMMON_API IUpdateLogThread* createUpdateLogThread(IPropertyTree* _cfg, const char* _service, const char* _agentName, IEspLogAgent* _logAgent);
  83. #endif // _LOGTHREAD_HPP__