00001 /*------------------------------------------------------------------------------ 00002 Name: ConnectionsHandler.h 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Handles the org::xmlBlaster::client::protocol::I_XmlBlasterConnections 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _UTIL_DISPATCH_CONNECTIONSHANDLER_H 00008 #define _UTIL_DISPATCH_CONNECTIONSHANDLER_H 00009 00010 #include <vector> 00011 #include <util/xmlBlasterDef.h> 00012 #include <util/dispatch/I_ConnectionsHandler.h> 00013 #include <util/dispatch/I_PostSendListener.h> 00014 #include <client/I_ConnectionProblems.h> 00015 #include <util/XmlBlasterException.h> 00016 #include <util/thread/ThreadImpl.h> 00017 #include <util/I_Timeout.h> 00018 //#include <util/queue/I_Queue.h> 00019 // #include <util/queue/PublishQueueEntry.h> 00020 // #include <util/queue/ConnectQueueEntry.h> 00021 00022 #ifndef _UTIL_QUEUE_I_QUEUE_H 00023 namespace org { namespace xmlBlaster { namespace util { namespace queue { 00024 class I_Queue; 00025 }}}} 00026 #endif 00027 00028 namespace org { namespace xmlBlaster { namespace util { namespace dispatch { 00029 00036 class Dll_Export ConnectionsHandler : public I_Timeout, public org::xmlBlaster::util::dispatch::I_ConnectionsHandler 00037 { 00038 private: 00039 const std::string ME; 00040 org::xmlBlaster::util::qos::ConnectQosRef connectQos_; 00041 org::xmlBlaster::util::qos::ConnectReturnQosRef connectReturnQos_; 00042 org::xmlBlaster::client::I_ConnectionProblems* connectionProblemsListener_; 00043 org::xmlBlaster::client::protocol::I_XmlBlasterConnection* connection_; 00044 enum States status_; 00045 org::xmlBlaster::util::Global& global_; 00046 org::xmlBlaster::util::I_Log& log_; 00047 org::xmlBlaster::util::thread::Mutex connectMutex_; 00048 org::xmlBlaster::util::thread::Mutex publishMutex_; 00049 int retries_; 00050 int currentRetry_; 00051 org::xmlBlaster::util::Timestamp pingPollTimerKey_; 00052 org::xmlBlaster::util::queue::I_Queue* queue_; 00053 org::xmlBlaster::util::dispatch::I_PostSendListener* postSendListener_; 00054 const std::string instanceName_; 00055 bool doStopPing_; // used to stop the pinger when destroying the object 00056 00057 public: 00058 ConnectionsHandler(org::xmlBlaster::util::Global& global, const std::string& instanceName); 00059 00060 virtual ~ConnectionsHandler(); 00061 00062 00075 org::xmlBlaster::util::qos::ConnectReturnQosRef connect(const org::xmlBlaster::util::qos::ConnectQosRef& qos); 00076 00082 bool disconnect(const org::xmlBlaster::util::qos::DisconnectQos& qos); 00083 00087 std::string getProtocol(); 00088 00092 // std::string loginRaw(); 00093 00094 bool shutdown(); 00095 00096 std::string getLoginName(); 00097 00098 bool isLoggedIn(); 00099 00100 std::string ping(const std::string& qos); 00101 00102 org::xmlBlaster::client::qos::SubscribeReturnQos subscribe(const org::xmlBlaster::client::key::SubscribeKey& key, const org::xmlBlaster::client::qos::SubscribeQos& qos); 00103 00104 std::vector<org::xmlBlaster::util::MessageUnit> get(const org::xmlBlaster::client::key::GetKey& key, const org::xmlBlaster::client::qos::GetQos& qos); 00105 00106 std::vector<org::xmlBlaster::client::qos::UnSubscribeReturnQos> 00107 unSubscribe(const org::xmlBlaster::client::key::UnSubscribeKey& key, const org::xmlBlaster::client::qos::UnSubscribeQos& qos); 00108 00109 org::xmlBlaster::client::qos::PublishReturnQos publish(const org::xmlBlaster::util::MessageUnit& msgUnit); 00110 00111 void publishOneway(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr); 00112 00113 std::vector<org::xmlBlaster::client::qos::PublishReturnQos> publishArr(const std::vector<org::xmlBlaster::util::MessageUnit> &msgUnitArr); 00114 00115 std::vector<org::xmlBlaster::client::qos::EraseReturnQos> erase(const org::xmlBlaster::client::key::EraseKey& key, const org::xmlBlaster::client::qos::EraseQos& qos); 00116 00123 org::xmlBlaster::util::dispatch::I_PostSendListener* registerPostSendListener(org::xmlBlaster::util::dispatch::I_PostSendListener *listener); 00124 00125 void initFailsafe(org::xmlBlaster::client::I_ConnectionProblems* connectionProblems); 00126 00127 void timeout(void *userData); 00128 00134 bool putToQueue(); 00135 00136 bool isRecoverable(const org::xmlBlaster::util::XmlBlasterException* reason); 00137 00143 long flushQueue(); 00144 00145 org::xmlBlaster::util::queue::I_Queue* getQueue(); 00146 00147 bool isFailsafe() const; 00148 00153 bool isConnected() const; 00154 00158 bool isAlive() const; 00159 00163 bool isPolling() const; 00164 00168 bool isDead() const; 00169 00174 std::string getStatusString() const; 00175 00176 org::xmlBlaster::util::qos::ConnectReturnQosRef connectRaw(const org::xmlBlaster::util::qos::ConnectQosRef& connectQos); 00177 00178 virtual org::xmlBlaster::client::protocol::I_XmlBlasterConnection& getConnection() const; 00179 00180 virtual org::xmlBlaster::util::qos::ConnectReturnQosRef getConnectReturnQos(); 00181 00182 virtual org::xmlBlaster::util::qos::ConnectQosRef getConnectQos(); 00183 00184 protected: 00186 long flushQueueUnlocked(org::xmlBlaster::util::queue::I_Queue *queueToFlush, bool doRemove=true); 00187 org::xmlBlaster::client::qos::PublishReturnQos queuePublish(const org::xmlBlaster::util::MessageUnit& msgUnit); 00188 org::xmlBlaster::client::qos::SubscribeReturnQos queueSubscribe(const org::xmlBlaster::client::key::SubscribeKey& key, const org::xmlBlaster::client::qos::SubscribeQos& qos); 00189 org::xmlBlaster::util::qos::ConnectReturnQosRef& queueConnect(); 00193 bool startPinger(bool withInitialPing); 00194 00198 void toPollingOrDead(const org::xmlBlaster::util::XmlBlasterException* reason); 00199 }; 00200 00201 00202 }}}} // namespaces 00203 00204 #endif