01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb3.test.ejbthree655;
23:
24: import org.jboss.logging.Logger;
25:
26: /**
27: * Comment
28: *
29: * FIXME: This is thing might be useless because all the lifecycle methods are optional.
30: *
31: * @author <a href="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
32: * @version $Revision: $
33: */
34: public abstract class AbstractStateChecker {
35: private static final Logger log = Logger
36: .getLogger(AbstractStateChecker.class);
37:
38: public static enum State {
39: INITIATED, CREATED, STARTED, STOPPED, DESTROYED
40: };
41:
42: private State currentState = State.INITIATED;
43:
44: public void create() {
45: log.info("create called on " + this );
46:
47: setState(State.INITIATED, State.CREATED);
48: }
49:
50: public void destroy() {
51: log.info("destroy called on " + this );
52:
53: setState(State.STOPPED, State.DESTROYED);
54: }
55:
56: public State getState() {
57: return currentState;
58: }
59:
60: private void setState(State expectedState, State newState) {
61: //log.info("setState expected = " + expectedState + ", current = " + getState() + ", new = " + newState);
62: if (!this .currentState.equals(expectedState)) {
63: // the exception is gobled up somewhere
64: log.warn("state should be " + expectedState + ", not "
65: + currentState);
66: throw new IllegalStateException("state should be "
67: + expectedState + ", not " + currentState);
68: }
69:
70: this .currentState = newState;
71: }
72:
73: public void start() {
74: log.info("start called on " + this );
75:
76: if (currentState.equals(State.STOPPED))
77: setState(State.STOPPED, State.STARTED);
78: else
79: setState(State.CREATED, State.STARTED);
80: }
81:
82: public void stop() {
83: //new Throwable().printStackTrace();
84: log.info("stop called on " + this);
85:
86: setState(State.STARTED, State.STOPPED);
87: }
88: }
|