code: protected static ChaiProviderImplementor factoryImpl(
              final Class wrapperClass,
              final ChaiSetting enableSetting,
              final ChaiProviderImplementor chaiProvider
      )
              throws Exception
      {
          //check to make sure watchdog ise enabled;
          final boolean isEnabled = Boolean.parseBoolean( chaiProvider.getChaiConfiguration().getSetting( enableSetting ) );
          if ( !isEnabled )
          {
              final String errorStr = "attempt to obtain " + wrapperClass.getName() + " wrapper when not enabled in chaiConfiguration";
              LOGGER.warn( errorStr );
              throw new IllegalStateException( errorStr );
          }
  
          if ( Proxy.isProxyClass( chaiProvider.getClass() ) && wrapperClass.isInstance( chaiProvider ) )
          {
              LOGGER.warn( "attempt to obtain " + wrapperClass.getName() + " wrapper for already wrapped ChaiProvider." );
              return chaiProvider;
          }
  
          try
          {
              final Constructor constructor = wrapperClass.getConstructor( ChaiProviderImplementor.class.getClass() );
              final InvocationHandler wrapper = ( InvocationHandler ) constructor.newInstance( chaiProvider );
              final Object wrappedProvider = Proxy.newProxyInstance( chaiProvider.getClass().getClassLoader(), chaiProvider.getClass().getInterfaces(), wrapper );
              return ( ChaiProviderImplementor ) wrappedProvider;
          }
          catch ( Exception e )
          {
              LOGGER.fatal( "Chai internal error, no appropriate constructor for " + wrapperClass.getCanonicalName(), e );
          }
  
          throw new Exception( "Chai internal error, unable to create wrapper for " + wrapperClass.getCanonicalName() );
      }
docs: Wrap a pre-existing ChaiProvider with a WatchdogWrapper instance.
  
  @param chaiProvider a pre-existing {@code ChaiProvider}
  @param enableSetting setting to mark if watchdog is enabled
  @param wrapperClass chai provider wrapper
  @return a wrapped {@code ChaiProvider} instance.