00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef GRID_CLIENT_IMPL_HPP_INCLUDED
00011 #define GRID_CLIENT_IMPL_HPP_INCLUDED
00012
00013 #include <vector>
00014 #include <string>
00015 #include <memory>
00016
00017 #include "gridgain/gridclient.hpp"
00018 #include "gridgain/impl/gridclientshareddata.hpp"
00019 #include "gridgain/impl/gridclientrecurringeventthread.hpp"
00020 #include "gridgain/impl/gridclientdataprojection.hpp"
00021 #include "gridgain/impl/gridclientcomputeprojection.hpp"
00022 #include "gridgain/impl/gridclientprojectionlistener.hpp"
00023 #include "gridgain/impl/utils/gridthreadpool.hpp"
00024
00028 class GridClientImpl : public GridClient, public GridClientProjectionListener {
00029 public:
00036 GridClientImpl(const GridClientConfiguration& cfg, std::shared_ptr<GridClientCommandExecutorPrivate>& exec);
00037
00044 virtual GridClientUuid id() const;
00045
00052 virtual TGridClientDataPtr data();
00053
00063 virtual TGridClientDataPtr data(const std::string& cacheName);
00064
00077 virtual TGridClientComputePtr compute();
00078
00086 virtual void addTopologyListener(TGridClientTopologyListenerPtr lsnr);
00087
00093 virtual void removeTopologyListener(TGridClientTopologyListenerPtr lsnr);
00094
00100 virtual TGridClientTopologyListenerListPtr topologyListeners() const;
00101
00106 virtual void stop(bool waitCompletion = true);
00107
00111 void onNodeIoFailed(const GridClientNode& n);
00112
00113 protected:
00115 TGridClientSharedDataPtr getSharedData() const {
00116 return sharedData;
00117 }
00118
00120 std::shared_ptr<GridClientComputeProjectionImpl> mainComputePrj;
00121
00123
00124 typedef std::map<std::string, std::shared_ptr<GridClientDataProjectionImpl> > TDataPrjMap;
00125
00127 TDataPrjMap mainDataPrjs;
00128
00129 private:
00131 void refreshTopology();
00132
00139 TGridClientDataPtr getOrCreateDataProjection(std::string cacheName);
00140
00147 void fireTopologyEvents(const TNodesSet& updNodes, const TNodesSet& prevNodes);
00148
00154 void fireNodeAdded(const GridClientNode& node);
00155
00161 void fireNodeRemoved(const GridClientNode& node);
00162
00164 TGridClientSharedDataPtr sharedData;
00165
00167 friend class GridClientTopologyRefresher;
00168
00170 class GridClientTopologyRefresher : public GridClientRecurringEventThread::EventListener {
00171 public:
00178 GridClientTopologyRefresher(long topRefreshFreq, GridClientImpl& pClient)
00179 : refreshThread(topRefreshFreq, *this), client(pClient) {
00180 }
00181
00185 virtual void onTimerEvent();
00186
00187 private:
00189 GridClientRecurringEventThread refreshThread;
00190
00192 GridClientImpl& client;
00193 };
00194
00196 std::shared_ptr<GridClientTopologyRefresher> topRefresher;
00197
00199 TGridThreadPoolPtr threadPool;
00200
00202 std::vector<TGridClientTopologyListenerPtr> topLsnrs;
00203
00205 mutable boost::mutex topLsnrsMux;
00206 };
00207
00208 #endif