]> andersk Git - moira.git/blobdiff - webmoira/mit/moira/Kticket.java
Make Moira Java Object thread safe (provide mutex locking of a sorts)
[moira.git] / webmoira / mit / moira / Kticket.java
index 28c6f445a5ce8ae3427bfd37e12877206b6498e2..cc7d35ffe956cd6b5455648b528756750abc7c44 100644 (file)
@@ -4,7 +4,6 @@ import java.util.Date;
 import java.io.IOException;
 
 public class Kticket implements Runnable {
-    Object LOCK;
     String name;
     String instance;
     String realm;
@@ -12,11 +11,10 @@ public class Kticket implements Runnable {
     Runtime r;
     Date renewTime;
 
-    Kticket(String name, String instance, String realm, Object lock) {
+    Kticket(String name, String instance, String realm) {
        this.name = name;
        this.instance = instance;
        this.realm = realm;
-       this.LOCK = lock;
        r = Runtime.getRuntime();
        renewTime = new Date();
     }
@@ -38,27 +36,30 @@ public class Kticket implements Runnable {
     }
 
     public void renew() {
-       synchronized(LOCK) {
-           try {
-               Process p = r.exec("/usr/athena/bin/kinit -k -t /mit/jis/javahacking/moira/KEY " + name + "/" + instance + "@" + realm);
-               p.waitFor();
-           } catch (IOException e) {
-               e.printStackTrace();
-           } catch (InterruptedException i) {
-           }
+       Moira m = null;
+       try {
+           m = Moira.getInstance("MOIRA.MIT.EDU"); // Host doesn't matter, we won't be making a connection!
+                               // We are getting a Moira instance so that no
+                               // other thread will have one and we can safely
+                               // modify the ticket file
+           Process p = r.exec("/usr/athena/bin/kinit -k -t /mit/jis/javahacking/moira/KEY " + name + "/" + instance + "@" + realm);
+           p.waitFor();
+       } catch (IOException e) {
+           e.printStackTrace();
+       } catch (InterruptedException i) {
+       } finally {
+           m.done();           // Release Moira object
        }
     }
 
     public void destroy() {
        dostop = true;
-       synchronized(LOCK) {
-           try {
-               Process p = r.exec("/usr/athena/bin/kdestroy");
-               p.waitFor();
-           } catch (IOException e) {
-               e.printStackTrace();
-           } catch (InterruptedException i) {
-           }
+       try {
+           Process p = r.exec("/usr/athena/bin/kdestroy");
+           p.waitFor();
+       } catch (IOException e) {
+           e.printStackTrace();
+       } catch (InterruptedException i) {
        }
     }
 }
This page took 0.0338 seconds and 4 git commands to generate.