Source:
public synchronized Map<DatastreamTask, EventProducer> 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<DatastreamTask, EventProducer>(); } Map<DatastreamTask, EventProducer> taskProducerMapping = new HashMap<DatastreamTask, EventProducer>(); List<DatastreamTask> unmappedTasks = new ArrayList<DatastreamTask>(); Map<String, EventProducer> existingProducersForConnectorType = _producers.get(connectorType); if (existingProducersForConnectorType == null) { existingProducersForConnectorType = new HashMap<String, EventProducer>(); _producers.put(connectorType, existingProducersForConnectorType); } Map<String, EventProducer> unusedProducers = new HashMap<String, EventProducer>(existingProducersForConnectorType); for (DatastreamTask task : tasks) { String destination = task.getDatastreamDestination().getConnectionString(); if (existingProducersForConnectorType != null && existingProducersForConnectorType.get(destination) != null) { taskProducerMapping.put(task, existingProducersForConnectorType.get(destination)); unusedProducers.remove(destination); } else { unmappedTasks.add(task); } } for (String destination : unusedProducers.keySet()) { existingProducersForConnectorType.remove(destination); } unusedProducers.clear(); if (unmappedTasks.size() == 0) { return taskProducerMapping; } for (DatastreamTask task : unmappedTasks) { String destination = task.getDatastreamDestination().getConnectionString(); EventProducer producer = existingProducersForConnectorType.get(destination); if (producer == null) { LOG.info(String.format("Creating new message producer for destination %s and task %s", destination, task)); producer = new EventProducerImpl(); existingProducersForConnectorType.put(destination, producer); } taskProducerMapping.put(task, producer); } 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<DatastreamTask, DatastreamEventProducer>(); } Map<DatastreamTask, DatastreamEventProducer> taskProducerMapping = new HashMap<DatastreamTask, DatastreamEventProducer>(); Map<String, DatastreamEventProducer> producersForConnectorType = _producers.get(connectorType); if (producersForConnectorType == null) { producersForConnectorType = new HashMap<String, DatastreamEventProducer>(); _producers.put(connectorType, producersForConnectorType); } Map<String, DatastreamEventProducer> unusedProducers = new HashMap<String, DatastreamEventProducer>(producersForConnectorType); 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, _config)); } taskProducerMapping.put(task, producersForConnectorType.get(destination)); } for (String destination : unusedProducers.keySet()) { producersForConnectorType.remove(destination); } unusedProducers.clear(); return taskProducerMapping; }