]> andersk Git - moira.git/blame - webmoira/mit/moira/Kticket.java
Make Moira Java Object thread safe (provide mutex locking of a sorts)
[moira.git] / webmoira / mit / moira / Kticket.java
CommitLineData
bde1652c 1package mit.moira;
2
3import java.util.Date;
4import java.io.IOException;
5
6public class Kticket implements Runnable {
bde1652c 7 String name;
8 String instance;
9 String realm;
10 boolean dostop = false;
11 Runtime r;
12 Date renewTime;
13
74842c59 14 Kticket(String name, String instance, String realm) {
bde1652c 15 this.name = name;
16 this.instance = instance;
17 this.realm = realm;
bde1652c 18 r = Runtime.getRuntime();
19 renewTime = new Date();
20 }
21
22 public void run() {
23 for(;;) {
24 if (dostop) return;
25 Date now = new Date();
26 if (now.after(renewTime)) {
27 renew();
28 renewTime = new Date(System.currentTimeMillis() + 6*3600*1000L); // 6 hours
29 }
30 try {
31 Thread.sleep(30*1000L); // Sleep for 30 seconds
32 } catch (InterruptedException i) {
33 // Nothing to be done about it
34 }
35 }
36 }
37
38 public void renew() {
74842c59 39 Moira m = null;
40 try {
41 m = Moira.getInstance("MOIRA.MIT.EDU"); // Host doesn't matter, we won't be making a connection!
42 // We are getting a Moira instance so that no
43 // other thread will have one and we can safely
44 // modify the ticket file
45 Process p = r.exec("/usr/athena/bin/kinit -k -t /mit/jis/javahacking/moira/KEY " + name + "/" + instance + "@" + realm);
46 p.waitFor();
47 } catch (IOException e) {
48 e.printStackTrace();
49 } catch (InterruptedException i) {
50 } finally {
51 m.done(); // Release Moira object
bde1652c 52 }
53 }
54
55 public void destroy() {
56 dostop = true;
74842c59 57 try {
58 Process p = r.exec("/usr/athena/bin/kdestroy");
59 p.waitFor();
60 } catch (IOException e) {
61 e.printStackTrace();
62 } catch (InterruptedException i) {
bde1652c 63 }
64 }
65}
This page took 0.059046 seconds and 5 git commands to generate.