BowlerKernel
GitTimeoutThread.java
Go to the documentation of this file.
1 package com.neuronrobotics.bowlerstudio.scripting;
2 
3 import org.eclipse.jgit.api.Git;
4 
5 import com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler;
6 
7 public class GitTimeoutThread extends Thread {
8  Git git;
9  String ref;
10  private RuntimeException ex;
11  long startTime=0;
12  public GitTimeoutThread(Git g) {
13  git=g;
14  ref = git.getRepository().getConfig().getString("remote", "origin", "url");
15  setException(new RuntimeException(
16  "Git opened here, timeout on close!!\nWhen Done with the git object, Call:\n ScriptingEngine.closeGit(git);\n"
17  + ref + "\n"));
18  }
19  public void run() {
20  resetTimer();
21  try {
22  while((startTime+(1000*120))>System.currentTimeMillis())
23  Thread.sleep(1000);
24  git.close();
25  ScriptingEngine.gitOpenTimeout.remove(git);
26  new IssueReportingExceptionHandler().uncaughtException(Thread.currentThread(), getException());
27  } catch (InterruptedException e) {
28  // exited clean
29  }
30  }
31  public void resetTimer() {
32  startTime=System.currentTimeMillis();
33  }
34  public RuntimeException getException() {
35  return ex;
36  }
37  private void setException(RuntimeException ex) {
38  this.ex = ex;
39  }
40 }