00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef RESOURCEPOOL_LOGINTERFACE_HH
00025 #define RESOURCEPOOL_LOGINTERFACE_HH
00026
00027 #include <map>
00028 #include <algorithm>
00029 #include <sstream>
00030 #include "util/Clone.hh"
00031 #include "mm/gc_ptr.hh"
00032 #include "ResourcePool/Command.hh"
00033
00034 namespace fatalmind {
00035
00036 class EventReader;
00091 class ResourcePoolEventObserver: public Clone {
00092 public:
00093 typedef unsigned int event_t;
00094 static const std::string NoResourceID;
00095
00096 ResourcePoolEventObserver();
00097
00110 virtual void event(event_t eventID, const std::string& resourceID = NoResourceID, const std::string& message ="");
00111
00112 bool isEvent(event_t eventID) {
00113 return ((logevents & eventID) != 0);
00114 }
00115
00119 static struct Events {
00120 static const event_t INCREMENT_POOL;
00121 static const event_t DOWNSIZE_POOL;
00122 static const event_t FAIL_RESOURCE;
00123 static const event_t GET_RESOURCE_FAIL;
00124 static const event_t EXECUTE_NFE;
00125 static const event_t EXECUTE_FAIL;
00126
00127 static const event_t TIME_HIRES;
00128
00129 static const event_t FAIL;
00130 static const event_t ALL;
00131 static const event_t NONE;
00132 } Event;
00133
00137
00138
00139 const std::string& getEventName(const event_t event) const;
00140
00149 const event_t getEvent(const std::string& value) const;
00150
00158 const event_t registerEvent(const std::string& value) ;
00159
00167 const event_t getEventMask(const std::string& value) const;
00168
00169 inline event_t setLogEvents(event_t events) {
00170 event_t rv = logevents;
00171 logevents = events;
00172 return rv;
00173 }
00178 void setDefaultEventMask();
00179
00180 gc_ptr<EventReader> getReader(const event_t event, const std::string& r);
00181
00182 protected:
00183
00184 event_t logevents;
00185 virtual Clone* DoClone() const;
00186
00187 private:
00188 typedef std::map<event_t, std::string> namemap_t;
00189 namemap_t names;
00190 int nextEventBit;
00191
00192 static const std::string INVALID;
00193 };
00194
00195 class EventReader: public usg_cnt_t<DefaultThreadedModel>, public std::ostringstream {
00196 typedef std::ostringstream super;
00197 private:
00198
00199 EventReader(ResourcePoolEventObserver& observer, ResourcePoolEventObserver::event_t e, std::string resource);
00200 friend class ResourcePoolEventObserver;
00201 public:
00202
00203
00204 ~EventReader();
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 template<typename T>
00218 inline
00219 EventReader& operator<< (const T& val) {
00220 if (observer.isEvent(event)) {
00221 super& s = *((super*)this);
00222 s <<val;
00223 }
00224 return *this;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 private:
00237 ResourcePoolEventObserver& observer;
00238 ResourcePoolEventObserver::event_t event;
00239 std::string resource;
00240
00241 };
00242
00243 }
00244 #endif