import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
+
+import org.apache.aries.blueprint.annotation.service.Reference;
import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
public class CacheBridgeRefEntryListener implements ClusteredDataTreeChangeListener<BridgeRefEntry> {
private static final Logger LOG = LoggerFactory.getLogger(CacheBridgeRefEntryListener.class);
+ private final InterfaceMetaUtils interfaceMetaUtils;
private final ListenerRegistration<CacheBridgeRefEntryListener> registration;
private final DataTreeIdentifier<BridgeRefEntry> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
- getWildcardPath());
+ InstanceIdentifier.create(BridgeRefInfo.class).child(BridgeRefEntry.class));
@Inject
- public CacheBridgeRefEntryListener(DataBroker dataBroker) {
+ public CacheBridgeRefEntryListener(@Reference DataBroker dataBroker, InterfaceMetaUtils interfaceMetaUtils) {
LOG.trace("Registering on path: {}", treeId);
+ this.interfaceMetaUtils = interfaceMetaUtils;
registration = dataBroker.registerDataTreeChangeListener(treeId, CacheBridgeRefEntryListener.this);
}
}
}
- protected InstanceIdentifier<BridgeRefEntry> getWildcardPath() {
- return InstanceIdentifier.create(BridgeRefInfo.class).child(BridgeRefEntry.class);
- }
-
@Override
public void onDataTreeChanged(Collection<DataTreeModification<BridgeRefEntry>> changes) {
for (DataTreeModification<BridgeRefEntry> change : changes) {
* Removing for now, can consider this as future optimization.
*
*/
- InterfaceMetaUtils.removeFromBridgeRefEntryCache(mod.getDataBefore());
+ if (mod.getDataBefore() != null) {
+ interfaceMetaUtils.removeFromBridgeRefEntryCache(mod.getDataBefore());
+ }
break;
case SUBTREE_MODIFIED:
case WRITE:
- InterfaceMetaUtils.addBridgeRefEntryToCache(mod.getDataAfter());
+ interfaceMetaUtils.addBridgeRefEntryToCache(mod.getDataAfter());
break;
default:
throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());