Source:
public int process(PaChannelData channelData, Set<String> currentlyProcessing) { int processed = 0; Set<ItemRefAndBroadcast> broadcasts = new HashSet<>(); Channel channel = channelData.channel(); Set<ContentHierarchyAndSummaries> hierarchiesAndSummaries = Sets.newHashSet(); ImmutableMap.Builder<String, String> acceptableBroadcastIds = ImmutableMap.builder(); try { for (ProgData programme : channelData.programmes()) { String programmeLock = lockIdentifier(programme); lock(currentlyProcessing, programmeLock); try { Optional<ContentHierarchyAndSummaries> possibleHierarchy = processor.process( programme, channel, channelData.zone(), channelData.lastUpdated() ); if (possibleHierarchy.isPresent()) { ContentHierarchyAndSummaries hierarchy = possibleHierarchy.get(); contentBuffer.add(hierarchy); hierarchiesAndSummaries.add(hierarchy); broadcasts.add(new ItemRefAndBroadcast( hierarchy.getItem(), hierarchy.getBroadcast() )); acceptableBroadcastIds.put( hierarchy.getBroadcast().getSourceId(), hierarchy.getItem().getCanonicalUri() ); } processed++; } catch (Exception e) { log.error(format("Error processing channel %s, prog id %s", channel.getKey(), programme.getProgId() )); } finally { unlock(currentlyProcessing, programmeLock); } } } catch (Exception e) { log.error(format("Error processing channel %s", channel.getKey()), e); } finally { writeContent(hierarchiesAndSummaries, channel); } try { ImmutableMap<String, String> acceptableIds = acceptableBroadcastIds.build(); log.trace("Trimming broadcasts for period {}; will remove IDs others than {}", channelData.schedulePeriod(), acceptableIds ); trimmer.trimBroadcasts(channelData.schedulePeriod(), channel, acceptableIds); scheduleWriter.replaceScheduleBlock(Publisher.PA, channel, broadcasts); log.trace( "Storing version for channel on day {}", channelData.version(), channel, channelData.scheduleDay() ); scheduleVersionStore.store(channel, channelData.scheduleDay(), channelData.version()); } catch (Exception e) { log.error( format( "Error trimming and writing schedule for channel %s", channel.getKey() ), e ); } return processed; }

Target:
public int process(PaChannelData channelData, Set<String> currentlyProcessing) { int processed = 0; Set<ItemRefAndBroadcast> broadcasts = new HashSet<>(); Channel channel = channelData.channel(); ImmutableMap.Builder<String, String> acceptableBroadcastIds = ImmutableMap.builder(); try { for (ProgData programme : channelData.programmes()) { String programmeLock = lockIdentifier(programme); lock(currentlyProcessing, programmeLock); try { Optional<ContentHierarchyAndSummaries> possibleHierarchy = processor.process( programme, channel, channelData.zone(), channelData.lastUpdated() ); if (possibleHierarchy.isPresent()) { ContentHierarchyAndSummaries hierarchy = possibleHierarchy.get(); contentBuffer.add(hierarchy); broadcasts.add(new ItemRefAndBroadcast( hierarchy.getItem(), hierarchy.getBroadcast() )); acceptableBroadcastIds.put( hierarchy.getBroadcast().getSourceId(), hierarchy.getItem().getCanonicalUri() ); } processed++; } catch (Exception e) { log.error( "Error processing channel {}, prog id {}", channel.getKey(), programme.getProgId() ); } finally { unlock(currentlyProcessing, programmeLock); } } } catch (Exception e) { log.error("Error processing channel {}", channel.getKey(), e); } try { contentBuffer.flush(); } catch (Exception e) { log.error("Error writing content for channel {}", channel.getKey(), e); } try { ImmutableMap<String, String> acceptableIds = acceptableBroadcastIds.build(); log.trace("Trimming broadcasts for period {}; will remove IDs others than {}", channelData.schedulePeriod(), acceptableIds ); trimmer.trimBroadcasts(channelData.schedulePeriod(), channel, acceptableIds); scheduleWriter.replaceScheduleBlock(Publisher.PA, channel, broadcasts); log.trace( "Storing version for channel on day {}", channelData.version(), channel, channelData.scheduleDay() ); scheduleVersionStore.store(channel, channelData.scheduleDay(), channelData.version()); } catch (Exception e) { log.error( "Error trimming and writing schedule for channel {}", channel.getKey(), e ); } return processed; }