Search in sources :

Example 1 with ChildShardContext

use of org.opendaylight.mdsal.dom.spi.shard.ChildShardContext in project controller by opendaylight.

the class DistributedShardChangePublisher method setupListenerContext.

private <L extends DOMDataTreeChangeListener> AbstractDOMDataTreeChangeListenerRegistration<L> setupListenerContext(final YangInstanceIdentifier listenerPath, final L listener) {
    // we need to register the listener registration path based on the shards root
    // we have to strip the shard path from the listener path and then register
    YangInstanceIdentifier strippedIdentifier = listenerPath;
    if (!shardPath.isEmpty()) {
        strippedIdentifier = YangInstanceIdentifier.create(stripShardPath(shardPath, listenerPath));
    }
    final DOMDataTreeListenerWithSubshards subshardListener = new DOMDataTreeListenerWithSubshards(strippedIdentifier, listener);
    final AbstractDOMDataTreeChangeListenerRegistration<L> reg = setupContextWithoutSubshards(listenerPath, strippedIdentifier, subshardListener);
    for (final ChildShardContext maybeAffected : childShards.values()) {
        if (listenerPath.contains(maybeAffected.getPrefix().getRootIdentifier())) {
            // consumer has initialDataChangeEvent subshard somewhere on lower level
            // register to the notification manager with snapshot and forward child notifications to parent
            LOG.debug("Adding new subshard{{}} to listener at {}", maybeAffected.getPrefix(), listenerPath);
            subshardListener.addSubshard(maybeAffected);
        } else if (maybeAffected.getPrefix().getRootIdentifier().contains(listenerPath)) {
            // already registering to the lowest shard possible
            throw new UnsupportedOperationException("Listener should be registered directly " + "into initialDataChangeEvent subshard");
        }
    }
    return reg;
}
Also used : ChildShardContext(org.opendaylight.mdsal.dom.spi.shard.ChildShardContext) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 2 with ChildShardContext

use of org.opendaylight.mdsal.dom.spi.shard.ChildShardContext in project controller by opendaylight.

the class DistributedShardFrontend method addChildShard.

private void addChildShard(final DOMDataTreeIdentifier prefix, final DOMDataTreeShard child) {
    Preconditions.checkArgument(child instanceof WriteableDOMDataTreeShard);
    childShards.put(prefix, new ChildShardContext(prefix, (WriteableDOMDataTreeShard) child));
}
Also used : ChildShardContext(org.opendaylight.mdsal.dom.spi.shard.ChildShardContext) WriteableDOMDataTreeShard(org.opendaylight.mdsal.dom.spi.shard.WriteableDOMDataTreeShard) ReadableWriteableDOMDataTreeShard(org.opendaylight.mdsal.dom.spi.shard.ReadableWriteableDOMDataTreeShard)

Example 3 with ChildShardContext

use of org.opendaylight.mdsal.dom.spi.shard.ChildShardContext in project controller by opendaylight.

the class DistributedShardFrontend method createModificationFactory.

DistributedShardModificationFactory createModificationFactory(final Collection<DOMDataTreeIdentifier> prefixes) {
    // TODO this could be abstract
    final Map<DOMDataTreeIdentifier, SubshardProducerSpecification> affectedSubshards = new HashMap<>();
    for (final DOMDataTreeIdentifier producerPrefix : prefixes) {
        for (final ChildShardContext maybeAffected : childShards.values()) {
            final DOMDataTreeIdentifier bindPath;
            if (producerPrefix.contains(maybeAffected.getPrefix())) {
                bindPath = maybeAffected.getPrefix();
            } else if (maybeAffected.getPrefix().contains(producerPrefix)) {
                // Bound path is inside subshard
                bindPath = producerPrefix;
            } else {
                continue;
            }
            SubshardProducerSpecification spec = affectedSubshards.computeIfAbsent(maybeAffected.getPrefix(), k -> new SubshardProducerSpecification(maybeAffected));
            spec.addPrefix(bindPath);
        }
    }
    final DistributedShardModificationFactoryBuilder builder = new DistributedShardModificationFactoryBuilder(shardRoot);
    for (final SubshardProducerSpecification spec : affectedSubshards.values()) {
        final ForeignShardModificationContext foreignContext = new ForeignShardModificationContext(spec.getPrefix(), spec.createProducer());
        builder.addSubshard(foreignContext);
        builder.addSubshard(spec.getPrefix(), foreignContext);
    }
    return builder.build();
}
Also used : ChildShardContext(org.opendaylight.mdsal.dom.spi.shard.ChildShardContext) SubshardProducerSpecification(org.opendaylight.mdsal.dom.spi.shard.SubshardProducerSpecification) HashMap(java.util.HashMap) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ForeignShardModificationContext(org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext)

Aggregations

ChildShardContext (org.opendaylight.mdsal.dom.spi.shard.ChildShardContext)3 HashMap (java.util.HashMap)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)1 ForeignShardModificationContext (org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext)1 ReadableWriteableDOMDataTreeShard (org.opendaylight.mdsal.dom.spi.shard.ReadableWriteableDOMDataTreeShard)1 SubshardProducerSpecification (org.opendaylight.mdsal.dom.spi.shard.SubshardProducerSpecification)1 WriteableDOMDataTreeShard (org.opendaylight.mdsal.dom.spi.shard.WriteableDOMDataTreeShard)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1