1 22 package org.jboss.ejb3.test.ejbthree655; 23 24 import org.jboss.logging.Logger; 25 26 34 public abstract class AbstractStateChecker 35 { 36 private static final Logger log = Logger.getLogger(AbstractStateChecker.class); 37 38 public static enum State { INITIATED, CREATED, STARTED, STOPPED, DESTROYED }; 39 40 private State currentState = State.INITIATED; 41 42 public void create() 43 { 44 log.info("create called on " + this); 45 46 setState(State.INITIATED, State.CREATED); 47 } 48 49 public void destroy() 50 { 51 log.info("destroy called on " + this); 52 53 setState(State.STOPPED, State.DESTROYED); 54 } 55 56 public State getState() 57 { 58 return currentState; 59 } 60 61 private void setState(State expectedState, State newState) 62 { 63 if(!this.currentState.equals(expectedState)) 65 { 66 log.warn("state should be " + expectedState + ", not " + currentState); 68 throw new IllegalStateException ("state should be " + expectedState + ", not " + currentState); 69 } 70 71 this.currentState = newState; 72 } 73 74 public void start() 75 { 76 log.info("start called on " + this); 77 78 if(currentState.equals(State.STOPPED)) 79 setState(State.STOPPED, State.STARTED); 80 else 81 setState(State.CREATED, State.STARTED); 82 } 83 84 public void stop() 85 { 86 log.info("stop called on " + this); 88 89 setState(State.STARTED, State.STOPPED); 90 } 91 } 92 | Popular Tags |