3 import java.util.Calendar;
4 import java.util.GregorianCalendar;
8 public class ScanThreadSpawner extends Thread {
9 public static ScanThreadSpawner Instance;
10 public boolean scanning = false;
12 public int timeBeforeKill;
13 public long aliveTime = System.currentTimeMillis();
15 public int neighborRank;
16 public boolean running = false;
17 public JaceSpawnerInterface previousSpawner = null;
19 private ScanThreadSpawner() {
20 // beat=HeartBeatThread.Instance().getHeartTime();
21 // timeBeforeKill=beat*3;
26 public void setHeartTime(int beat) {
28 timeBeforeKill = beat * 4;
31 public void setServer(JaceSpawnerInterface stub) {
32 previousSpawner = stub;
33 aliveTime = System.currentTimeMillis();
36 public static ScanThreadSpawner Instance() {
37 if (Instance == null) {
38 System.out.println("creating new ScanThreadSpawner ");
39 Instance = new ScanThreadSpawner();
49 public void setAliveTime() {
50 aliveTime = System.currentTimeMillis();
51 // System.out.println("spawner is pinging me at "+aliveTime);
54 @SuppressWarnings("static-access")
56 System.out.println("start ScanThreadSpawner.......");
58 // System.out.println("ScanThread alive.......");
61 } catch (Exception e) {
63 // System.out.println("test Neighbor: "+neighborRank);
70 public void testNeighbor() {
79 //boolean changed = false;
81 currentTime = System.currentTimeMillis();
82 if (currentTime - aliveTime > timeBeforeKill
83 && Register.Instance().getSpawnerStub().getFinished() == false) {
84 Calendar cal = new GregorianCalendar();
85 System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
86 + cal.get(Calendar.SECOND));
87 System.out.println("neighbor maybe Dead, "
88 + (currentTime - aliveTime) + " " + currentTime + " "
89 + aliveTime + " result "
90 + (currentTime - aliveTime > timeBeforeKill)
91 + " timebk=" + timeBeforeKill);
92 boolean response = false;
94 response = previousSpawner.ping();
95 System.out.println("previous spawner is still alive");
96 } catch (Exception e) {
98 .println("the previous spawner is officially dead "
101 if (response == false) {
102 JaceSpawner.Instance().getNewSpawner(previousSpawner);
106 } catch (Exception e) {
107 System.out.println("error in test neighbor: " + e);