/
timeout.java
56 lines (46 loc) · 1.35 KB
/
timeout.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import omero.*;
import omero.api.*;
import omero.model.*;
import omero.sys.*;
public class timeout {
static int IDLETIME = 5;
static client c;
static ServiceFactoryPrx s;
public static void main(String[] args) throws Exception {
final int idletime = args.length > 1 ? Integer.parseInt(args[0]) : IDLETIME;
c = new client(args);
s = c.createSession();
System.out.println(s.getAdminService().getEventContext().sessionUuid);
final RenderingEnginePrx re = s.createRenderingEngine(); // for keep alive
class Run extends Thread {
public boolean stop = false;
public void run() {
while ( ! stop ) {
try {
Thread.sleep(idletime*1000L);
} catch (Exception e) {
// ok
}
System.out.println(System.currentTimeMillis() + " calling keep alive");
try {
// Currently, passing a null or empty array to keepAllAlive
// would suffice. For future-proofing, however, it makes sense
// to pass stateful services.
s.keepAllAlive(new ServiceInterfacePrx[]{re});
} catch (Exception e) {
c.closeSession();
throw new RuntimeException(e);
}
}
}
}
final Run run = new Run();
class Stop extends Thread {
public void run() {
run.stop = true;
}
}
Runtime.getRuntime().addShutdownHook(new Stop());
run.start();
}
}