View Javadoc

1   /*
2    * The contents of this file are subject to the terms 
3    * of the Common Development and Distribution License 
4    * (the "License").  You may not use this file except 
5    * in compliance with the License.
6    * 
7    * You can obtain a copy of the license at 
8    * http://www.sun.com/cddl/cddl.html. 
9    * See the License for the specific language governing 
10   * permissions and limitations under the License.
11   * 
12   * When distributing Covered Code, include this CDDL 
13   * HEADER in each file and include the License file at 
14   * license.txt.  If applicable, add the following below 
15   * this CDDL HEADER, with the fields enclosed by brackets 
16   * "[]" replaced with your own identifying information: 
17   * Portions Copyright [yyyy] [name of copyright owner]
18   * 
19   * Portions Copyright 2004 eBay, Inc.
20   */
21  package com.ebay.carad.os.vitalsigns.dataretrievers;
22  
23  import com.ebay.carad.os.vitalsigns.IDashboardAgent;
24  import com.ebay.carad.os.vitalsigns.IDataRetriever;
25  import com.ebay.carad.os.vitalsigns.ReportingException;
26  import com.ebay.carad.os.vitalsigns.templates.ITemplatizable;
27  
28  /***
29   * <p>Wraps an instance of ITester, and logs its output.</p>
30   * 
31   * @author Jeremy Kraybill
32   * @author Jeremy Thomerson
33   * @version $Id$
34   */
35  public class TesterLogger implements IDataRetriever, ITemplatizable, Cloneable {
36  
37  	//private static final Logger LOGGER = Logger.getLogger(QueryLogger.class);
38  	
39  	private ITester mTester;
40  	
41  	/***
42  	 * Basic constructor.
43  	 */
44  	public TesterLogger() {
45  		super();
46  	}
47  	
48  	/***
49  	 * IoC method, sets the tester we are wrapping.
50  	 * 
51  	 * @param tester the tester to run
52  	 */
53  	public void setTester(ITester tester) {
54  		mTester = tester;
55  	}
56  	
57  	/***
58  	 * Returns the tester we are running.
59  	 * 
60  	 * @return the tester to run
61  	 */
62  	public ITester getTester() {
63  		return mTester;
64  	}
65  	
66  	public Float getData() {
67  		Float value = null;
68  		try {
69  			value = new Float(mTester.test());
70  		} catch (Exception ex) {
71  			// TODO : previously this did not throw an exception, but simply logged the error.  should we have changed it or left it the way it was?
72  			throw new ReportingException("exception running tester: " + mTester, ex);
73  		}
74  		return value;
75  	}
76  
77  	public void templatize(Object[] params) {
78  		if (mTester instanceof ITemplatizable) {
79  			((ITemplatizable) mTester).templatize(params);
80  		}
81  	}
82  
83      public Object clone() throws CloneNotSupportedException {
84      	TesterLogger newObj = (TesterLogger) super.clone();
85      	newObj.setTester((ITester) mTester.clone());
86      	return newObj;
87      }
88  
89      public Float getData(IDashboardAgent agent) {
90          return getData();
91      }
92  
93  }