View Javadoc

1   package net.sf.appstatus.core.services;
2   
3   import org.apache.commons.collections.ArrayStack;
4   
5   /**
6    * This locator allows to retrieve the current ServiceMonitor. It uses a
7    * ThreadLocal internally to track all running calls.
8    *
9    * @author Nicolas Richeton
10   *
11   */
12  public class ServiceMonitorLocator {
13  
14  	private static final ThreadLocal<ArrayStack> monitorStack = new ThreadLocal<ArrayStack>() {
15  		@Override
16  		protected ArrayStack initialValue() {
17  			return new ArrayStack();
18  		}
19  	};
20  
21  	public static IServiceMonitor getCurrentServiceMonitor() {
22  		ArrayStack stack = monitorStack.get();
23  
24  		if (!stack.isEmpty()) {
25  			return (IServiceMonitor) stack.peek();
26  		}
27  
28  		return null;
29  	}
30  
31  	public static ArrayStack getServiceMonitorStack() {
32  		return monitorStack.get();
33  	}
34  
35  }