rasdaman complete source
rasmgr_master.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
37 #ifndef RASMGR_MASTER_HH
38 #define RASMGR_MASTER_HH
39 
40 #include "rasmgr_comm_nb.hh"
41 #include <deque>
42 #include<string>
43 
47 class ClientID
48 {
49 public:
50  ClientID();
51  void init(const char*);
52 
53  bool operator==(const ClientID&);
54  bool operator!=(const ClientID&);
55 
56  std::string getID() const;
57  bool isValid() const;
58 private:
59  std::string idstring;
60  bool valid;
61  friend std::ostream& operator<<(std::ostream&, const ClientID&);
62 };
63 
64 
68 class ClientQueue
69 {
70 public:
71  ClientQueue();
72  ~ClientQueue();
73 
74  void put(ClientID&, const char *dbName, char serverType, int errorCode);
75 
76  // the answer is 0 or the errorcode
77  int canBeServed(ClientID&, const char *dbName, char serverType, bool fake);
78 
79 private:
80  struct ClientEntry
81  {
82  bool activ;
83  ClientID clientID;
84  std::string dbName;
85  char serverType;
86  int errorCode;
87  time_t lastAction;
88  time_t timeLimit;
89 
90  bool wasfake;
91 
92  ClientEntry();
93  ClientEntry(ClientID &client, const char *dbName, char serverType, int errorCode);
94 
95  bool shouldWeCleanup(bool fake);
96  void updateTime();
97 
98  bool isTimeout();
99  };
100 
101  std::deque<ClientEntry> clients;
102 
103 };
104 
108 class MasterComm:public NbServerComm
109 {
110 public:
111  MasterComm();
112  ~MasterComm();
113  void Run();
114  void commitChanges();
115  void commitAuthFile();
116 private:
117  bool isMessage(const char *messageStart);
118  int getFreeServer(bool fake);
119  const char* convertAnswerCode(int code);
120 
121 // int getFakeFreeServer();
122  int answerAccessDenied();
123  int answerAccessDeniedCode();
124  void doCommit();
125 
126  bool commit;
127  bool commitAuthOnly;
128 
129  void processJob( NbJob &currentJob );
130  int processRequest( NbJob &currentJob );
131 
132  bool fillInBuffer(const char*);
133  char *header;
134  char *body;
135  char inBuffer[MAXMSG];
136  char outBuffer[MAXMSGOUTBUFF];
137 
138  bool allowMultipleWriteTransactions;
139 
140  ClientQueue clientQueue;
141 };
142 
143 extern MasterComm masterCommunicator;
144 
145 #endif