/** Same with {@link #of} but with better type inference behavior for the case of {@link Fn}. */ public static <InputT, OutputT> Contextful<Fn<InputT, OutputT>> fn( final Fn<InputT, OutputT> fn, Requirements requirements) { return of(fn, requirements); } }
/** Watches the growth of the given poll function. See class documentation for more details. */ public static <InputT, OutputT> Growth<InputT, OutputT, OutputT> growthOf( Growth.PollFn<InputT, OutputT> pollFn, Requirements requirements) { return new AutoValue_Watch_Growth.Builder<InputT, OutputT, OutputT>() .setTerminationPerInput(Growth.never()) .setPollFn(Contextful.of(pollFn, requirements)) // use null as a signal that this is the identity function and output coder can be // reused as key coder .setOutputKeyFn(null) .build(); }
@Override public PCollection<MatchResult.Metadata> expand(PCollection<String> input) { PCollection<MatchResult.Metadata> res; if (getConfiguration().getWatchInterval() == null) { res = input.apply( "Match filepatterns", ParDo.of(new MatchFn(getConfiguration().getEmptyMatchTreatment()))); } else { res = input .apply( "Continuously match filepatterns", Watch.growthOf( Contextful.of(new MatchPollFn(), Requirements.empty()), new ExtractFilenameFn()) .withPollInterval(getConfiguration().getWatchInterval()) .withTerminationPerInput(getConfiguration().getWatchTerminationCondition())) .apply(Values.create()); } return res.apply(Reshuffle.viaRandomKey()); }
.apply( Watch.growthOf( Contextful.of( new TimedPollFn<String, KV<Integer, String>>( polls,
.withDestinationCoder(StringUtf8Coder.of()) .withNaming( Contextful.of( tableManifestNaming, Requirements.requiresSideInputs(outputDirectoryName))) .via(Contextful.fn(KV::getValue), TextIO.sink()) .withTempDirectory(outputDir) .withNaming( Contextful.of( manifestNaming, Requirements.requiresSideInputs(outputDirectoryName)))); return fileWriteResults;