Warning: session_start(): open(/var/lib/php/sessions/sess_psr295p1kajb6j8dh5016jb1h9, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!752
!include #1004681 // Concepts
sconcept Sensor {
long updatedWhen;
PersistableThrowable error;
transient volatile bool updating;
void actionImpl() {} // override this in subclasses
void action() {
updatedWhen = now();
updating = true;
Throwable theError = null;
try {
actionImpl();
} catch e {
theError = e;
} finally {
error = persistableThrowable(theError);
updating = false;
}
}
bool ok() { ret error == null; }
void dependOn(Sensor s) {
updater.depend(this, s);
}
void update() {
updater.update(this);
}
}
sconcept BooleanSensor extends Sensor {
bool booleanValue;
}
sclass Updater {
new HashSet updated;
void depend(Sensor a, Sensor b) {
update(b);
}
void update(Sensor s) {
if (!updated.contains(s)) {
s.action();
updated.add(s);
}
}
void reset() {
updated.clear();
}
}
static new Updater updater;
sconcept RawPSCmd extends Sensor {
S output;
O notRunBecause;
void actionImpl() {
if (isLinux())
output = backtick("ps -aef");
else
notRunBecause = "Not on Linux";
}
}
// boolean value is true when there is at least 1 chrome process
sconcept PSChrome extends BooleanSensor {
int chromeProcesses;
void actionImpl() {
RawPSCmd ps = unary(RawPSCmd.class);
dependOn(ps);
if (!ps.ok()) supplierFailure();
L cmds = psGetCommands(ps.output);
chromeProcesses = l(indexesOfLinesStartingWith(cmds, "/opt/google/chrome/"));
booleanValue = chromeProcesses > 0;
}
}
p {
typeWriterConsole();
int last = -1;
while licensed {
updater.reset();
pcall {
PSChrome chrome = unary(PSChrome.class);
chrome.update();
if (!chrome.ok())
print("Chrome Detection Error: " + chrome.error);
else if (last != chrome.chromeProcesses) {
last = chrome.chromeProcesses;
print("Chrome Processes: " + last);
setConsoleTitle(n(last, "Chrome Process"));
}
}
sleepSeconds(1);
}
}