1 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 { 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 } 49 | Popular Tags |