]>
Commit | Line | Data |
---|---|---|
bde1652c | 1 | package mit.moira; |
2 | ||
3 | import java.util.Date; | |
4 | import java.io.IOException; | |
5 | ||
6 | public class Kticket implements Runnable { | |
7 | Object LOCK; | |
8 | String name; | |
9 | String instance; | |
10 | String realm; | |
11 | boolean dostop = false; | |
12 | Runtime r; | |
13 | Date renewTime; | |
14 | ||
15 | Kticket(String name, String instance, String realm, Object lock) { | |
16 | this.name = name; | |
17 | this.instance = instance; | |
18 | this.realm = realm; | |
19 | this.LOCK = lock; | |
20 | r = Runtime.getRuntime(); | |
21 | renewTime = new Date(); | |
22 | } | |
23 | ||
24 | public void run() { | |
25 | for(;;) { | |
26 | if (dostop) return; | |
27 | Date now = new Date(); | |
28 | if (now.after(renewTime)) { | |
29 | renew(); | |
30 | renewTime = new Date(System.currentTimeMillis() + 6*3600*1000L); // 6 hours | |
31 | } | |
32 | try { | |
33 | Thread.sleep(30*1000L); // Sleep for 30 seconds | |
34 | } catch (InterruptedException i) { | |
35 | // Nothing to be done about it | |
36 | } | |
37 | } | |
38 | } | |
39 | ||
40 | public void renew() { | |
41 | synchronized(LOCK) { | |
42 | try { | |
43 | Process p = r.exec("/usr/athena/bin/kinit -k -t /mit/jis/javahacking/moira/KEY " + name + "/" + instance + "@" + realm); | |
44 | p.waitFor(); | |
45 | } catch (IOException e) { | |
46 | e.printStackTrace(); | |
47 | } catch (InterruptedException i) { | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
52 | public void destroy() { | |
53 | dostop = true; | |
54 | synchronized(LOCK) { | |
55 | try { | |
56 | Process p = r.exec("/usr/athena/bin/kdestroy"); | |
57 | p.waitFor(); | |
58 | } catch (IOException e) { | |
59 | e.printStackTrace(); | |
60 | } catch (InterruptedException i) { | |
61 | } | |
62 | } | |
63 | } | |
64 | } |