use of org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent.Builder in project controller by opendaylight.
the class DataChanged method readExternal.
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
// Read the version
in.readShort();
NormalizedNodeDataInput streamReader = NormalizedNodeInputOutput.newDataInputWithoutValidation(in);
// Note: the scope passed to builder is not actually used.
Builder builder = DOMImmutableDataChangeEvent.builder(DataChangeScope.SUBTREE);
// Read created data
int size = in.readInt();
for (int i = 0; i < size; i++) {
YangInstanceIdentifier path = streamReader.readYangInstanceIdentifier();
NormalizedNode<?, ?> node = streamReader.readNormalizedNode();
builder.addCreated(path, node);
}
// Read updated data
size = in.readInt();
for (int i = 0; i < size; i++) {
YangInstanceIdentifier path = streamReader.readYangInstanceIdentifier();
NormalizedNode<?, ?> before = streamReader.readNormalizedNode();
NormalizedNode<?, ?> after = streamReader.readNormalizedNode();
builder.addUpdated(path, before, after);
}
// Read removed data
size = in.readInt();
for (int i = 0; i < size; i++) {
YangInstanceIdentifier path = streamReader.readYangInstanceIdentifier();
NormalizedNode<?, ?> node = streamReader.readNormalizedNode();
builder.addRemoved(path, node);
}
// Read original subtree
boolean present = in.readBoolean();
if (present) {
builder.setBefore(streamReader.readNormalizedNode());
}
// Read updated subtree
present = in.readBoolean();
if (present) {
builder.setAfter(streamReader.readNormalizedNode());
}
change = builder.build();
}
use of org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent.Builder in project controller by opendaylight.
the class ResolveDataChangeEventsTask method resolve.
/**
* Resolves and submits notification tasks to the specified manager.
*/
public synchronized void resolve(final NotificationManager<DataChangeListenerRegistration<?>, DOMImmutableDataChangeEvent> manager) {
try (RegistrationTreeSnapshot<DataChangeListenerRegistration<?>> w = listenerRoot.takeSnapshot()) {
// Defensive: reset internal state
collectedEvents = ArrayListMultimap.create();
// Run through the tree
final ResolveDataChangeState s = ResolveDataChangeState.initial(candidate.getRootPath(), w.getRootNode());
resolveAnyChangeEvent(s, candidate.getRootNode());
/*
* Convert to tasks, but be mindful of multiple values -- those indicate multiple
* wildcard matches, which need to be merged.
*/
for (Entry<DataChangeListenerRegistration<?>, Collection<DOMImmutableDataChangeEvent>> e : collectedEvents.asMap().entrySet()) {
final Collection<DOMImmutableDataChangeEvent> col = e.getValue();
final DOMImmutableDataChangeEvent event;
if (col.size() != 1) {
final Builder b = DOMImmutableDataChangeEvent.builder(DataChangeScope.BASE);
for (DOMImmutableDataChangeEvent i : col) {
b.merge(i);
}
event = b.build();
LOG.trace("Merged events {} into event {}", col, event);
} else {
event = col.iterator().next();
}
manager.submitNotification(e.getKey(), event);
}
}
}
Aggregations