SimpleIrdListener implements AutoCloseable, DataTreeChangeListener<IrdInstanceConfiguration> { protected void createIrd(IrdInstanceConfiguration cfg, WriteTransaction wx) { ResourceId rid = cfg.getInstanceId(); InstanceIdentifier<?> entryContextIID = cfg.getEntryContext(); if (!isValidEntryContext(entryContextIID)) { return; } ContextKey key = entryContextIID.firstKeyOf(Context.class); if (key == null) { LOG.error("Failed to create Ird: The entry-context must point to a certain context"); return; } Uuid entryContext = key.getContextId(); LOG.info("Creating Ird: " + "\n\tResource ID: " + rid.getValue()); List<IrdConfigurationEntry> entries = cfg.getIrdConfigurationEntry(); if (entries != null && !entries.isEmpty()) { LOG.warn("Do not support adding resources while create Ird, will be ignored"); } InstanceIdentifier<IrdInstance> iid = SimpleIrdUtils.getInstanceIID(rid); IrdInstanceBuilder builder = new IrdInstanceBuilder(); builder.fieldsFrom(cfg); builder.setIrdEntry(new LinkedList<IrdEntry>()); wx.put(LogicalDatastoreType.OPERATIONAL, iid, builder.build()); ResourcepoolUtils.createResource(mContext, rid, ResourceTypeIrd.class, wx); ResourcepoolUtils.lazyUpdateResource(mContext, rid, wx); InstanceIdentifier<Resource> resourceIID = ResourcepoolUtils.getResourceIID(mContext, rid); SimpleIrdEntryListener listener; listener = new SimpleIrdEntryListener(resourceIID, entryContext); listener.register(mDataBroker, SimpleIrdUtils.getConfigEntryListIID(rid)); mListeners.put(rid, listener); SimpleIrdRfc7285DefaultNetworkMapListener rfcListener; rfcListener = new SimpleIrdRfc7285DefaultNetworkMapListener(); rfcListener.register(mDataBroker, rid); mRfcListeners.put(rid, rfcListener); SimpleIrdRfc7285CostTypeListener ctListener; ctListener = new SimpleIrdRfc7285CostTypeListener(); ctListener.register(mDataBroker, rid); mCostTypeListeners.put(rid, ctListener); } SimpleIrdListener(Uuid context); void register(DataBroker dataBroker, InstanceIdentifier<IrdInstanceConfiguration> iid); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdInstanceConfiguration>> changes); @Override synchronized void close();  }
@Test public void createIrd() throws Exception { InstanceIdentifier<Context> contextIId = InstanceIdentifier.builder(Context.class, new ContextKey(new Uuid(DEFAULT_CONTEXT_UUID))).build(); IrdInstanceConfigurationBuilder iicb = new IrdInstanceConfigurationBuilder() .setInstanceId(new ResourceId(DEFAULT_INSTANCE_ID)) .setEntryContext(contextIId); simpleIrdListener.createIrd(iicb.build(), wx); }