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

public class TrackerProxy<T> extends Object implements 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 Details

    • TrackerProxy

      public TrackerProxy(Class<T> type, TrackerConfig config, com.codahale.metrics.MetricRegistry metrics)
      Create proxy.
      Parameters:
      type - service type
      config - config
      metrics - metrics
  • Method Details

    • getTracker

      public Tracker<T> getTracker()
      Returns:
      tracker instance
    • invoke

      public Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation) throws Throwable
      Specified by:
      invoke in interface org.aopalliance.intercept.MethodInterceptor
      Throws:
      Throwable