1 4 package com.tctest.restart; 5 6 import EDU.oswego.cs.dl.util.concurrent.FutureResult; 7 8 import com.tc.exception.TCRuntimeException; 9 10 public abstract class AbstractRestartTestApp implements RestartTestApp { 11 12 protected static final State INIT = new State(TestAppState.INIT); 13 protected static final State START = new State(TestAppState.START); 14 protected static final State HOLDER = new State(TestAppState.HOLDER); 15 protected static final State WAITER = new State(TestAppState.WAITER); 16 protected static final State END = new State(TestAppState.END); 17 protected final FutureResult state = new FutureResult(); 18 private Integer id; 19 protected final ThreadGroup threadGroup; 20 21 protected AbstractRestartTestApp(ThreadGroup threadGroup) { 22 super(); 23 this.threadGroup = threadGroup; 24 } 25 26 public String getStateName() { 27 return getState().getName(); 28 } 29 30 public synchronized void setID(int i) { 31 this.id = new Integer (i); 32 } 33 34 public synchronized int getID() { 35 if (this.id == null) throw new AssertionError ("ID is null."); 36 return this.id.intValue(); 37 } 38 39 public synchronized boolean isInit() { 40 return getState().getName().equals(INIT.getName()); 41 } 42 43 public synchronized boolean isStart() { 44 return getState().getName().equals(START.getName()); 45 } 46 47 public synchronized boolean isHolder() { 48 return getState().getName().equals(HOLDER.getName()); 49 } 50 51 public synchronized boolean isWaiter() { 52 return getState().getName().equals(WAITER.getName()); 53 } 54 55 public synchronized boolean isEnd() { 56 return getState().getName().equals(END.getName()); 57 } 58 59 private State getState() { 60 try { 61 return (State) this.state.get(); 62 } catch (Exception e) { 63 throw new TCRuntimeException(e); 64 } 65 } 66 67 protected synchronized void changeState(State newState) { 68 this.state.set(newState); 69 notifyAll(); 70 } 71 72 static protected final class State { 73 private final String name; 74 75 private State(String name) { 76 this.name = name; 77 } 78 79 public String getName() { 80 return this.name; 81 } 82 83 public String toString() { 84 return this.name; 85 } 86 } 87 88 } 89 | Popular Tags |