View Javadoc

1   /*
2    * Created on 18.05.2005 from Linke
3    *
4    */
5   package test.crispy.example.interceptor;
6   
7   import net.sf.crispy.Interceptor;
8   import net.sf.crispy.InterceptorContext;
9   
10  /**
11   * @author Linke
12   *
13   */
14  public class WaitInterceptor implements Interceptor {
15  	
16  	private int waitTime = 50;
17  	
18  	public WaitInterceptor() { }
19  	public WaitInterceptor(int pvWaitTime) { setWaitTime(pvWaitTime); }
20  	
21  	/**
22  	 * @param pvWaitTime The waitTime to set.
23  	 */
24  	public void setWaitTime(int pvWaitTime) { waitTime = pvWaitTime; }
25  	/**
26  	 * @return Returns the waitTime.
27  	 */
28  	public int getWaitTime() { return waitTime; }
29  
30  	/**
31  	 * @see net.sf.crispy.Interceptor#beforeNewInstance(java.lang.Class)
32  	 */
33  	public void beforeNewInstance(Class pvInterfaceClass) {	 }
34  
35  	/**
36  	 * @see net.sf.crispy.Interceptor#afterNewInstance(java.lang.Class, java.lang.Object)
37  	 */
38  	public void afterNewInstance(Class pvInterfaceClass, Object pvProxyObject) {
39  		try { 
40  			Thread.sleep(getWaitTime()); 
41  		} catch (InterruptedException e) { 
42  			e.printStackTrace(); 
43  		}
44  	}
45  
46  	/**
47  	 * @see net.sf.crispy.Interceptor#beforeMethodInvocation(net.sf.crispy.InterceptorContext)
48  	 */
49  	public void beforeMethodInvocation(InterceptorContext pvInterceptorContext) {	}
50  
51  	/**
52  	 * @see net.sf.crispy.Interceptor#afterMethodInvocation(net.sf.crispy.InterceptorContext)
53  	 */
54  	public void afterMethodInvocation(InterceptorContext pvInterceptorContext) {
55  		try { 
56  			Thread.sleep(getWaitTime()); 
57  		} catch (InterruptedException e) { 
58  			e.printStackTrace(); 
59  		}
60  	}
61  
62  	/**
63  	 * @see net.sf.crispy.Interceptor#onError(java.lang.Throwable)
64  	 */
65  	public void onError(Throwable pvThrowable) {
66  		try { 
67  			Thread.sleep(getWaitTime()); 
68  		} catch (InterruptedException e) { 
69  			e.printStackTrace(); 
70  		}
71  	}
72  
73  }