Class TrackerProxy<T>
java.lang.Object
ru.vyarus.dropwizard.guice.test.track.TrackerProxy<T>
- Type Parameters:
T- bean type
- All Implemented Interfaces:
org.aopalliance.aop.Advice,org.aopalliance.intercept.Interceptor,org.aopalliance.intercept.MethodInterceptor
AOP interceptor redirect calls from the real bean into spy object, which was created around the same real bean.
There is a chicken-egg problem: service binding can't be overridden (with spy instance), because spy requires service instance for construction. So, instead of replacing bean, we intercept bean calls. Actual spy object is created lazily just after injector creation. On the first call, AOP interceptor breaks the current aop chain (if other interceptors registered) and redirect calls to spy, which again calls the same service (including aop handler), but, this time, it processes normally.
-
Constructor Summary
ConstructorsConstructorDescriptionTrackerProxy(Class<T> type, TrackerConfig config, com.codahale.metrics.MetricRegistry metrics) Create proxy. -
Method Summary
Modifier and TypeMethodDescriptioninvoke(org.aopalliance.intercept.MethodInvocation methodInvocation)
-
Constructor Details
-
TrackerProxy
public TrackerProxy(Class<T> type, TrackerConfig config, com.codahale.metrics.MetricRegistry metrics) Create proxy.- Parameters:
type- service typeconfig- configmetrics- metrics
-
-
Method Details
-
getTracker
- Returns:
- tracker instance
-
invoke
- Specified by:
invokein interfaceorg.aopalliance.intercept.MethodInterceptor- Throws:
Throwable
-