KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > restart > AbstractRestartTestApp


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc id;
19   protected final ThreadGroup JavaDoc threadGroup;
20
21   protected AbstractRestartTestApp(ThreadGroup JavaDoc threadGroup) {
22     super();
23     this.threadGroup = threadGroup;
24   }
25
26   public String JavaDoc getStateName() {
27     return getState().getName();
28   }
29
30   public synchronized void setID(int i) {
31     this.id = new Integer JavaDoc(i);
32   }
33
34   public synchronized int getID() {
35     if (this.id == null) throw new AssertionError JavaDoc("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 JavaDoc 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 JavaDoc name;
74   
75     private State(String JavaDoc name) {
76       this.name = name;
77     }
78   
79     public String JavaDoc getName() {
80       return this.name;
81     }
82   
83     public String JavaDoc toString() {
84       return this.name;
85     }
86   }
87
88 }
89
Popular Tags