Source:
protected Module wrapPluginSink( final Key<? extends PluginSink> input, final Key<PluginSink> wrapKey ) { return new PrivateModule() { @Override protected void configure() { Key<PluginSink> sinkKey = (Key<PluginSink>) input; if (batching.getFlushInterval().isPresent() && BatchablePluginSink.class.isAssignableFrom( input.getTypeLiteral().getRawType())) { final Key<PluginSink> flushingKey = Key.get(PluginSink.class, Names.named("flushing")); final Key<? extends BatchablePluginSink> batchedPluginSink = (Key<? extends BatchablePluginSink>) (Key<? extends PluginSink>) sinkKey; bind(BatchablePluginSink.class) .annotatedWith(BatchingDelegate.class) .to(batchedPluginSink); bind(flushingKey).toInstance( new BatchingPluginSink(batching.getFlushInterval().get(), batching.getBatchSizeLimit(), batching.getMaxPendingFlushes())); sinkKey = flushingKey; } if (filter.isPresent()) { final Key<PluginSink> filteringKey = Key.get(PluginSink.class, Names.named("filtered")); bind(PluginSink.class).annotatedWith(FilteringDelegate.class).to(sinkKey); bind(filteringKey).toInstance(new FilteringPluginSink(filter.get())); sinkKey = filteringKey; } bind(wrapKey).to(sinkKey); expose(wrapKey); } @Provides @Singleton public BatchingStatistics batchingStatisticsProvider( CoreStatistics statistics, @Named("pluginId") String pluginId, Logger log ) { if (batching.isReportStatistics()) { log.info("Enabling reporting of batching-specific metrics for output " + input.getTypeLiteral().getRawType().getName()); return statistics.newBatching(pluginId); } else { return new NoopCoreStatistics().newBatching(pluginId); } } }; }

Target:
protected Module wrapPluginSink( final Key<? extends PluginSink> input, final Key<PluginSink> wrapKey ) { return new PrivateModule() { @Override protected void configure() { Key<PluginSink> sinkKey = (Key<PluginSink>) input; if (batching.getFlushInterval().isPresent() && BatchablePluginSink.class.isAssignableFrom( input.getTypeLiteral().getRawType())) { final Key<PluginSink> flushingKey = Key.get(PluginSink.class, Names.named("flushing")); final Key<? extends BatchablePluginSink> batchedPluginSink = (Key<? extends BatchablePluginSink>) (Key<? extends PluginSink>) sinkKey; bind(BatchablePluginSink.class) .annotatedWith(BatchingDelegate.class) .to(batchedPluginSink); bind(flushingKey).toInstance( new BatchingPluginSink(batching.getFlushInterval().get(), batching.getBatchSizeLimit(), batching.getMaxPendingFlushes())); sinkKey = flushingKey; } if (filter.isPresent()) { final Key<PluginSink> filteringKey = Key.get(PluginSink.class, Names.named("filtered")); bind(PluginSink.class).annotatedWith(FilteringDelegate.class).to(sinkKey); bind(filteringKey).toInstance(new FilteringPluginSink(filter.get())); sinkKey = filteringKey; } bind(wrapKey).to(sinkKey); expose(wrapKey); } @Provides @Singleton public BatchingStatistics batchingStatisticsProvider( CoreStatistics statistics, @Named("pluginId") String pluginId, Logger log ) { if (batching.isReportStatistics()) { log.info("Enabling reporting of batching-specific metrics for output " + input.getTypeLiteral().getRawType().getName()); return statistics.newBatching(pluginId); } else { return NoopCoreStatistics.noopBatchingStatistics; } } }; }