Source:
<code>private Optional<InputStreamRegexMonitor> getInputRegexMonitor(Config config, SystemAdmins systemAdmins) { <START> if (new JobConfig(config).getMonitorInputRegexFrequency() <= 0) { <END> log.info("InputStreamRegexMonitor is disabled."); return Optional.empty(); } StreamMetadataCache streamMetadata = new StreamMetadataCache(systemAdmins, 0, SystemClock.instance()); Set<SystemStream> inputStreamsToMonitor = new TaskConfigJava(config).getAllInputStreams(); if (inputStreamsToMonitor.isEmpty()) { throw new SamzaException("Input streams to a job can not be empty."); } Map<String, Pattern> inputRegexesToMonitor = new HashMap<>(); Option<String> rewritersList = new JobConfig(config).getConfigRewriters(); if (rewritersList.isDefined()) { String[] rewriters = rewritersList.get().split(","); for (String rewriterName : rewriters) { Option<String> rewriterSystem = new JobConfig(config).getRegexResolvedSystem(rewriterName); Option<String> rewriterRegex = new JobConfig(config).getRegexResolvedStreams(rewriterName); if (rewriterSystem.isDefined() && rewriterRegex.isDefined()) { Pattern patternForSystem = inputRegexesToMonitor.get(rewriterSystem.get()); if (patternForSystem == null) { patternForSystem = Pattern.compile(rewriterRegex.get()); } else { patternForSystem = Pattern.compile(patternForSystem.pattern() + "|" + rewriterRegex.get()); } inputRegexesToMonitor.put(rewriterSystem.get(), patternForSystem); } } return Optional.of( new InputStreamRegexMonitor(inputStreamsToMonitor, inputRegexesToMonitor, streamMetadata, metrics, new JobConfig(config).getMonitorInputRegexFrequency(), newInputStreams -> { log.error("New input system-streams discovered. Failing the job. New input streams: {}", newInputStreams, " Existing input streams:", inputStreamsToMonitor); state.status = SamzaApplicationState.SamzaAppStatus.FAILED; coordinatorException = new InputStreamsDiscoveredException("New input streams added: " + newInputStreams); })); } else { log.warn("No config rewriters are defined. No InputStreamRegexMonitor created."); return Optional.empty(); } }</code><technical_language>Consider exposing isStreamMonitoringEnabled a convenience API JobConfig class</technical_language>

Target:
private Optional<StreamRegexMonitor> getInputRegexMonitor(Config config, SystemAdmins systemAdmins) { if (new JobConfig(config).getMonitorRegexEnabled()) { log.info("StreamRegexMonitor is disabled."); return Optional.empty(); } StreamMetadataCache streamMetadata = new StreamMetadataCache(systemAdmins, 0, SystemClock.instance()); Set<SystemStream> inputStreamsToMonitor = new TaskConfigJava(config).getAllInputStreams(); if (inputStreamsToMonitor.isEmpty()) { throw new SamzaException("Input streams to a job can not be empty."); } Option<String> rewritersList = new JobConfig(config).getConfigRewriters(); if (!rewritersList.isDefined()) { log.warn("No config rewriters are defined. No StreamRegexMonitor created."); return Optional.empty(); } Map<String, Pattern> inputRegexesToMonitor = JavaConverters.mapAsJavaMapConverter(new JobConfig(config).getMonitorRegexPatternMap(rewritersList.get())) .asJava(); return Optional.of(new StreamRegexMonitor(inputStreamsToMonitor, inputRegexesToMonitor, streamMetadata, metrics, new JobConfig(config).getMonitorRegexFrequency(), new StreamRegexMonitor.Callback() { @Override public void onInputStreamsChanged(Set<SystemStream> initialInputSet, Set<SystemStream> newInputStreams, Map<String, Pattern> regexesMonitored) { log.error("New input system-streams discovered. Failing the job. New input streams: {}", newInputStreams, " Existing input streams:", inputStreamsToMonitor); state.status = SamzaApplicationState.SamzaAppStatus.FAILED; coordinatorException = new InputStreamsDiscoveredException("New input streams added: " + newInputStreams); } })); }