Search in sources :

Example 1 with AbstractRegistration

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

the class ConfigLoaderImpl method registerConfigFile.

@Override
public synchronized AbstractRegistration registerConfigFile(final ConfigFileProcessor config) {
    final String pattern = INITIAL + config.getSchemaPath().getLastComponent().getLocalName() + EXTENSION;
    this.configServices.put(pattern, config);
    final File[] fList = this.file.listFiles();
    final List<String> newFiles = new ArrayList<>();
    if (fList != null) {
        for (final File newFile : fList) {
            if (newFile.isFile()) {
                final String filename = newFile.getName();
                if (Pattern.matches(pattern, filename)) {
                    newFiles.add(filename);
                }
            }
        }
    }
    for (final String filename : newFiles) {
        handleConfigFile(config, filename);
    }
    return new AbstractRegistration() {

        @Override
        protected void removeRegistration() {
            synchronized (ConfigLoaderImpl.this) {
                ConfigLoaderImpl.this.configServices.remove(pattern);
            }
        }
    };
}
Also used : AbstractRegistration(org.opendaylight.yangtools.concepts.AbstractRegistration) ArrayList(java.util.ArrayList) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 2 with AbstractRegistration

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

the class ConfigLoaderImplTest method configLoaderImplTest.

@Test
public void configLoaderImplTest() {
    assertNotNull(ClassLoader.getSystemClassLoader().getResource("etc/opendaylight/bgpcep/protocols-config.xml"));
    final AbstractRegistration ticket = this.configLoader.registerConfigFile(this.processor);
    verify(this.processor).loadConfiguration(any());
    triggerEvent("protocols-config.xml");
    verify(this.processor, timeout(20000).times(2)).loadConfiguration(any());
    ticket.close();
    triggerEvent("protocols-config.xml");
    verify(this.processor, timeout(20000).times(2)).loadConfiguration(any());
}
Also used : AbstractRegistration(org.opendaylight.yangtools.concepts.AbstractRegistration) Test(org.junit.Test)

Example 3 with AbstractRegistration

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

the class ActionsRegistryImpl method registerActionPolicy.

AbstractRegistration registerActionPolicy(final Class<? extends Augmentation<Actions>> actionPolicyClass, final ActionsAugPolicy actionPolicy) {
    synchronized (this.actionsRegistry) {
        final ActionsAugPolicy prev = this.actionsRegistry.putIfAbsent(actionPolicyClass, actionPolicy);
        Preconditions.checkState(prev == null, "Action Policy %s already registered %s", actionPolicyClass, prev);
        return new AbstractRegistration() {

            @Override
            protected void removeRegistration() {
                synchronized (ActionsRegistryImpl.this.actionsRegistry) {
                    ActionsRegistryImpl.this.actionsRegistry.remove(actionPolicyClass);
                }
            }
        };
    }
}
Also used : AbstractRegistration(org.opendaylight.yangtools.concepts.AbstractRegistration) ActionsAugPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.ActionsAugPolicy)

Example 4 with AbstractRegistration

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

the class ActionsRegistryImpl method registerBgpActionPolicy.

public AbstractRegistration registerBgpActionPolicy(final Class<? extends ChildOf<BgpActions>> bgpActionPolicyClass, final BgpActionPolicy bgpActionPolicy) {
    synchronized (this.bgpActions) {
        final BgpActionPolicy prev = this.bgpActions.putIfAbsent(bgpActionPolicyClass, bgpActionPolicy);
        Preconditions.checkState(prev == null, "Action Policy %s already registered %s", bgpActionPolicyClass, prev);
        return new AbstractRegistration() {

            @Override
            protected void removeRegistration() {
                synchronized (ActionsRegistryImpl.this.bgpActions) {
                    ActionsRegistryImpl.this.bgpActions.remove(bgpActionPolicyClass);
                }
            }
        };
    }
}
Also used : BgpActionPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionPolicy) AbstractRegistration(org.opendaylight.yangtools.concepts.AbstractRegistration)

Example 5 with AbstractRegistration

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

the class BgpTopologyDeployerImpl method registerService.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public AbstractRegistration registerService(final TopologyReferenceSingletonService topologyProviderService) {
    final Dictionary<String, String> properties = new Hashtable<>();
    properties.put("topology-id", topologyProviderService.getInstanceIdentifier().firstKeyOf(Topology.class).getTopologyId().getValue());
    final ServiceRegistration<?> registerService = this.context.registerService(new String[] { TopologyReference.class.getName() }, topologyProviderService, properties);
    final ClusterSingletonServiceRegistration registerClusterSingletonService = registerSingletonService(topologyProviderService);
    return new AbstractRegistration() {

        @Override
        protected void removeRegistration() {
            try {
                registerClusterSingletonService.close();
            } catch (final Exception e) {
                LOG.warn("Failed to close ClusterSingletonServiceRegistration {} for TopologyBuilder {}", registerClusterSingletonService, topologyProviderService.getInstanceIdentifier(), e);
            } finally {
                registerService.unregister();
            }
        }
    };
}
Also used : Hashtable(java.util.Hashtable) TopologyReference(org.opendaylight.bgpcep.topology.TopologyReference) AbstractRegistration(org.opendaylight.yangtools.concepts.AbstractRegistration) ClusterSingletonServiceRegistration(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)

Aggregations

AbstractRegistration (org.opendaylight.yangtools.concepts.AbstractRegistration)10 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Test (org.junit.Test)1 TopologyReference (org.opendaylight.bgpcep.topology.TopologyReference)1 ClusterSingletonServiceRegistration (org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration)1 ActionsAugPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.ActionsAugPolicy)1 BgpActionAugPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy)1 BgpActionPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionPolicy)1 BgpConditionsAugmentationPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.BgpConditionsAugmentationPolicy)1 BgpConditionsPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.BgpConditionsPolicy)1 ConditionsAugPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.ConditionsAugPolicy)1 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)1 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType)1 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)1 NetworkTopology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology)1 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)1