Search in sources :

Example 1 with AbstractRegistration

use of org.opendaylight.protocol.concepts.AbstractRegistration in project bgpcep by opendaylight.

the class SimpleNlriRegistry method registerNlriSerializer.

synchronized AutoCloseable registerNlriSerializer(final Class<? extends DataObject> nlriClass, final NlriSerializer serializer) {
    final NlriSerializer prev = this.serializers.get(nlriClass);
    Preconditions.checkState(prev == null, "Serializer already bound to class " + prev);
    this.serializers.put(nlriClass, serializer);
    final Object lock = this;
    return new AbstractRegistration() {

        @Override
        protected void removeRegistration() {
            synchronized (lock) {
                SimpleNlriRegistry.this.serializers.remove(nlriClass);
            }
        }
    };
}
Also used : AbstractRegistration(org.opendaylight.protocol.concepts.AbstractRegistration) NlriSerializer(org.opendaylight.protocol.bgp.parser.spi.NlriSerializer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 2 with AbstractRegistration

use of org.opendaylight.protocol.concepts.AbstractRegistration in project bgpcep by opendaylight.

the class SimpleNlriRegistry method registerNlriParser.

synchronized AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser, final NextHopParserSerializer nextHopSerializer, final Class<? extends CNextHop> cNextHopClass, final Class<? extends CNextHop>... cNextHopClassList) {
    final BgpTableType key = createKey(afi, safi);
    final NlriParser prev = this.handlers.get(key);
    Preconditions.checkState(prev == null, "AFI/SAFI is already bound to parser " + prev);
    this.handlers.put(key, parser);
    this.nextHopParsers.put(key, nextHopSerializer);
    if (cNextHopClass != null) {
        final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cNextHopClass, key);
        this.nextHopSerializers.put(nhKey, nextHopSerializer);
        for (final Class<? extends CNextHop> cNextHop : cNextHopClassList) {
            final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cNextHop, key);
            this.nextHopSerializers.put(nhKeys, nextHopSerializer);
        }
    }
    final Object lock = this;
    return new AbstractRegistration() {

        @Override
        protected void removeRegistration() {
            synchronized (lock) {
                SimpleNlriRegistry.this.handlers.remove(key);
                SimpleNlriRegistry.this.nextHopParsers.remove(key);
                if (cNextHopClass != null) {
                    final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cNextHopClass, key);
                    SimpleNlriRegistry.this.nextHopSerializers.remove(nhKey);
                    for (final Class<? extends CNextHop> cNextHop : cNextHopClassList) {
                        final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cNextHop, key);
                        SimpleNlriRegistry.this.nextHopSerializers.remove(nhKeys);
                    }
                }
            }
        }
    };
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) SimpleEntry(java.util.AbstractMap.SimpleEntry) AbstractRegistration(org.opendaylight.protocol.concepts.AbstractRegistration) NlriParser(org.opendaylight.protocol.bgp.parser.spi.NlriParser) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop)

Example 3 with AbstractRegistration

use of org.opendaylight.protocol.concepts.AbstractRegistration in project bgpcep by opendaylight.

the class SimpleAttributeRegistry method registerAttributeSerializer.

synchronized AutoCloseable registerAttributeSerializer(final Class<? extends DataObject> paramClass, final AttributeSerializer serializer) {
    final AbstractRegistration reg = this.handlers.registerSerializer(paramClass, serializer);
    this.serializers.put(reg, serializer);
    return new AbstractRegistration() {

        @Override
        protected void removeRegistration() {
            synchronized (SimpleAttributeRegistry.this) {
                SimpleAttributeRegistry.this.serializers.remove(reg);
                SimpleAttributeRegistry.this.roSerializers.set(SimpleAttributeRegistry.this.serializers.values());
            }
            reg.close();
        }
    };
}
Also used : AbstractRegistration(org.opendaylight.protocol.concepts.AbstractRegistration)

Aggregations

AbstractRegistration (org.opendaylight.protocol.concepts.AbstractRegistration)3 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 NlriParser (org.opendaylight.protocol.bgp.parser.spi.NlriParser)1 NlriSerializer (org.opendaylight.protocol.bgp.parser.spi.NlriSerializer)1 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType)1 CNextHop (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop)1