SimpleIrdListener implements AutoCloseable, DataTreeChangeListener<IrdInstanceConfiguration> { protected void removeIrd(IrdInstanceConfiguration cfg, WriteTransaction wx) { ResourceId rid = cfg.getInstanceId(); if (cfg.getEntryContext() == null) { LOG.error("Configuration is invalid, no need to remove it"); return; } LOG.info("Removing Ird: " + "\n\tResource ID: " + rid.getValue()); SimpleIrdEntryListener listener = mListeners.get(rid); if (listener == null) { LOG.error("{} is not a valid Ird instance", rid.getValue()); return; } mListeners.remove(rid); SimpleIrdRfc7285DefaultNetworkMapListener rfcListener = mRfcListeners.get(rid); mRfcListeners.remove(rid); SimpleIrdRfc7285CostTypeListener ctListener = mCostTypeListeners.get(rid); mCostTypeListeners.remove(rid); try { listener.close(); rfcListener.close(); ctListener.close(); } catch (Exception e) { LOG.error("Error while closing listener", e); } ResourcepoolUtils.deleteResource(mContext, rid, wx); InstanceIdentifier<IrdInstance> iid = SimpleIrdUtils.getInstanceIID(rid); wx.delete(LogicalDatastoreType.OPERATIONAL, iid); } 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 removeIrd() throws Exception { IrdInstanceConfigurationBuilder iicb = new IrdInstanceConfigurationBuilder() .setInstanceId(new ResourceId("test-instance-id")); simpleIrdListener.removeIrd(iicb.build(), wx); }