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 class ServerManagerUtil { 10 11 protected static Log logger = LogFactory.getLog(ServerManagerUtil.class); 12 13 public static ServerManager start(Class testClass, boolean withPersistentStore) throws Exception { 14 ServerManager existingServerManager = getExistingServerManager(); 15 if (existingServerManager != null) { 16 logger.debug("Using existing ServerManager"); 17 return existingServerManager; 18 } 19 logger.debug("Creating server manager"); 20 ServerManager serverManager = new ServerManager(testClass); 21 serverManager.start(withPersistentStore); 22 return serverManager; 23 } 24 25 public static void stop(ServerManager serverManager) { 26 ServerManager existingServerManager = getExistingServerManager(); 27 if (existingServerManager != null) { 28 logger.debug("Not stopping existing ServerManager"); 29 return; 30 } 31 logger.debug("Stopping ServerManager"); 32 serverManager.stop(); 33 } 34 35 private static ThreadLocal serverManagerHolder = new ThreadLocal (); 36 37 private static ServerManager getExistingServerManager() { 38 return (ServerManager) serverManagerHolder.get(); 39 } 40 41 public static ServerManager startAndBind(Class testClass, boolean withPersistentStore) throws Exception { 42 ServerManager sm = start(testClass, withPersistentStore); 43 serverManagerHolder.set(sm); 44 return sm; 45 } 46 47 public static void stopAndRelease(ServerManager sm) { 48 serverManagerHolder.set(null); 49 stop(sm); 50 } 51 52 public static void stopAllWebServers(ServerManager serverManager) { 53 getExistingServerManager().stopAllWebServers(); 54 } 55 56 } 57 | Popular Tags |