KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > integrationtests > framework > AbstractStoppable


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.spring.integrationtests.framework;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 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 JavaDoc {
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 JavaDoc {
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 JavaDoc;
33
34   protected abstract void doStart() throws Exception JavaDoc;
35
36   public boolean isStopped() {
37     return stopped;
38   }
39
40   public void stopIgnoringExceptions() {
41     try {
42       stop();
43     } catch (Exception JavaDoc e) {
44       logger.error(e);
45     }
46   }
47
48 }
49
Popular Tags