01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.test.server.appserver.deployment;
05:
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08:
09: public abstract class AbstractStoppable implements Stoppable {
10:
11: protected boolean stopped = true;
12: protected Log logger = LogFactory.getLog(getClass());
13:
14: public void start() throws Exception {
15: logger.info("### Starting " + this );
16: long l1 = System.currentTimeMillis();
17: doStart();
18: stopped = false;
19: long l2 = System.currentTimeMillis();
20: logger.info("### Started " + this + "; " + (l2 - l1) / 1000f);
21: }
22:
23: public void stop() throws Exception {
24: logger.info("### Stopping " + this );
25: long l1 = System.currentTimeMillis();
26: stopped = true;
27: doStop();
28: long l2 = System.currentTimeMillis();
29: logger.info("### Stopped " + this + "; " + (l2 - l1) / 1000f);
30: }
31:
32: protected abstract void doStop() throws Exception;
33:
34: protected abstract void doStart() throws Exception;
35:
36: public boolean isStopped() {
37: return stopped;
38: }
39:
40: public void stopIgnoringExceptions() {
41: try {
42: stop();
43: } catch (Exception e) {
44: logger.error(e);
45: }
46: }
47:
48: }
|