GridComputing
Job Management in Grid Computing
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
gridnetwork.h
Go to the documentation of this file.
1 #ifndef GRIDNETWORK_H_
2 #define GRIDNETWORK_H_
3 
4 #include <map>
5 #include <string>
6 #include <functional>
7 #include <stdexcept>
8 #include "bytebuffer.h"
9 #include "interfaces.h"
10 #include "runnable.h"
11 
12 class Grid;
13 
15 #define GRID_SAVE_FILE "gridComputing.grid"
16 
18 
21 class ExistingGrid : public std::runtime_error
22 {
23 private:
24  std::string _name;
25 
26 public:
27  ExistingGrid(const std::string& name) : std::runtime_error("Grid already exists"), _name(name) {}
28  const std::string& GetExistingName() const { return _name; }
29 };
30 
32 
35 class UnknownGrid : public std::runtime_error
36 {
37 private:
38  std::string _name;
39 
40 public:
41  UnknownGrid(const std::string& name) : std::runtime_error("Grid not found"), _name(name) {}
42  const std::string& GetUnknownName() const { return _name; }
43 };
44 
46 
49 class GridNetwork : public ISave, public IUpdate, public Runnable
50 {
51 private:
52  std::map<std::string, Grid*> _bst;
53  void AddGrid(const std::string& name, Grid* grid);
54 
57 
59  void Run();
60 
61 public:
63  ~GridNetwork();
64 
66  void NewGrid(const std::string& name, const std::string& topic);
68  void ChangeGridName(const std::string& oldName, const std::string& newName);
70  void ChangeGridTopic(const std::string& name, const std::string& newTopic);
72  void RemoveGrid(const std::string& name);
73 
75  Grid* GetGrid(const std::string& name);
76 
82  static GridNetwork* Load(ByteBuffer& bb);
83 
89  bool Save(ByteBuffer& bb) const override;
90 
95  void Update(uint32 diff);
96 
98  const std::map<std::string, Grid*>& GetContainer() const { return _bst; }
99 
105  std::vector<const Grid*> ApplyPredicate(std::function<bool(const Grid*)> predicate) const;
106 
107 private: // no copying
109  GridNetwork(const GridNetwork &);
112 };
113 
114 #endif // GRIDNETWORK_H_