00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef SEMAINE_COMPONENTS_COMPONENT_H
00011 #define SEMAINE_COMPONENTS_COMPONENT_H
00012
00013 #include <list>
00014 #include <queue>
00015
00016 #include <semaine/config.h>
00017
00018 #include <decaf/lang/System.h>
00019 #include <decaf/lang/Thread.h>
00020 #include <decaf/util/concurrent/Concurrent.h>
00021 #include <decaf/util/concurrent/Mutex.h>
00022
00023 #include <cms/CMSException.h>
00024
00025 #include <semaine/cms/SEMAINEMessageAvailableListener.h>
00026 #include <semaine/cms/receiver/Receiver.h>
00027 #include <semaine/cms/sender/Sender.h>
00028 #include <semaine/components/meta/MetaMessenger.h>
00029
00030
00031 using namespace decaf::lang;
00032 using namespace cms;
00033 using namespace semaine::cms;
00034 using namespace semaine::cms::receiver;
00035 using namespace semaine::cms::sender;
00036 using namespace semaine::components::meta;
00037
00038 namespace semaine {
00039 namespace components {
00040
00052 class Component : public Thread, public SEMAINEMessageAvailableListener
00053 {
00054 public:
00055 static const std::string STATE_STARTING;
00056 static const std::string STATE_READY;
00057 static const std::string STATE_STOPPED;
00058 static const std::string STATE_FAILURE;
00059 static const std::string STATE_STALLED;
00060
00061 virtual ~Component();
00062
00063 const std::string getName() { return name; }
00064
00069 virtual void messageAvailableFrom(Receiver * const source);
00070
00074 void run();
00075
00076 void requestExit();
00077
00078
00079
00080 protected:
00081 std::list<Receiver *> receivers;
00082 std::list<Sender *> senders;
00083 std::queue<Receiver *> inputWaiting;
00084 CMSLogger * log;
00085 bool _exitRequested;
00086 std::string state;
00087 MetaMessenger meta;
00088 int waitingTime;
00089 bool isInput;
00090 bool isOutput;
00091 decaf::util::concurrent::Mutex mutex;
00092
00101 Component(const std::string & componentName, bool isInput=false, bool isOutput=false)
00102 throw (CMSException);
00103
00114 Component(const std::string & componentName,
00115 const std::string & cmsUrl, const std::string & cmsUser = "", const std::string & cmsPassword = "")
00116 throw (CMSException);
00117
00129 Component(const std::string & componentName, bool isInput, bool isOutput,
00130 const std::string & cmsUrl, const std::string & cmsUser, const std::string & cmsPassword)
00131 throw (CMSException);
00132
00133 bool exitRequested();
00134
00136
00146 virtual void act() throw(std::exception) {}
00147
00156 virtual void react(SEMAINEMessage * message) throw (std::exception) {}
00157
00163 virtual void customStartIO() throw(std::exception) {}
00164
00165 private:
00166 const std::string name;
00167
00168 void startIO() throw(std::exception);
00169
00170
00171
00172
00173 };
00174
00175
00176
00177
00178 }
00179 }
00180
00181 #endif
00182