SimpleIrdEntryListener implements AutoCloseable, DataTreeChangeListener<IrdConfigurationEntry> { protected Map<IrdConfigurationEntry, Resource> readEntries( List<IrdConfigurationEntry> configs, ReadWriteTransaction rwx) { Map<IrdConfigurationEntry, Future<Optional<Resource>>> futures; futures = new HashMap<>(); for (IrdConfigurationEntry entry: configs) { ResourceId expected = entry.getEntryId(); try { InstanceIdentifier<?> iid = entry.getInstance(); if (iid == null || !iid.getTargetType().equals(Resource.class)) { LOG.error("Invalid instance identifier for {}", expected.getValue()); return null; } if (entry.getLocation() == null) { LOG.error("Entry {} missing URI information", expected.getValue()); return null; } InstanceIdentifier<Resource> resourceIID = (InstanceIdentifier<Resource>)iid; futures.put(entry, getValidResource(expected, resourceIID, rwx)); } catch (Exception e) { LOG.error("Failed to read data for {}. Aborting", expected.getValue()); return null; } } Map<IrdConfigurationEntry, Resource> resources; resources = new HashMap<>(); for (Map.Entry<IrdConfigurationEntry, Future<Optional<Resource>>> entry: futures.entrySet()) { try { Optional<Resource> _resource = entry.getValue().get(); if (_resource.isPresent()) { Resource resource = _resource.get(); if (isValidResource(resource)) { resources.put(entry.getKey(), resource); continue; } } LOG.error("Contains invalid data. Aborting."); return null; } catch (Exception e) { LOG.error("Failed to read data. Aborting"); return null; } } return resources; } SimpleIrdEntryListener(InstanceIdentifier<Resource> instance, Uuid entryContext); void register(DataBroker dataBroker, InstanceIdentifier<IrdConfigurationEntry> iid); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdConfigurationEntry>> changes); @Override synchronized void close();  }
@Test public void readEntries() throws Exception { List<IrdConfigurationEntry> configs = new LinkedList<>(); ContextKey ck = new ContextKey(new Uuid(DEFAULT_CONTEXT_UUID)); ResourceKey rk = new ResourceKey(new ResourceId("FIRST_RESOURCE")); ResourceKey ik = new ResourceKey(new ResourceId("FIRST_INSTANCE")); InstanceIdentifier<Resource> resourceIID = InstanceIdentifier.builder(Context.class, ck) .child(Resource.class, rk).build(); InstanceIdentifier<Resource> instanceIID = InstanceIdentifier.builder(Context.class, ck) .child(Resource.class, ik).build(); IrdConfigurationEntryBuilder configBuilder = new IrdConfigurationEntryBuilder() .setEntryId(new ResourceId("THE_FIRST_ENTRY_ID")) .setInstance(instanceIID) .setLocation(new FixedUrlBuilder() .setUri(new Uri("http: configs.add(configBuilder.build()); Map<IrdConfigurationEntry, Resource> result = simpleIrdEntryListener.readEntries(configs, rwx); assertEquals(result, null); }