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