import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class TimeOutThread implements Runnable{ public static int SLEEP = 6000; public static int READRCV = 200; public static int WRITERCV = 15000; public static int MAXTRANS = 3; private int duration; TimeOutThread(){ this.duration = SLEEP; } @Override public void run() { try { Thread.sleep(duration); } catch (InterruptedException e) { System.out.println("Timeout thread interrupted."); } } /******************************************************* * This static method reads the /lib/timeout.conf file * * and returns user configurable time out values. * * Must be run when the server is started. * * If unsuccessful, it will set values to default. * *******************************************************/ public static synchronized void setTimeouts(){ // Try to use the user defined configuration for timeouts. try(BufferedReader br = new BufferedReader(new FileReader(new File("./lib/timeout.conf")))){ String line; while((line = br.readLine()) != null){ if(!line.startsWith("#")){ String[] args = line.split(" : "); switch(args[0]){ case "Sleep": SLEEP = Integer.parseInt(args[1]); case "ReadRcv": READRCV = Integer.parseInt(args[1]); case "WriteRcv": WRITERCV = Integer.parseInt(args[1]); case "MaxRetrans": MAXTRANS = Integer.parseInt(args[1]); } } } } catch (Exception e){ // Return some default values if parsing fails. SLEEP = 6000; READRCV = 200; WRITERCV = 10000; MAXTRANS = 3; } } }