View Javadoc
1   /*
2    * Copyright 2010 Capgemini
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   *
15   */
16  package net.sf.appstatus.core.services;
17  
18  import org.slf4j.Logger;
19  
20  /**
21   * Service monitor
22   *
23   * @author Guillaume Mary
24   * @author Nicolas Richeton
25   *
26   */
27  public interface IServiceMonitor {
28  
29  	/**
30  	 * Notify of the beginning of a call to a service.
31  	 *
32  	 * @param operationName
33  	 *            operation name
34  	 * @param parameters
35  	 *            operation parameters
36  	 * @return call id
37  	 */
38  	void beginCall(Object... parameters);
39  
40  	/**
41  	 * Reports that a cache system was used instead of performing the actual
42  	 * call.
43  	 *
44  	 */
45  	void cacheHit();
46  
47  	void context(String name, String value);
48  
49  	void correlationId(String correlationId);
50  
51  	/**
52  	 * Notify the end of a call to a service.
53  	 *
54  	 */
55  	void endCall();
56  
57  	/**
58  	 * Reports an error : the call has succeed but returns an error (with data).
59  	 *
60  	 * @param message
61  	 */
62  	void error(String message);
63  
64  	/**
65  	 * Manually set the execution time. If this method is not called, execution
66  	 * time is computed between beginCall and endCall.
67  	 */
68  	void executionTime(long timeMillis);
69  
70  	/**
71  	 * Reports a failure : the call has failed completely
72  	 *
73  	 * @param reason
74  	 */
75  	void failure(String reason);
76  
77  	/**
78  	 * Reports a failure : the call has failed completely with exception e.
79  	 *
80  	 * @param reason
81  	 * @param e
82  	 */
83  	void failure(String reason, Exception e);
84  
85  	/**
86  	 * Report that another service was called in order to perform original
87  	 * action
88  	 */
89  	void nestedCall();
90  
91  	/**
92  	 * Set the log message format for this monitor instance, based on :
93  	 * http://commons.apache.org/lang/api-release/org/apache/commons/lang3/text/
94  	 * StrSubstitutor.html
95  	 *
96  	 * <p>
97  	 * Example :
98  	 * <code>${correlationId}|${group}|${name}|${responseTime}|${cache}|${status}|${statusMessage}</code>
99  	 * </p>
100 	 *
101 	 * <p>
102 	 * Available variables :
103 	 * </p>
104 	 * <ul>
105 	 * <li>group</li>
106 	 * <li>name</li>
107 	 * <li>responseTime</li>
108 	 * <li>cache</li>
109 	 * <li>failure</li>
110 	 * <li>failureReason</li>
111 	 * <li>failureException</li>
112 	 * <li>error</li>
113 	 * <li>errorMessage</li>
114 	 * <li>correlationId</li>
115 	 * <li>status : SUCCESS/FAILURE/ERROR</li>
116 	 * <li>statusMessage : failure or error message</li>
117 	 * <li>Any additional context values</li>
118 	 * </ul>
119 	 *
120 	 * @param format
121 	 */
122 	void setLogFormat(String format);
123 
124 	/**
125 	 * Set the logger to use for this service call.
126 	 *
127 	 * @param logger
128 	 */
129 	void setLogger(Logger logger);
130 
131 }