1 #ifndef _DMUCS_HOST_STATE_H_
2 #define _DMUCS_HOST_STATE_H_ 1
3 
4 /*
5  * dmucs_host_state.cc: the DMUCS host state definition.
6  *
7  * Copyright (C) 2005, 2006  Victor T. Norman
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 
25 #include "dmucs_host.h"
26 
27 
28 
29 /*
30  * States of DmucsHosts:
31  * o available -- we got a status "avail" message for the host and/or we are
32  *   periodically receiving load average messages from it.  (Note: we may
33  *   not always receive the status message -- when the host comes up before
34  *   the Dmucs server.  In that case, we treat the load average message as
35  *   a status "avail" message.
36  * o unavailable -- we got a status "unavail" message from the host.  We
37  *   may still be receiving load average messages from it, but it has been
38  *   made "administratively" unavailable.
39  * o overloaded -- the load average messages we receive indicate that the
40  *   machine is very busy, and shouldn't be used for compiles.
41  * o silent -- we got a status "avail" message from the host, but now we
42  *   are not getting any load average messages from it.
43  */
44 
45 class DmucsHostState
46 {
47 public:
avail(DmucsHost * host)48     virtual void avail(DmucsHost *host) {}
unavail(DmucsHost * host)49     virtual void unavail(DmucsHost *host) {}
silent(DmucsHost * host)50     virtual void silent(DmucsHost *host) {}
overloaded(DmucsHost * host)51     virtual void overloaded(DmucsHost *host) {}
addToDb(DmucsHost * host)52     virtual void addToDb(DmucsHost *host) {}
removeFromDb(DmucsHost * host)53     virtual void removeFromDb(DmucsHost *host) {}
dump()54     virtual const char *dump() { return "Unknown"; }
asInt()55     virtual int asInt() { return (int) STATUS_UNKNOWN; }
56 
57 protected:
changeState(DmucsHost * host,DmucsHostState * newState)58     void changeState(DmucsHost *host, DmucsHostState *newState) {
59 	host->changeState(newState);
60     }
61 };
62 
63 
64 class DmucsHostStateAvail : public DmucsHostState
65 {
66 public:
67     virtual void unavail(DmucsHost *host);
68     virtual void silent(DmucsHost *host);
69     virtual void overloaded(DmucsHost *host);
asInt()70     virtual int asInt() { return (int) STATUS_AVAILABLE; }
71     virtual void addToDb(DmucsHost *host);
72     virtual void removeFromDb(DmucsHost *host);
dump()73     virtual const char *dump() { return "Available"; }
74 
75     static DmucsHostStateAvail *getInstance();
76 
77 private:
DmucsHostStateAvail()78     DmucsHostStateAvail() {}
79 
80     static DmucsHostStateAvail *instance_;
81 };
82 
83 class DmucsHostStateUnavail : public DmucsHostState
84 {
85 public:
86     virtual void avail(DmucsHost *host);
asInt()87     virtual int asInt() { return (int) STATUS_UNAVAILABLE; }
88     virtual void addToDb(DmucsHost *host);
89     virtual void removeFromDb(DmucsHost *host);
dump()90     virtual const char *dump() { return "Unavail"; }
91 
92     static DmucsHostStateUnavail *getInstance();
93 
94 private:
DmucsHostStateUnavail()95     DmucsHostStateUnavail() {}
96 
97     static DmucsHostStateUnavail *instance_;
98 };
99 
100 class DmucsHostStateSilent : public DmucsHostState
101 {
102 public:
103     virtual void avail(DmucsHost *host);
104     virtual void unavail(DmucsHost *host);
asInt()105     virtual int asInt() { return (int) STATUS_SILENT; };
106     virtual void addToDb(DmucsHost *host);
107     virtual void removeFromDb(DmucsHost *host);
dump()108     virtual const char *dump() { return "Silent"; }
109 
110     static DmucsHostStateSilent *getInstance();
111 
112 private:
DmucsHostStateSilent()113     DmucsHostStateSilent() {}
114 
115     static DmucsHostStateSilent *instance_;
116 };
117 
118 class DmucsHostStateOverloaded : public DmucsHostState
119 {
120 public:
121     virtual void avail(DmucsHost *host);
122     virtual void unavail(DmucsHost *host);
123     virtual void silent(DmucsHost *host);
asInt()124     virtual int asInt() { return (int) STATUS_OVERLOADED; }
125     virtual void addToDb(DmucsHost *host);
126     virtual void removeFromDb(DmucsHost *host);
dump()127     virtual const char *dump() { return "Overloaded"; }
128 
129     static DmucsHostStateOverloaded *getInstance();
130 
131 private:
DmucsHostStateOverloaded()132     DmucsHostStateOverloaded() {}
133 
134     static DmucsHostStateOverloaded *instance_;
135 };
136 
137 #endif
138 
139