Source:
public synchronized Map<DatastreamTask, DatastreamEventProducer> getEventProducers(List<DatastreamTask> tasks, String connectorType) { Validate.notNull(tasks); Validate.notNull(connectorType); Validate.notEmpty(connectorType); if (tasks.isEmpty()) { LOG.info("Tasks is empty"); return new HashMap<>(); } Map<DatastreamTask, DatastreamEventProducer> taskProducerMapping = new HashMap<DatastreamTask, DatastreamEventProducer>(); Map<String, DatastreamEventProducer> producersForConnectorType = _producers.get(connectorType); if (producersForConnectorType == null) { producersForConnectorType = new HashMap<>(); _producers.put(connectorType, producersForConnectorType); } Map<String, DatastreamEventProducer> unusedProducers = new HashMap<String, DatastreamEventProducer>(producersForConnectorType); VerifiableProperties verifProps = new VerifiableProperties(_config); for (DatastreamTask task : tasks) { String destination = task.getDatastreamDestination().getConnectionString(); if (producersForConnectorType.containsKey(destination)) { unusedProducers.remove(destination); } else { LOG.info(String.format("Creating new message producer for destination %s and task %s", destination, task)); ArrayList<DatastreamTask> tasksPerProducer = new ArrayList<DatastreamTask>(); tasksPerProducer.add(task); producersForConnectorType.put(destination, new DatastreamEventProducerImpl(tasksPerProducer,_transportProviderFactory.createTransportProvider(_config), _checkpointProvider, verifProps.getDomainProperties(CONFIG_PRODUCER))); } taskProducerMapping.put(task, producersForConnectorType.get(destination)); } for (String destination : unusedProducers.keySet()) { producersForConnectorType.remove(destination); } unusedProducers.clear(); return taskProducerMapping; }

Target:
public synchronized Map<DatastreamTask, DatastreamEventProducer> getEventProducers(List<DatastreamTask> tasks, String connectorType) { Validate.notNull(tasks); Validate.notNull(connectorType); Validate.notEmpty(connectorType); if (tasks.isEmpty()) { LOG.info("Tasks is empty"); return new HashMap<>(); } Map<DatastreamTask, DatastreamEventProducer> taskProducerMapping = new HashMap<DatastreamTask, DatastreamEventProducer>(); Map<String, DatastreamEventProducer> producersForConnectorType = _producers.get(connectorType); if (producersForConnectorType == null) { producersForConnectorType = new HashMap<>(); _producers.put(connectorType, producersForConnectorType); } Map<String, DatastreamEventProducer> unusedProducers = new HashMap<String, DatastreamEventProducer>(producersForConnectorType); VerifiableProperties properties = new VerifiableProperties(_config); for (DatastreamTask task : tasks) { String destination = task.getDatastreamDestination().getConnectionString(); if (producersForConnectorType.containsKey(destination)) { unusedProducers.remove(destination); } else { LOG.info(String.format("Creating new message producer for destination %s and task %s", destination, task)); ArrayList<DatastreamTask> tasksPerProducer = new ArrayList<DatastreamTask>(); tasksPerProducer.add(task); producersForConnectorType.put(destination, new DatastreamEventProducerImpl(tasksPerProducer,_transportProviderFactory.createTransportProvider(_config), _checkpointProvider, properties.getDomainProperties(CONFIG_PRODUCER))); } taskProducerMapping.put(task, producersForConnectorType.get(destination)); } for (String destination : unusedProducers.keySet()) { producersForConnectorType.remove(destination); } unusedProducers.clear(); return taskProducerMapping; }