22 |
|
|
23 |
import dk.thoerup.circuitbreaker.CircuitInvocation; |
import dk.thoerup.circuitbreaker.CircuitInvocation; |
24 |
|
|
25 |
public class AnnotatedInvocation implements CircuitInvocation { |
public class AnnotatedInvocation<T> implements CircuitInvocation<T> { |
26 |
|
|
27 |
public static class CBAnnotationException extends Exception { |
public static class CBAnnotationException extends Exception { |
28 |
public CBAnnotationException() { |
public CBAnnotationException() { |
38 |
this.obj = obj; |
this.obj = obj; |
39 |
} |
} |
40 |
|
|
41 |
public Object proceed() throws Exception { |
@SuppressWarnings("unchecked") |
42 |
|
public T proceed() throws Exception { |
43 |
|
|
44 |
Method methods[] = obj.getClass().getMethods(); |
Method methods[] = obj.getClass().getMethods(); |
45 |
for(Method current : methods) { |
for(Method current : methods) { |
48 |
|
|
49 |
if (anno != null ) { |
if (anno != null ) { |
50 |
try { |
try { |
51 |
return current.invoke(obj, (Object[])null); //invoke the first method annotated |
return (T) current.invoke(obj, (Object[])null); //invoke the first method annotated |
52 |
} catch (InvocationTargetException e) { |
} catch (InvocationTargetException e) { |
53 |
throw (Exception) e.getCause(); //unwrap any exception from InvocationTargetException |
throw (Exception) e.getCause(); //unwrap any exception from InvocationTargetException |
54 |
} |
} |